mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
## Why Live preferences can be newer than the last successful configuration load. Starting a new thread after a reload failure could overwrite those preferences with stale settings. ## What changed Carry local settings alongside the new-session configuration, retaining the live settings when reloading fails and applying the staged settings when the new thread starts. During resume and agent selection, replace staged local settings only when the directory-trust check actually reloads configuration. ## Testing Add a regression test that changes a live rendering preference, writes invalid `config.toml`, and verifies that loading a new thread's configuration preserves the live local settings. GitOrigin-RevId: 4ac3c70de6d627e1609cc0a5d4ba5df5a61a8b20
102 lines
3.8 KiB
Rust
102 lines
3.8 KiB
Rust
//! New-session configuration from server defaults and explicit launch settings.
|
|
//!
|
|
//! Build the replacement configuration without replacing the active task's settings.
|
|
|
|
use super::*;
|
|
use codex_config::ConfigLayerSource;
|
|
|
|
pub(crate) fn has_launch_setting(
|
|
config: &Config,
|
|
cli_kv_overrides: &[(String, TomlValue)],
|
|
key: &str,
|
|
) -> bool {
|
|
// A remote server cannot resolve this invocation's explicitly selected local profile.
|
|
// Only count the profile when it supplies the effective value; project settings can shadow it.
|
|
cli_kv_overrides.iter().any(|(path, _)| path == key)
|
|
|| config
|
|
.config_layer_stack
|
|
.layers_high_to_low()
|
|
.find(|layer| layer.config.get(key).is_some())
|
|
.is_some_and(|layer| {
|
|
matches!(
|
|
layer.name,
|
|
ConfigLayerSource::User {
|
|
profile: Some(_),
|
|
..
|
|
}
|
|
)
|
|
})
|
|
}
|
|
|
|
pub(super) fn overlay_new_session_defaults(
|
|
config: &mut Config,
|
|
defaults: &codex_app_server_protocol::Config,
|
|
cli_kv_overrides: &[(String, TomlValue)],
|
|
harness_overrides: &ConfigOverrides,
|
|
) {
|
|
if harness_overrides.model.is_none() && !has_launch_setting(config, cli_kv_overrides, "model") {
|
|
config.model = defaults.model.clone();
|
|
}
|
|
if !has_launch_setting(config, cli_kv_overrides, "model_reasoning_effort") {
|
|
config.model_reasoning_effort = defaults.model_reasoning_effort.clone();
|
|
}
|
|
if !has_launch_setting(config, cli_kv_overrides, "daybreak") {
|
|
config.daybreak_enabled = defaults
|
|
.additional
|
|
.get("daybreak")
|
|
.and_then(serde_json::Value::as_bool)
|
|
.unwrap_or(false);
|
|
}
|
|
}
|
|
|
|
impl App {
|
|
pub(super) async fn load_new_session_config(
|
|
&mut self,
|
|
app_server: &AppServerSession,
|
|
) -> Result<(Config, crate::local_settings::LocalSettings)> {
|
|
let cwd = self.chat_widget.config_ref().cwd.to_path_buf();
|
|
let defaults_cwd = match app_server.thread_params_mode() {
|
|
crate::app_server_session::ThreadParamsMode::Embedded => cwd.as_path(),
|
|
crate::app_server_session::ThreadParamsMode::Remote => {
|
|
app_server.remote_cwd_override().unwrap_or(Path::new("."))
|
|
}
|
|
};
|
|
let defaults = crate::config_update::read_effective_config_if_supported(
|
|
app_server.request_handle(),
|
|
defaults_cwd,
|
|
)
|
|
.await?;
|
|
// Stage local preferences and permission carryover without changing the active task.
|
|
let (mut config, local_settings) = match self.rebuild_config_for_cwd(cwd).await {
|
|
Ok(config) => {
|
|
let settings = self.local_settings.reloaded(&config);
|
|
(config, settings)
|
|
}
|
|
Err(err) => {
|
|
tracing::warn!(%err, "failed to refresh local settings before a new thread");
|
|
(self.config.clone(), self.local_settings.clone())
|
|
}
|
|
};
|
|
if let Some(defaults) = defaults.as_ref() {
|
|
crate::projectless::apply_defaults(
|
|
&mut config,
|
|
&self.harness_overrides,
|
|
app_server,
|
|
&self.environment_manager,
|
|
defaults,
|
|
);
|
|
}
|
|
self.apply_runtime_policy_overrides(&mut config, RuntimePolicyOverrideScope::ExplicitOnly)?;
|
|
config.service_tier = self.chat_widget.configured_service_tier();
|
|
if let Some(defaults) = defaults.as_ref() {
|
|
overlay_new_session_defaults(
|
|
&mut config,
|
|
&defaults.config,
|
|
&self.cli_kv_overrides,
|
|
&self.harness_overrides,
|
|
);
|
|
}
|
|
Ok((config, local_settings))
|
|
}
|
|
}
|