Preserve restored permission profiles in TUI sessions (#41192)

## Why

Restored app-server threads can carry permission profiles that cannot be
represented without loss as legacy sandbox-mode overrides. Sending those
profiles as per-turn overrides can discard their original permission details.

## What changed

- Distinguish restored permission profiles from legacy per-turn sandbox
  overrides.
- Preserve restored profiles while routing turns and changing to compatible
  working directories.
- Reject `/cd` when a restored profile cannot be represented safely by a
  legacy sandbox mode.

## Testing

- Cover retaining a restored read-only profile across `/cd` without a turn
  override.
- Verify that lossy sandbox-mode projections are detected.

GitOrigin-RevId: 6143dca4b83ab4f59bab05f6a59b4fe841c56192
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-27 19:51:10 +00:00
1 parent 8935ff19db
commit c29bc99949
9 files changed
+167 -12

No files matched your search

@@ -2638,6 +2638,11 @@ async fn changing_directory_preserves_project_trust_permissions_history_and_hook
("../trusted", "profile", "permission profile override"),
("../trusted", "reviewer", "reviewer"),
("../p", "named", "different settings"),
(
"../trusted",
"restored",
"Permission profile cannot be preserved",
),
("../p", "keymap", "open_transcript"),
("../unknown", "local", "This directory is not trusted"),
("../trusted", "main", "background terminals"),
@@ -2659,8 +2664,17 @@ async fn changing_directory_preserves_project_trust_permissions_history_and_hook
let mut profile = RuntimePermissionProfileOverride::from_config(&app.config);
profile.active_permission_profile =
(kind == "named").then(|| ActivePermissionProfile::new("dev"));
if kind == "restored" {
profile.permission_profile = PermissionProfile::workspace_write_with(
&[failed.clone().abs()],
codex_protocol::permissions::NetworkSandboxPolicy::Restricted,
/*exclude_tmpdir_env_var*/ false,
/*exclude_slash_tmp*/ false,
);
profile.turn_override = RuntimePermissionProfileTurnOverride::Preserve;
}
app.runtime_permission_profile_override =
matches!(kind, "profile" | "reviewer" | "named").then_some(profile);
matches!(kind, "profile" | "reviewer" | "named" | "restored").then_some(profile);
app.app_server_target = crate::AppServerTarget::Embedded;
if kind == "workspace" {
let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:8765")?;
@@ -2691,6 +2705,8 @@ async fn changing_directory_preserves_project_trust_permissions_history_and_hook
let output = history().join("");
if kind == "mcp" {
assert_snapshot!(output, @"■ MCP inventory is still loading.");
} else if kind == "restored" {
assert_snapshot!(output, @"■ Permission profile cannot be preserved by /cd.");
}
assert!(output.contains(expected), "{path}");
app.clear_committed_mcp_inventory_loading();