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

+66 -10
View File
@@ -18,6 +18,7 @@ use crate::bottom_pane::FeedbackAudience;
use crate::dynamic_tools_mcp::DynamicToolMcpServer;
use crate::dynamic_tools_mcp::ThreadToolTransport;
use crate::legacy_core::config::Config;
use crate::local_settings::LocalSettings;
use crate::service_tier_resolution;
use crate::session_state::MessageHistoryMetadata;
use crate::session_state::ThreadSessionState;
@@ -378,6 +379,15 @@ pub(crate) enum TurnPermissionsOverride {
pub(crate) struct UnsupportedLegacyPermissionProfile;
impl AppServerSession {
/// Platform of the app-server process, not necessarily its executor.
pub(crate) fn app_server_platform_family(&self) -> Option<&str> {
self.client.platform_family()
}
pub(crate) fn app_server_platform_os(&self) -> Option<&str> {
self.client.platform_os()
}
pub(crate) fn new(client: AppServerClient, thread_params_mode: ThreadParamsMode) -> Self {
Self {
client,
@@ -796,10 +806,12 @@ impl AppServerSession {
pub(crate) async fn fork_thread(
&mut self,
local_settings: &LocalSettings,
config: Config,
thread_id: ThreadId,
) -> Result<AppServerStartedThread> {
self.fork_thread_at(
local_settings,
config,
thread_id,
/*last_turn_id*/ None,
@@ -811,6 +823,7 @@ impl AppServerSession {
pub(crate) async fn fork_thread_at(
&mut self,
local_settings: &LocalSettings,
config: Config,
thread_id: ThreadId,
last_turn_id: Option<String>,
@@ -818,6 +831,7 @@ impl AppServerSession {
goal_continuation: ForkGoalContinuation,
) -> Result<AppServerStartedThread> {
self.fork_thread_at_with_presentation(
local_settings,
config,
thread_id,
last_turn_id,
@@ -830,10 +844,12 @@ impl AppServerSession {
pub(crate) async fn fork_side_thread(
&mut self,
local_settings: &LocalSettings,
config: Config,
thread_id: ThreadId,
) -> Result<AppServerStartedThread> {
self.fork_thread_at_with_presentation(
local_settings,
config,
thread_id,
/*last_turn_id*/ None,
@@ -844,8 +860,13 @@ impl AppServerSession {
.await
}
#[expect(
clippy::too_many_arguments,
reason = "keep local preferences separate while the legacy Config parameter is still required"
)]
async fn fork_thread_at_with_presentation(
&mut self,
local_settings: &LocalSettings,
config: Config,
thread_id: ThreadId,
last_turn_id: Option<String>,
@@ -919,6 +940,7 @@ impl AppServerSession {
/*turn_cursor*/ None,
/*item_cursor*/ None,
Some(&config),
Some(local_settings),
HistoryHydrationScope::Initial,
)
.await
@@ -947,9 +969,11 @@ impl AppServerSession {
let Some(model) = config.model.as_deref().or(self.default_model.as_deref()) else {
return config.clone();
};
let local_settings = LocalSettings::from(config);
let mut session_config = config.clone();
match service_tier_resolution::service_tier_update_for_core(
config,
&local_settings.notices,
model,
&self.available_models,
) {
@@ -1063,6 +1087,7 @@ impl AppServerSession {
/*turn_cursor*/ None,
/*item_cursor*/ None,
/*config*/ None,
/*local_settings*/ None,
HistoryHydrationScope::Initial,
)
.await?;
@@ -1773,8 +1798,9 @@ fn config_request_overrides_from_config(
}
fn service_tier_override_from_config(config: &Config) -> Option<Option<String>> {
let local_settings = LocalSettings::from(config);
config.service_tier.clone().map(Some).or_else(|| {
(config.notices.fast_default_opt_out == Some(true))
(local_settings.notices.fast_default_opt_out == Some(true))
.then(|| Some(SERVICE_TIER_DEFAULT_REQUEST_VALUE.to_string()))
})
}
@@ -2245,8 +2271,11 @@ async fn thread_session_state_from_thread_response(
.map(ThreadId::from_string)
.transpose()
.map_err(|err| format!("forked_from_id is invalid: {err}"))?;
let history_config =
codex_message_history::HistoryConfig::new(config.codex_home.clone(), &config.history);
let local_settings = LocalSettings::from(config);
let history_config = codex_message_history::HistoryConfig::new(
local_settings.codex_home,
&local_settings.history,
);
let (log_id, entry_count) = codex_message_history::history_metadata(&history_config).await;
Ok(ThreadSessionState {
thread_id,
@@ -3277,7 +3306,12 @@ mod tests {
app_server.available_models = vec![preset];
let resumed = app_server
.resume_thread(config, thread_id, ResumeModelSettings::RestoreFromThread)
.resume_thread(
&LocalSettings::from(&config),
config,
thread_id,
ResumeModelSettings::RestoreFromThread,
)
.await?;
assert_eq!(resumed.session.service_tier, None);
@@ -3304,6 +3338,7 @@ mod tests {
let mut app_server = crate::start_embedded_app_server_for_picker(&config).await?;
app_server
.resume_thread(
&LocalSettings::from(&config),
config.clone(),
source_thread_id,
ResumeModelSettings::RestoreFromThread,
@@ -3316,10 +3351,18 @@ mod tests {
let mut ephemeral_config = config;
ephemeral_config.ephemeral = true;
let normal_ephemeral_fork = app_server
.fork_thread(ephemeral_config.clone(), source_thread_id)
.fork_thread(
&LocalSettings::from(&ephemeral_config),
ephemeral_config.clone(),
source_thread_id,
)
.await?;
let side_fork = app_server
.fork_side_thread(ephemeral_config, source_thread_id)
.fork_side_thread(
&LocalSettings::from(&ephemeral_config),
ephemeral_config,
source_thread_id,
)
.await?;
assert_eq!(
@@ -3353,7 +3396,11 @@ mod tests {
ephemeral_config.ephemeral = true;
let fork = app_server
.fork_thread(ephemeral_config, source_thread_id)
.fork_thread(
&LocalSettings::from(&ephemeral_config),
ephemeral_config,
source_thread_id,
)
.await?;
assert_eq!(fork.session.forked_from_id, Some(source_thread_id));
@@ -3423,6 +3470,7 @@ mod tests {
let mut app_server = crate::start_embedded_app_server_for_picker(&config).await?;
let resumed = app_server
.resume_thread(
&LocalSettings::from(&config),
config.clone(),
source_thread_id,
ResumeModelSettings::RestoreFromThread,
@@ -3436,7 +3484,11 @@ mod tests {
side_config.ephemeral = true;
let next_request_id = app_server.next_request_id;
let side = app_server
.fork_side_thread(side_config, source_thread_id)
.fork_side_thread(
&LocalSettings::from(&side_config),
side_config,
source_thread_id,
)
.await?;
assert_eq!(app_server.next_request_id, next_request_id + 1);
@@ -3527,8 +3579,12 @@ mod tests {
)?;
let mut app_server = crate::start_embedded_app_server_for_picker(&config).await?;
let regular = app_server.fork_thread(config.clone(), thread_id).await?;
let side = app_server.fork_side_thread(config, thread_id).await?;
let regular = app_server
.fork_thread(&LocalSettings::from(&config), config.clone(), thread_id)
.await?;
let side = app_server
.fork_side_thread(&LocalSettings::from(&config), config, thread_id)
.await?;
assert_eq!(regular.turns.len(), 1);
assert!(matches!(