Separate TUI preferences from server configuration (#42202)

## Why

TUI preferences and persistence paths belong to the local client, while thread
configuration and account requirements may come from the active app server.
Keeping both in the same resolved `Config` can replace live local preferences
when a thread is resumed, forked, reconnected, or switched.

## What changed

- Add `LocalSettings` as the TUI-owned source for UI, history, notice, and local
  persistence settings, and preserve it across session lifecycle transitions.
- Write preference changes to the selected user config file and reload local
  settings from disk when changing roots.
- Use the app server's account response for authentication-dependent onboarding
  and status UI instead of the local model-provider configuration.
- Retain platform family and OS metadata reported by remote app servers.

## Testing

- Cover local setting defaults, overrides, persistence destinations, reloads,
  and preservation across widget replacement and root switching.
- Cover remote platform metadata and server-controlled authentication UI.

GitOrigin-RevId: dbc2965fb1d6cbecb3f973f6133f3dcd4467b753
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-02 04:20:38 +00:00
1 parent 0b509e930e
commit 9d57be71ba
87 files changed
+1188 -459

No files matched your search

@@ -17,7 +17,7 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
let cwd = app.config.cwd.clone();
app.config.model = Some("gpt-test".into());
// Avoid platform-specific path widths in the mode-preservation snapshot.
app.config.tui_status_line = Some(vec!["model-with-reasoning".into()]);
app.local_settings.tui.status_line = Some(vec!["model-with-reasoning".into()]);
app.config
.permissions
.set_permission_profile(PermissionProfile::read_only())?;
@@ -187,6 +187,7 @@ async fn reconnect_restores_history_permissions_and_keeps_old_input_paused() ->
let connected = reconnect(
app.app_server_target.clone(),
app.config.clone(),
app.local_settings.clone(),
Some(id),
/*remote_cwd*/ None,
transport,
@@ -315,6 +316,7 @@ async fn reconnect_exhaustion_and_unknown_initial_thread_stay_offline() -> Resul
reconnect(
app.app_server_target.clone(),
app.config.clone(),
app.local_settings.clone(),
id,
/*remote_cwd*/ None,
crate::dynamic_tools_mcp::ThreadToolTransport::Dynamic,
@@ -366,6 +368,7 @@ async fn reconnect_allows_slow_hydration_but_bounds_a_stalled_server() -> Result
endpoint: endpoint.clone(),
},
app.config.clone(),
app.local_settings.clone(),
Some(id),
/*remote_cwd*/ None,
crate::dynamic_tools_mcp::ThreadToolTransport::Dynamic,
+9 -4
View File
@@ -293,7 +293,7 @@ fn select_model_availability_nux_returns_none_when_all_models_are_exhausted() {
#[tokio::test]
async fn prepare_startup_tooltip_override_persists_model_availability_nux_count() {
let codex_home = tempdir().expect("temp codex home");
let mut config = ConfigBuilder::default()
let config = ConfigBuilder::default()
.codex_home(codex_home.path().to_path_buf())
.build()
.await
@@ -310,12 +310,17 @@ async fn prepare_startup_tooltip_override_persists_model_availability_nux_count(
message: "gpt-5.4 is available".to_string(),
});
let tooltip =
prepare_startup_tooltip_override(&mut config, &presets, /*is_first_run*/ false).await;
let mut local_settings = crate::local_settings::LocalSettings::from(&config);
let tooltip = prepare_startup_tooltip_override(
&mut local_settings,
&presets,
/*is_first_run*/ false,
)
.await;
assert_eq!(tooltip.as_deref(), Some("gpt-5.4 is available"));
assert_eq!(
config.model_availability_nux.shown_count,
local_settings.tui.model_availability_nux.shown_count,
HashMap::from([("gpt-5.4".to_string(), 1)])
);
@@ -285,6 +285,7 @@ async fn reconnect_daemon_command_center_after_socket_replacement_without_a_conv
let connected = reconnect(
app.app_server_target.clone(),
app.config.clone(),
app.local_settings.clone(),
previous_thread,
/*remote_cwd*/ None,
session.thread_tool_transport(),
@@ -193,7 +193,7 @@ stream_max_retries = 0
#[tokio::test]
async fn manual_recap_works_when_auto_recap_disabled() -> Result<()> {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
app.config.tui_auto_recap = false;
app.local_settings.tui.auto_recap = false;
let thread_id = ThreadId::new();
app.active_thread_id = Some(thread_id);
app.transcript_cells
@@ -305,7 +305,7 @@ async fn auto_recap_opt_out_blocks_requests_and_cleans_up_pending_start() -> Res
prepare_eligible_recap(&mut app, thread_id);
let (mut app_server, requests, proxy) = start_recording_remote_app_server(&app.config).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.config.tui_auto_recap = false;
app.local_settings.tui.auto_recap = false;
app.schedule_recap_check(thread_id, Instant::now());
app.request_recap(&app_server, thread_id, RecapTrigger::Automatic);
app.handle_event(
@@ -327,13 +327,13 @@ async fn auto_recap_opt_out_blocks_requests_and_cleans_up_pending_start() -> Res
.flat_map(|cell| cell.display_lines(/*width*/ 80))
.collect::<Vec<_>>();
app.config.tui_auto_recap = true;
app.local_settings.tui.auto_recap = true;
app.request_recap(&app_server, thread_id, RecapTrigger::Automatic);
let started_event = tokio::time::timeout(Duration::from_secs(/*secs*/ 5), app_event_rx.recv())
.await?
.expect("recap start event");
assert!(matches!(started_event, AppEvent::RecapStarted { .. }));
app.config.tui_auto_recap = false;
app.local_settings.tui.auto_recap = false;
app.handle_event(&mut tui, &mut app_server, started_event)
.await?;
tokio::time::timeout(Duration::from_secs(/*secs*/ 5), async {
@@ -411,6 +411,7 @@ async fn removing_remote_thread_omits_disconnect_guidance() -> Result<()> {
.await?;
let resumed = server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -549,6 +550,7 @@ async fn external_transport_registers_dynamic_tools_and_finds_task_mentions() ->
.await?;
let resumed = restarted_app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
target_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -557,7 +559,7 @@ async fn external_transport_registers_dynamic_tools_and_finds_task_mentions() ->
assert!(resumed.task_tools_available);
assert!(restarted_app_server.task_tools_available(target_id));
let forked = restarted_app_server
.fork_thread(app.config.clone(), target_id)
.fork_thread(&app.local_settings, app.config.clone(), target_id)
.await?;
assert!(forked.task_tools_available);
assert!(restarted_app_server.task_tools_available(forked.session.thread_id));
@@ -738,6 +740,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
)?;
app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
delegation_source,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -752,6 +755,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
);
app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
delegation_source,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
@@ -765,7 +769,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
starts[0]["config"]["mcp_servers.codex_tui"]
);
app_server
.fork_thread(app.config.clone(), delegation_source)
.fork_thread(&app.local_settings, app.config.clone(), delegation_source)
.await?;
let forked = recorded_params(&requests, "thread/fork")
.pop()
@@ -1245,6 +1249,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
)?;
app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
creation_source,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -1467,7 +1472,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
#[tokio::test]
async fn older_pagination_reconciles_review_prompts_across_page_boundaries() -> Result<()> {
let (mut app, codex_home) = make_history_test_app().await?;
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(100);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(100);
let thread_id = create_fake_paginated_rollout(
codex_home.path(),
"2026-01-02T00-00-00",
@@ -1563,6 +1568,7 @@ async fn older_pagination_reconciles_review_prompts_across_page_boundaries() ->
.await?;
let started = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -1666,7 +1672,7 @@ async fn transcript_home_loads_every_older_history_page() -> Result<()> {
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.config.sqlite = SqliteConfig::new_for_testing(codex_home.path().abs());
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(2);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(2);
let thread_id = create_fake_paginated_rollout(
codex_home.path(),
"2026-01-02T00-00-00",
@@ -1734,6 +1740,7 @@ async fn transcript_home_loads_every_older_history_page() -> Result<()> {
.await?;
let started = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -1858,13 +1865,14 @@ async fn remote_legacy_history_start_negotiates_once_for_resume_and_fork() -> Re
let started = app_server.start_thread(&app.config).await?;
let resumed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
legacy_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
)
.await?;
let forked = app_server
.fork_thread(app.config.clone(), legacy_thread_id)
.fork_thread(&app.local_settings, app.config.clone(), legacy_thread_id)
.await?;
assert_ne!(started.session.thread_id, legacy_thread_id);
@@ -1981,6 +1989,7 @@ async fn assert_remote_legacy_history_retry(request: LegacyHistoryRequest) -> Re
LegacyHistoryRequest::Resume => {
let resumed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
legacy_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -1991,7 +2000,7 @@ async fn assert_remote_legacy_history_retry(request: LegacyHistoryRequest) -> Re
}
LegacyHistoryRequest::Fork => {
let forked = app_server
.fork_thread(app.config.clone(), legacy_thread_id)
.fork_thread(&app.local_settings, app.config.clone(), legacy_thread_id)
.await?;
assert_ne!(forked.session.thread_id, legacy_thread_id);
"thread/fork"
@@ -2045,6 +2054,7 @@ async fn paginated_fork_survives_post_response_hydration_failure() -> Result<()>
let started = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
parent_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -2053,7 +2063,7 @@ async fn paginated_fork_survives_post_response_hydration_failure() -> Result<()>
assert_eq!(started.session.thread_id, parent_thread_id);
let forked = app_server
.fork_thread(app.config.clone(), parent_thread_id)
.fork_thread(&app.local_settings, app.config.clone(), parent_thread_id)
.await?;
assert_ne!(forked.session.thread_id, parent_thread_id);
@@ -2070,7 +2080,7 @@ async fn underfilled_scrollback_fetches_older_pages_without_opening_the_transcri
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.config.sqlite = SqliteConfig::new_for_testing(codex_home.path().abs());
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(8);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(8);
let thread_id = create_history_rollout(
&app.config,
ThreadHistoryMode::Paginated,
@@ -2133,6 +2143,7 @@ async fn underfilled_scrollback_fetches_older_pages_without_opening_the_transcri
.await?;
let started = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -2149,6 +2160,7 @@ async fn underfilled_scrollback_fetches_older_pages_without_opening_the_transcri
/*index*/ 0,
Arc::new(crate::history_cell::new_session_info(
&app.config,
&app.local_settings,
started.session.model.as_str(),
&started.session,
/*is_first_event*/ false,
@@ -2161,7 +2173,7 @@ async fn underfilled_scrollback_fetches_older_pages_without_opening_the_transcri
.await?;
app.transcript_cells = initial_cells;
app.scrollback_has_older_history = app_server.has_older_history(thread_id);
app.config.terminal_resize_reflow.max_rows = TerminalResizeReflowMaxRows::Limit(32);
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(32);
let initial_cell_count = app.transcript_cells.len();
let initial_page_requests = recorded_params(&requests, "thread/items/list").len();
let mut tui = crate::tui::test_support::make_test_tui()?;
@@ -2270,6 +2282,7 @@ async fn paginated_workflows_never_request_full_thread_history() -> Result<()> {
app_server.remember_thread_history_mode(paginated_thread_id, ThreadHistoryMode::Legacy);
let resumed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
paginated_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -2289,12 +2302,16 @@ async fn paginated_workflows_never_request_full_thread_history() -> Result<()> {
.await?;
assert!(!cells.is_empty());
app_server
.fork_thread(app.config.clone(), paginated_thread_id)
.fork_thread(&app.local_settings, app.config.clone(), paginated_thread_id)
.await?;
let mut side_config = app.config.clone();
side_config.ephemeral = true;
app_server
.fork_side_thread(side_config, paginated_thread_id)
.fork_side_thread(
&crate::local_settings::LocalSettings::from(&side_config),
side_config,
paginated_thread_id,
)
.await?;
let paginated_reads = recorded_params(&requests, "thread/read");
@@ -2631,6 +2648,7 @@ async fn cold_paginated_subagent_transcript_excludes_inherited_parent_history()
let resumed = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
child_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
@@ -3132,6 +3150,7 @@ fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
.await?;
let root = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
root_thread_id,
app.resume_model_settings(),
@@ -3141,6 +3160,7 @@ fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
.await?;
app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
child_thread_id,
app.resume_model_settings(),
+1
View File
@@ -1207,6 +1207,7 @@ async fn owned_subagent_approval_before_thread_started_is_preserved() -> Result<
)?;
app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
child_thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,