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

@@ -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(),