Preserve saved sandbox permissions when resuming codex exec (#62194)

## Why

`codex exec resume` sends the current process's sandbox defaults as
overrides. A session started with `:read-only` can therefore resume with
workspace write access when the configured default is `:workspace`.

## What changed

- Restore the saved permission selection, working directory, and workspace
  roots by default. Honor explicit overrides and append directories requested
  with `--add-dir` to the resumed workspace roots.
- Recover built-in read-only permissions from older history without widening
  current read access. Require an explicit permission selection when a saved
  named profile cannot be loaded or saved read-only access cannot be restored.
- Report sandbox permissions and writable roots from the running thread.

## Testing

Add regression coverage for a denied write on the first resumed shell call,
legacy read-only history, explicit permission overrides, and workspace root
preservation with and without `--add-dir`.

GitOrigin-RevId: ed2cf3132f9ce34570661f801c9534a55696e3a5
This commit is contained in:
viyatb-oai
2026-11-18 05:13:56 +00:00
committed by copyberry
parent b78fa4af86
commit 89feadf3cc
16 changed files with 756 additions and 150 deletions
@@ -65,7 +65,7 @@ pub fn summarize_permission_profile(
}
}
if workspace_writable {
if workspace_writable && (cwd.is_opaque() || policy.can_write_path(cwd, &context)) {
let mut writable_entries = vec!["workdir".to_string()];
if slash_tmp_writable {
writable_entries.push("/tmp".to_string());
@@ -77,10 +77,12 @@ pub fn summarize_permission_profile(
workspace_roots
.iter()
.filter(|root| root.to_string() != cwd.to_string())
.filter(|root| policy.can_write_path(root, &context))
.map(PathUri::inferred_native_path_string),
);
format!("workspace-write [{}]", writable_entries.join(", "))
} else if other_writes
} else if workspace_writable
|| other_writes
|| tmpdir_writable
|| (cwd.infer_path_convention() == Some(PathConvention::Posix)
&& slash_tmp_writable)