config: remove legacy profile write paths (#24055)

## Why

[#23883](https://github.com/openai/codex/pull/23883) moved the
user-facing `--profile` flag onto profile v2 and
[#23886](https://github.com/openai/codex/pull/23886) removed CLI
forwarding for the legacy profile-v1 path. Core and TUI config
persistence still carried `active_profile` and
`ConfigEditsBuilder::with_profile`, which let later writes continue
targeting legacy `[profiles.<name>]` tables after profile selection
moved to profile-v2 config files.

## What

- Remove legacy profile routing from
[`ConfigEditsBuilder`](https://github.com/openai/codex/blob/4b38e9c22e762261d7f7eef49d8a21792e241a06/codex-rs/core/src/config/edit.rs#L1064-L1294),
so core config edits no longer carry `with_profile` or infer
`[profiles.*]` write targets from a `profile` key.
- Drop `active_profile` plumbing from runtime `Config`, TUI
startup/state, app-server config override forwarding, and Windows
sandbox setup persistence.
- Make app-server-backed TUI config edits use unscoped model,
service-tier, feature, Auto-review, plan-mode, and Windows sandbox paths
through
[`tui/src/config_update.rs`](https://github.com/openai/codex/blob/4b38e9c22e762261d7f7eef49d8a21792e241a06/codex-rs/tui/src/config_update.rs#L43-L112).
- Update config edit coverage so legacy `profile` state stays untouched
by direct model writes, and remove tests whose only contract was the
deleted profile-scoped persistence path.

## Testing

- Not run locally.
This commit is contained in:
jif-oai authored and GitHub committed 2026-05-22 12:50:42 +02:00
1 parent fd72e99384
commit 2c6605ab35
18 files changed
+107 -974

No files matched your search

-3
View File
@@ -486,7 +486,6 @@ pub(crate) struct App {
/// Config is stored here so we can recreate ChatWidgets as needed.
pub(crate) config: Config,
pub(crate) state_db: Option<StateDbHandle>,
pub(crate) active_profile: Option<String>,
cli_kv_overrides: Vec<(String, TomlValue)>,
harness_overrides: ConfigOverrides,
loader_overrides: LoaderOverrides,
@@ -693,7 +692,6 @@ impl App {
cli_kv_overrides: Vec<(String, TomlValue)>,
harness_overrides: ConfigOverrides,
loader_overrides: LoaderOverrides,
active_profile: Option<String>,
initial_prompt: Option<String>,
initial_images: Vec<PathBuf>,
session_selection: SessionSelection,
@@ -971,7 +969,6 @@ See the Codex keymap documentation for supported actions and examples."
workspace_command_runner: Some(workspace_command_runner),
config,
state_db,
active_profile,
cli_kv_overrides,
harness_overrides,
loader_overrides,
+18 -102
View File
@@ -344,7 +344,6 @@ impl App {
let auto_review_preset = auto_review_mode();
let mut next_config = self.config.clone();
let active_profile = self.active_profile.clone();
let windows_sandbox_changed = updates.iter().any(|(feature, _)| {
matches!(
feature,
@@ -356,42 +355,12 @@ impl App {
let mut permission_profile_override = None;
let mut active_permission_profile_override = None;
let mut feature_updates_to_apply = Vec::with_capacity(updates.len());
// Auto-Review owns `approvals_reviewer`, but disabling the feature
// from inside a profile should not silently clear a value configured at
// the root scope.
let (root_approvals_reviewer_blocks_profile_disable, profile_approvals_reviewer_configured) = {
let effective_config = next_config.config_layer_stack.effective_config();
let root_blocks_disable = effective_config
.as_table()
.and_then(|table| table.get("approvals_reviewer"))
.is_some_and(|value| value != &TomlValue::String("user".to_string()));
let profile_configured = active_profile.as_deref().is_some_and(|profile| {
effective_config
.as_table()
.and_then(|table| table.get("profiles"))
.and_then(TomlValue::as_table)
.and_then(|profiles| profiles.get(profile))
.and_then(TomlValue::as_table)
.is_some_and(|profile_config| profile_config.contains_key("approvals_reviewer"))
});
(root_blocks_disable, profile_configured)
};
let mut permissions_history_label: Option<&'static str> = None;
let mut config_edits = Vec::new();
for (feature, enabled) in updates {
let feature_key = feature.key();
let mut feature_edits = Vec::new();
if feature == Feature::GuardianApproval
&& !enabled
&& self.active_profile.is_some()
&& root_approvals_reviewer_blocks_profile_disable
{
self.chat_widget.add_error_message(
"Cannot disable Auto-review in this profile because `approvals_reviewer` is configured outside the active profile.".to_string(),
);
continue;
}
let mut feature_config = next_config.clone();
if let Err(err) = feature_config.features.set_enabled(feature, enabled) {
tracing::error!(
@@ -413,24 +382,16 @@ impl App {
// changes it explicitly.
feature_config.approvals_reviewer = auto_review_preset.approvals_reviewer;
feature_edits.push(crate::config_update::replace_config_value(
crate::config_update::profile_scoped_key_path(
active_profile.as_deref(),
"approvals_reviewer",
),
"approvals_reviewer",
serde_json::json!(auto_review_preset.approvals_reviewer.to_string()),
));
if previous_approvals_reviewer != auto_review_preset.approvals_reviewer {
permissions_history_label = Some("Auto-review");
}
} else if !effective_enabled {
if profile_approvals_reviewer_configured || self.active_profile.is_none() {
feature_edits.push(crate::config_update::clear_config_value(
crate::config_update::profile_scoped_key_path(
active_profile.as_deref(),
"approvals_reviewer",
),
));
}
feature_edits.push(crate::config_update::clear_config_value(
"approvals_reviewer",
));
feature_config.approvals_reviewer = ApprovalsReviewer::User;
if previous_approvals_reviewer != ApprovalsReviewer::User {
permissions_history_label = Some("Default");
@@ -463,17 +424,11 @@ impl App {
};
feature_edits.extend([
crate::config_update::replace_config_value(
crate::config_update::profile_scoped_key_path(
active_profile.as_deref(),
"approval_policy",
),
"approval_policy",
serde_json::json!("on-request"),
),
crate::config_update::replace_config_value(
crate::config_update::profile_scoped_key_path(
active_profile.as_deref(),
"sandbox_mode",
),
"sandbox_mode",
serde_json::json!("workspace-write"),
),
]);
@@ -486,7 +441,6 @@ impl App {
feature_updates_to_apply.push((feature, effective_enabled));
config_edits.extend(feature_edits);
config_edits.push(crate::config_update::build_feature_enabled_edit(
active_profile.as_deref(),
feature_key,
effective_enabled,
));
@@ -815,11 +769,8 @@ impl App {
effective_config: &ConfigReadResponse,
feature_updates: &[(Feature, bool)],
) {
let active_profile = self.active_profile.clone();
let active_profile = active_profile.as_deref();
for (feature, _) in feature_updates {
let enabled =
feature_enabled_from_effective_config(effective_config, active_profile, *feature);
let enabled = feature_enabled_from_effective_config(effective_config, *feature);
if let Err(err) = self.config.features.set_enabled(*feature, enabled) {
tracing::warn!(
error = %err,
@@ -840,14 +791,10 @@ impl App {
return;
}
if let Some(reviewer) =
approvals_reviewer_from_effective_config(effective_config, active_profile)
{
if let Some(reviewer) = approvals_reviewer_from_effective_config(effective_config) {
self.set_approvals_reviewer_in_app_and_widget(reviewer);
}
if let Some(policy) =
approval_policy_from_effective_config(effective_config, active_profile)
{
if let Some(policy) = approval_policy_from_effective_config(effective_config) {
if let Err(err) = self
.config
.permissions
@@ -876,7 +823,7 @@ impl App {
.iter()
.any(|(feature, _)| *feature == Feature::GuardianApproval)
|| !self.config.features.enabled(Feature::GuardianApproval)
|| sandbox_mode_from_effective_config(effective_config, self.active_profile.as_deref())
|| sandbox_mode_from_effective_config(effective_config)
!= Some(AppServerSandboxMode::WorkspaceWrite)
{
return;
@@ -982,10 +929,7 @@ impl App {
else {
return;
};
let Some(mode) = windows_sandbox_mode_from_effective_config(
&effective_config,
self.active_profile.as_deref(),
) else {
let Some(mode) = windows_sandbox_mode_from_effective_config(&effective_config) else {
return;
};
self.config.permissions.windows_sandbox_mode = Some(mode);
@@ -1026,59 +970,38 @@ fn overridden_write_message(write_response: &ConfigWriteResponse) -> &str {
fn feature_enabled_from_effective_config(
effective_config: &ConfigReadResponse,
active_profile: Option<&str>,
feature: Feature,
) -> bool {
let profile_features = active_profile
.and_then(|profile| effective_config.config.profiles.get(profile))
.and_then(|profile| profile.additional.get("features"))
.and_then(features_toml_from_json);
let root_features = effective_config
.config
.additional
.get("features")
.and_then(features_toml_from_json);
profile_features
root_features
.as_ref()
.and_then(|features| features.entries().get(feature.key()).copied())
.or_else(|| {
root_features
.as_ref()
.and_then(|features| features.entries().get(feature.key()).copied())
})
.unwrap_or_else(|| feature.default_enabled())
}
fn approvals_reviewer_from_effective_config(
effective_config: &ConfigReadResponse,
active_profile: Option<&str>,
) -> Option<ApprovalsReviewer> {
active_profile
.and_then(|profile| effective_config.config.profiles.get(profile))
.and_then(|profile| profile.approvals_reviewer)
.or(effective_config.config.approvals_reviewer)
effective_config
.config
.approvals_reviewer
.map(codex_app_server_protocol::ApprovalsReviewer::to_core)
}
fn approval_policy_from_effective_config(
effective_config: &ConfigReadResponse,
active_profile: Option<&str>,
) -> Option<AskForApproval> {
active_profile
.and_then(|profile| effective_config.config.profiles.get(profile))
.and_then(|profile| profile.approval_policy)
.or(effective_config.config.approval_policy)
effective_config.config.approval_policy
}
fn sandbox_mode_from_effective_config(
effective_config: &ConfigReadResponse,
active_profile: Option<&str>,
) -> Option<AppServerSandboxMode> {
active_profile
.and_then(|profile| effective_config.config.profiles.get(profile))
.and_then(|profile| profile.additional.get("sandbox_mode"))
.and_then(|mode| serde_json::from_value(mode.clone()).ok())
.or(effective_config.config.sandbox_mode)
effective_config.config.sandbox_mode
}
fn memories_from_effective_config(effective_config: &ConfigReadResponse) -> Option<MemoriesToml> {
@@ -1096,20 +1019,13 @@ fn features_toml_from_json(value: &serde_json::Value) -> Option<FeaturesToml> {
#[cfg(target_os = "windows")]
fn windows_sandbox_mode_from_effective_config(
effective_config: &ConfigReadResponse,
active_profile: Option<&str>,
) -> Option<codex_config::types::WindowsSandboxModeToml> {
let profile_windows = active_profile
.and_then(|profile| effective_config.config.profiles.get(profile))
.and_then(|profile| profile.additional.get("windows"))
.and_then(windows_toml_from_json);
let root_windows = effective_config
.config
.additional
.get("windows")
.and_then(windows_toml_from_json);
profile_windows
.and_then(|windows| windows.sandbox)
.or_else(|| root_windows.and_then(|windows| windows.sandbox))
root_windows.and_then(|windows| windows.sandbox)
}
#[cfg(target_os = "windows")]
+19 -77
View File
@@ -1158,12 +1158,9 @@ impl App {
&[("result", "success")],
);
}
let profile = self.active_profile.as_deref();
let elevated_enabled = matches!(mode, WindowsSandboxEnableMode::Elevated);
let edits = crate::config_update::build_windows_sandbox_mode_edits(
profile,
elevated_enabled,
);
let edits =
crate::config_update::build_windows_sandbox_mode_edits(elevated_enabled);
match crate::config_update::write_config_batch(
app_server.request_handle(),
edits,
@@ -1299,14 +1296,9 @@ impl App {
}
}
AppEvent::PersistModelSelection { model, effort } => {
let profile = self.active_profile.as_deref();
match crate::config_update::write_config_batch(
app_server.request_handle(),
crate::config_update::build_model_selection_edits(
profile,
model.as_str(),
effort,
),
crate::config_update::build_model_selection_edits(model.as_str(), effort),
)
.await
{
@@ -1320,11 +1312,6 @@ impl App {
message.push(' ');
message.push_str(label);
}
if let Some(profile) = profile {
message.push_str(" for ");
message.push_str(profile);
message.push_str(" profile");
}
self.chat_widget.add_info_message(message, /*hint*/ None);
}
Err(err) => {
@@ -1332,14 +1319,8 @@ impl App {
error = %err,
"failed to persist model selection"
);
if let Some(profile) = profile {
self.chat_widget.add_error_message(format!(
"Failed to save model for profile `{profile}`: {err}"
));
} else {
self.chat_widget
.add_error_message(format!("Failed to save default model: {err}"));
}
self.chat_widget
.add_error_message(format!("Failed to save default model: {err}"));
}
}
}
@@ -1381,11 +1362,10 @@ impl App {
self.chat_widget.on_plugin_mentions_loaded(plugins);
}
AppEvent::PersistPersonalitySelection { personality } => {
let profile = self.active_profile.as_deref();
match crate::config_update::write_config_batch(
app_server.request_handle(),
vec![crate::config_update::replace_config_value(
crate::config_update::profile_scoped_key_path(profile, "personality"),
"personality",
serde_json::json!(personality.to_string()),
)],
)
@@ -1393,12 +1373,7 @@ impl App {
{
Ok(_) => {
let label = Self::personality_label(personality);
let mut message = format!("Personality set to {label}");
if let Some(profile) = profile {
message.push_str(" for ");
message.push_str(profile);
message.push_str(" profile");
}
let message = format!("Personality set to {label}");
self.chat_widget.add_info_message(message, /*hint*/ None);
}
Err(err) => {
@@ -1406,15 +1381,9 @@ impl App {
error = %err,
"failed to persist personality selection"
);
if let Some(profile) = profile {
self.chat_widget.add_error_message(format!(
"Failed to save personality for profile `{profile}`: {err}"
));
} else {
self.chat_widget.add_error_message(format!(
"Failed to save default personality: {err}"
));
}
self.chat_widget.add_error_message(format!(
"Failed to save default personality: {err}"
));
}
}
}
@@ -1423,38 +1392,25 @@ impl App {
self.config.service_tier = service_tier.clone();
self.sync_active_thread_service_tier_to_cached_session()
.await;
let profile = self.active_profile.as_deref();
let edits = crate::config_update::build_service_tier_selection_edits(
profile,
service_tier.as_deref(),
);
match crate::config_update::write_config_batch(app_server.request_handle(), edits)
.await
{
Ok(_) => {
let mut message = if let Some(service_tier) = service_tier {
let message = if let Some(service_tier) = service_tier {
format!("Service tier set to {service_tier}")
} else {
"Service tier cleared".to_string()
};
if let Some(profile) = profile {
message.push_str(" for ");
message.push_str(profile);
message.push_str(" profile");
}
self.chat_widget.add_info_message(message, /*hint*/ None);
}
Err(err) => {
tracing::error!(error = %err, "failed to persist service tier selection");
if let Some(profile) = profile {
self.chat_widget.add_error_message(format!(
"Failed to save service tier for profile `{profile}`: {err}"
));
} else {
self.chat_widget.add_error_message(format!(
"Failed to save default service tier: {err}"
));
}
self.chat_widget.add_error_message(format!(
"Failed to save default service tier: {err}"
));
}
}
}
@@ -1603,14 +1559,10 @@ impl App {
self.chat_widget.set_approvals_reviewer(policy);
self.sync_active_thread_permission_settings_to_cached_session()
.await;
let profile = self.active_profile.as_deref();
if let Err(err) = crate::config_update::write_config_batch(
app_server.request_handle(),
vec![crate::config_update::replace_config_value(
crate::config_update::profile_scoped_key_path(
profile,
"approvals_reviewer",
),
"approvals_reviewer",
serde_json::json!(policy.to_string()),
)],
)
@@ -1706,11 +1658,7 @@ impl App {
}
}
AppEvent::PersistPlanModeReasoningEffort(effort) => {
let profile = self.active_profile.as_deref();
let key_path = crate::config_update::profile_scoped_key_path(
profile,
"plan_mode_reasoning_effort",
);
let key_path = "plan_mode_reasoning_effort";
let edit = if let Some(effort) = effort {
crate::config_update::replace_config_value(
key_path,
@@ -1729,15 +1677,9 @@ impl App {
error = %err,
"failed to persist plan mode reasoning effort"
);
if let Some(profile) = profile {
self.chat_widget.add_error_message(format!(
"Failed to save Plan mode reasoning effort for profile `{profile}`: {err}"
));
} else {
self.chat_widget.add_error_message(format!(
"Failed to save Plan mode reasoning effort: {err}"
));
}
self.chat_widget.add_error_message(format!(
"Failed to save Plan mode reasoning effort: {err}"
));
}
}
AppEvent::PersistModelMigrationPromptAcknowledged {
-1
View File
@@ -22,7 +22,6 @@ pub(super) async fn make_test_app() -> App {
workspace_command_runner: None,
config,
state_db: None,
active_profile: None,
cli_kv_overrides: Vec::new(),
harness_overrides: ConfigOverrides::default(),
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
-235
View File
@@ -2041,239 +2041,6 @@ async fn update_feature_flags_disabling_guardian_clears_manual_review_policy_wit
Ok(())
}
#[tokio::test]
async fn update_feature_flags_enabling_guardian_in_profile_sets_profile_auto_review_policy()
-> Result<()> {
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
let auto_review = auto_review_mode();
app.active_profile = Some("guardian".to_string());
let config_toml_path = codex_home.path().join("config.toml").abs();
let config_toml = "profile = \"guardian\"\napprovals_reviewer = \"user\"\n";
std::fs::write(config_toml_path.as_path(), config_toml)?;
let user_config = toml::from_str::<TomlValue>(config_toml)?;
app.config.config_layer_stack = app
.config
.config_layer_stack
.with_user_config(&config_toml_path, user_config);
app.config.approvals_reviewer = ApprovalsReviewer::User;
app.chat_widget
.set_approvals_reviewer(ApprovalsReviewer::User);
let mut app_server = start_config_write_test_app_server(&app).await?;
app.update_feature_flags(&mut app_server, vec![(Feature::GuardianApproval, true)])
.await;
assert!(app.config.features.enabled(Feature::GuardianApproval));
assert_eq!(
app.config.approvals_reviewer,
auto_review.approvals_reviewer
);
assert_eq!(
app.chat_widget.config_ref().approvals_reviewer,
auto_review.approvals_reviewer
);
assert_eq!(
op_rx.try_recv(),
Ok(Op::OverrideTurnContext {
cwd: None,
approval_policy: Some(auto_review.approval_policy),
approvals_reviewer: Some(auto_review.approvals_reviewer),
permission_profile: Some(auto_review.permission_profile()),
active_permission_profile: Some(auto_review.active_permission_profile.clone()),
windows_sandbox_level: None,
model: None,
effort: None,
summary: None,
service_tier: None,
collaboration_mode: None,
personality: None,
})
);
let config = std::fs::read_to_string(codex_home.path().join("config.toml"))?;
let config_value = toml::from_str::<TomlValue>(&config)?;
let profile_config = config_value
.as_table()
.and_then(|table| table.get("profiles"))
.and_then(TomlValue::as_table)
.and_then(|profiles| profiles.get("guardian"))
.and_then(TomlValue::as_table)
.expect("guardian profile should exist");
assert_eq!(
config_value
.as_table()
.and_then(|table| table.get("approvals_reviewer")),
Some(&TomlValue::String("user".to_string()))
);
assert_eq!(
profile_config.get("approvals_reviewer"),
Some(&TomlValue::String("guardian_subagent".to_string()))
);
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
async fn update_feature_flags_disabling_guardian_in_profile_allows_inherited_user_reviewer()
-> Result<()> {
let (mut app, mut app_event_rx, mut op_rx) = make_test_app_with_channels().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.active_profile = Some("guardian".to_string());
let config_toml_path = codex_home.path().join("config.toml").abs();
let config_toml = r#"
profile = "guardian"
approvals_reviewer = "user"
[profiles.guardian]
approvals_reviewer = "guardian_subagent"
[profiles.guardian.features]
guardian_approval = true
"#;
std::fs::write(config_toml_path.as_path(), config_toml)?;
let user_config = toml::from_str::<TomlValue>(config_toml)?;
app.config.config_layer_stack = app
.config
.config_layer_stack
.with_user_config(&config_toml_path, user_config);
app.config
.features
.set_enabled(Feature::GuardianApproval, /*enabled*/ true)?;
app.chat_widget
.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ true);
app.config.approvals_reviewer = ApprovalsReviewer::AutoReview;
app.chat_widget
.set_approvals_reviewer(ApprovalsReviewer::AutoReview);
let mut app_server = start_config_write_test_app_server(&app).await?;
app.update_feature_flags(&mut app_server, vec![(Feature::GuardianApproval, false)])
.await;
assert!(!app.config.features.enabled(Feature::GuardianApproval));
assert!(
!app.chat_widget
.config_ref()
.features
.enabled(Feature::GuardianApproval)
);
assert_eq!(app.config.approvals_reviewer, ApprovalsReviewer::User);
assert_eq!(
app.chat_widget.config_ref().approvals_reviewer,
ApprovalsReviewer::User
);
assert_eq!(
op_rx.try_recv(),
Ok(Op::OverrideTurnContext {
cwd: None,
approval_policy: None,
approvals_reviewer: Some(ApprovalsReviewer::User),
permission_profile: None,
active_permission_profile: None,
windows_sandbox_level: None,
model: None,
effort: None,
summary: None,
service_tier: None,
collaboration_mode: None,
personality: None,
})
);
let cell = match app_event_rx.try_recv() {
Ok(AppEvent::InsertHistoryCell(cell)) => cell,
other => panic!("expected InsertHistoryCell event, got {other:?}"),
};
let rendered = cell
.display_lines(/*width*/ 120)
.into_iter()
.map(|line| line.to_string())
.collect::<Vec<_>>()
.join("\n");
assert!(rendered.contains("Permissions updated to Default"));
let config = std::fs::read_to_string(codex_home.path().join("config.toml"))?;
assert!(!config.contains("guardian_approval = true"));
assert!(!config.contains("guardian_subagent"));
assert_eq!(
toml::from_str::<TomlValue>(&config)?
.as_table()
.and_then(|table| table.get("approvals_reviewer")),
Some(&TomlValue::String("user".to_string()))
);
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
async fn update_feature_flags_disabling_guardian_in_profile_keeps_inherited_non_user_reviewer_enabled()
-> Result<()> {
let (mut app, mut app_event_rx, mut op_rx) = make_test_app_with_channels().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.active_profile = Some("guardian".to_string());
let config_toml_path = codex_home.path().join("config.toml").abs();
let config_toml = "profile = \"guardian\"\napprovals_reviewer = \"guardian_subagent\"\n\n[features]\nguardian_approval = true\n";
std::fs::write(config_toml_path.as_path(), config_toml)?;
let user_config = toml::from_str::<TomlValue>(config_toml)?;
app.config.config_layer_stack = app
.config
.config_layer_stack
.with_user_config(&config_toml_path, user_config);
app.config
.features
.set_enabled(Feature::GuardianApproval, /*enabled*/ true)?;
app.chat_widget
.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ true);
app.config.approvals_reviewer = ApprovalsReviewer::AutoReview;
app.chat_widget
.set_approvals_reviewer(ApprovalsReviewer::AutoReview);
let mut app_server = start_config_write_test_app_server(&app).await?;
app.update_feature_flags(&mut app_server, vec![(Feature::GuardianApproval, false)])
.await;
assert!(app.config.features.enabled(Feature::GuardianApproval));
assert!(
app.chat_widget
.config_ref()
.features
.enabled(Feature::GuardianApproval)
);
assert_eq!(app.config.approvals_reviewer, ApprovalsReviewer::AutoReview);
assert_eq!(
app.chat_widget.config_ref().approvals_reviewer,
ApprovalsReviewer::AutoReview
);
assert!(
op_rx.try_recv().is_err(),
"disabling an inherited non-user reviewer should not patch the active session"
);
let app_events = std::iter::from_fn(|| app_event_rx.try_recv().ok()).collect::<Vec<_>>();
assert!(
!app_events.iter().any(|event| match event {
AppEvent::InsertHistoryCell(cell) => cell
.display_lines(/*width*/ 120)
.iter()
.any(|line| line.to_string().contains("Permissions updated to")),
_ => false,
}),
"blocking disable with inherited guardian review should not emit a permissions history update: {app_events:?}"
);
let config = std::fs::read_to_string(codex_home.path().join("config.toml"))?;
assert!(config.contains("guardian_approval = true"));
assert_eq!(
toml::from_str::<TomlValue>(&config)?
.as_table()
.and_then(|table| table.get("approvals_reviewer")),
Some(&TomlValue::String("guardian_subagent".to_string()))
);
app_server.shutdown().await?;
Ok(())
}
#[tokio::test]
async fn open_agent_picker_allows_existing_agent_threads_when_feature_is_disabled() -> Result<()> {
let (mut app, mut app_event_rx, _op_rx) = Box::pin(make_test_app_with_channels()).await;
@@ -3979,7 +3746,6 @@ async fn make_test_app() -> App {
workspace_command_runner: None,
config,
state_db: None,
active_profile: None,
cli_kv_overrides: Vec::new(),
harness_overrides: ConfigOverrides::default(),
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
@@ -4043,7 +3809,6 @@ async fn make_test_app_with_channels() -> (
workspace_command_runner: None,
config,
state_db: None,
active_profile: None,
cli_kv_overrides: Vec::new(),
harness_overrides: ConfigOverrides::default(),
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
-1
View File
@@ -1224,7 +1224,6 @@ fn config_request_overrides_from_config(
overrides.insert(key.to_string(), serde_json::Value::String(value));
}
};
insert("profile", config.active_profile.clone());
insert(
"model_reasoning_effort",
config
+12 -47
View File
@@ -35,49 +35,33 @@ pub(crate) fn clear_config_value(key_path: impl Into<String>) -> ConfigEdit {
replace_config_value(key_path, JsonValue::Null)
}
pub(crate) fn profile_scoped_key_path(profile: Option<&str>, key_path: &str) -> String {
if let Some(profile) = profile {
let profile = serde_json::Value::String(profile.to_string()).to_string();
format!("profiles.{profile}.{key_path}")
} else {
key_path.to_string()
}
}
pub(crate) fn app_scoped_key_path(app_id: &str, key_path: &str) -> String {
let app_id = serde_json::Value::String(app_id.to_string()).to_string();
format!("apps.{app_id}.{key_path}")
}
pub(crate) fn build_model_selection_edits(
profile: Option<&str>,
model: &str,
effort: Option<impl ToString>,
) -> Vec<ConfigEdit> {
let effort_edit = effort.map_or_else(
|| clear_config_value(profile_scoped_key_path(profile, "model_reasoning_effort")),
|| clear_config_value("model_reasoning_effort"),
|effort| {
replace_config_value(
profile_scoped_key_path(profile, "model_reasoning_effort"),
"model_reasoning_effort",
serde_json::json!(effort.to_string()),
)
},
);
vec![
replace_config_value(
profile_scoped_key_path(profile, "model"),
serde_json::json!(model),
),
replace_config_value("model", serde_json::json!(model)),
effort_edit,
]
}
pub(crate) fn build_service_tier_selection_edits(
profile: Option<&str>,
service_tier: Option<&str>,
) -> Vec<ConfigEdit> {
pub(crate) fn build_service_tier_selection_edits(service_tier: Option<&str>) -> Vec<ConfigEdit> {
let service_tier_edit = service_tier.map_or_else(
|| clear_config_value(profile_scoped_key_path(profile, "service_tier")),
|| clear_config_value("service_tier"),
|service_tier| {
let config_value = if service_tier == SERVICE_TIER_DEFAULT_REQUEST_VALUE {
SERVICE_TIER_DEFAULT_REQUEST_VALUE
@@ -88,25 +72,18 @@ pub(crate) fn build_service_tier_selection_edits(
None => service_tier,
}
};
replace_config_value(
profile_scoped_key_path(profile, "service_tier"),
serde_json::json!(config_value),
)
replace_config_value("service_tier", serde_json::json!(config_value))
},
);
vec![service_tier_edit]
}
#[cfg(target_os = "windows")]
pub(crate) fn build_windows_sandbox_mode_edits(
profile: Option<&str>,
elevated_enabled: bool,
) -> Vec<ConfigEdit> {
let feature_key_path =
|feature: &str| profile_scoped_key_path(profile, &format!("features.{feature}"));
pub(crate) fn build_windows_sandbox_mode_edits(elevated_enabled: bool) -> Vec<ConfigEdit> {
let feature_key_path = |feature: &str| format!("features.{feature}");
vec![
replace_config_value(
profile_scoped_key_path(profile, "windows.sandbox"),
"windows.sandbox",
serde_json::json!(if elevated_enabled {
"elevated"
} else {
@@ -119,17 +96,13 @@ pub(crate) fn build_windows_sandbox_mode_edits(
]
}
pub(crate) fn build_feature_enabled_edit(
profile: Option<&str>,
feature_key: &str,
enabled: bool,
) -> ConfigEdit {
let key_path = profile_scoped_key_path(profile, &format!("features.{feature_key}"));
pub(crate) fn build_feature_enabled_edit(feature_key: &str, enabled: bool) -> ConfigEdit {
let key_path = format!("features.{feature_key}");
let is_default_false_feature = FEATURES
.iter()
.find(|spec| spec.key == feature_key)
.is_some_and(|spec| !spec.default_enabled);
if enabled || profile.is_some() || !is_default_false_feature {
if enabled || !is_default_false_feature {
replace_config_value(key_path, serde_json::json!(enabled))
} else {
clear_config_value(key_path)
@@ -210,14 +183,6 @@ mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn profile_scoped_key_path_quotes_dotted_profile_names() {
assert_eq!(
profile_scoped_key_path(Some("team.prod"), "model"),
"profiles.\"team.prod\".model"
);
}
#[test]
fn app_scoped_key_path_quotes_dotted_app_ids() {
assert_eq!(
-2
View File
@@ -1658,7 +1658,6 @@ async fn run_ratatui_app(
}
set_default_client_residency_requirement(config.enforce_residency.value());
let active_profile = config.active_profile.clone();
let should_show_trust_screen = should_show_trust_screen(&config);
let should_prompt_windows_sandbox_nux_at_startup = cfg!(target_os = "windows")
&& trust_decision_was_made
@@ -1716,7 +1715,6 @@ async fn run_ratatui_app(
cli_kv_overrides.clone(),
overrides.clone(),
loader_overrides.clone(),
active_profile,
prompt,
images,
session_selection,
-39
View File
@@ -272,7 +272,6 @@ struct PickerPage {
#[derive(Clone)]
struct SessionPickerViewPersistence {
codex_home: PathBuf,
active_profile: Option<String>,
}
struct SessionPickerRunOptions {
@@ -369,7 +368,6 @@ async fn run_resume_picker_with_launch_context(
initial_density: SessionListDensity::from(config.tui_session_picker_view),
view_persistence: Some(SessionPickerViewPersistence {
codex_home: config.codex_home.to_path_buf(),
active_profile: config.active_profile.clone(),
}),
pager_keymap: runtime_keymap.pager,
list_keymap: runtime_keymap.list,
@@ -415,7 +413,6 @@ pub async fn run_fork_picker_with_app_server(
initial_density: SessionListDensity::from(config.tui_session_picker_view),
view_persistence: Some(SessionPickerViewPersistence {
codex_home: config.codex_home.to_path_buf(),
active_profile: config.active_profile.clone(),
}),
pager_keymap: runtime_keymap.pager,
list_keymap: runtime_keymap.list,
@@ -1679,7 +1676,6 @@ impl PickerState {
};
ConfigEditsBuilder::new(&persistence.codex_home)
.with_profile(persistence.active_profile.as_deref())
.set_session_picker_view(SessionPickerViewMode::from(self.density))
.apply()
.await
@@ -4444,7 +4440,6 @@ mod tests {
);
state.view_persistence = Some(SessionPickerViewPersistence {
codex_home: tmp.path().to_path_buf(),
active_profile: None,
});
state
@@ -4463,39 +4458,6 @@ session_picker_view = "dense"
);
}
#[tokio::test]
async fn ctrl_o_persists_density_preference_for_active_profile() {
let tmp = tempdir().expect("tmpdir");
let loader = page_only_loader(|_| {});
let mut state = PickerState::new(
FrameRequester::test_dummy(),
loader,
ProviderFilter::MatchDefault(String::from("openai")),
/*show_all*/ true,
/*filter_cwd*/ None,
SessionPickerAction::Resume,
);
state.view_persistence = Some(SessionPickerViewPersistence {
codex_home: tmp.path().to_path_buf(),
active_profile: Some(String::from("work")),
});
state
.handle_key(KeyEvent::new(KeyCode::Char('o'), KeyModifiers::CONTROL))
.await
.unwrap();
assert_eq!(state.density, SessionListDensity::Dense);
let contents =
std::fs::read_to_string(tmp.path().join(CONFIG_TOML_FILE)).expect("read config");
assert_eq!(
contents,
r#"[profiles.work.tui]
session_picker_view = "dense"
"#
);
}
#[tokio::test]
async fn ctrl_o_keeps_toggled_density_when_persistence_fails() {
let tmp = tempdir().expect("tmpdir");
@@ -4512,7 +4474,6 @@ session_picker_view = "dense"
);
state.view_persistence = Some(SessionPickerViewPersistence {
codex_home: codex_home_file,
active_profile: None,
});
state