Preserve session config when switching thread permission profiles (#45981)

## Why

Permission profile changes reloaded configuration without the thread's session overrides, so profiles defined at thread start could be unavailable to `thread/settings/update`.

## What changed

Reload permission configuration with the thread's merged, enabled `SessionFlags` layers, the effective working directory, and the requested profile. Preserve sandbox executable paths through `ConfigManager`.

## Testing

Add regression coverage for switching away from and back to session-defined and disk-defined profiles, including top-level profile selection. Add a config manager test for merging session layers, excluding disabled layers, and retaining filesystem access to the exec wrapper directory.

GitOrigin-RevId: b0271e28a90cd55d3faf5fdf5f044d768395b0b6
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-16 16:46:34 +00:00
1 parent d7104e268b
commit 7b6dd0c7b8
5 files changed
+191 -19

No files matched your search

@@ -702,3 +702,70 @@ fn create_config_toml(codex_home: &std::path::Path, server_uri: &str) -> std::io
.with_provider_config("supports_websockets = false")
.write(codex_home)
}
#[tokio::test]
async fn thread_settings_update_preserves_session_profiles() -> Result<()> {
for (profile_on_disk, top_level_selection) in [(false, false), (true, false), (true, true)] {
let home = TempDir::new()?;
let profile = json!({"extends": ":read-only"});
std::fs::write(
home.path().join("config.toml"),
if profile_on_disk {
"default_permissions = ':read-only'\n[permissions.audit]\nextends = ':read-only'\n"
} else {
""
},
)?;
write_models_cache(home.path()).await?;
let mut server = TestAppServer::builder()
.with_codex_home(home.path())
.build_initialized_with_timeout(DEFAULT_TIMEOUT)
.await?;
let mut config = std::collections::HashMap::from([
("default_permissions".to_string(), json!("audit")),
("features.guardian_approval".to_string(), json!(true)),
]);
if !profile_on_disk {
config.insert("permissions.audit".to_string(), profile);
}
if top_level_selection {
config.remove("default_permissions");
}
let id = server
.send_thread_start_request_with_auto_env(ThreadStartParams {
model: Some("mock-model".to_string()),
config: Some(config),
permissions: top_level_selection.then(|| "audit".to_string()),
..Default::default()
})
.await?;
let started: ThreadStartResponse =
timeout(DEFAULT_TIMEOUT, server.read_response(id)).await??;
let thread_id = started.thread.id;
for profile_id in [":workspace", "audit"] {
let id = server
.send_thread_settings_update_request(ThreadSettingsUpdateParams {
thread_id: thread_id.clone(),
permissions: Some(profile_id.to_string()),
..Default::default()
})
.await?;
let _: ThreadSettingsUpdateResponse =
timeout(DEFAULT_TIMEOUT, server.read_response(id)).await??;
let applied: ThreadSettingsUpdatedNotification = timeout(
DEFAULT_TIMEOUT,
server.read_notification("thread/settings/updated"),
)
.await??;
assert_eq!(
applied
.thread_settings
.active_permission_profile
.unwrap()
.id,
profile_id
);
}
}
Ok(())
}