mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
8935ff19db
commit
c29bc99949
9 files changed
+167
-12
No files matched your search
@@ -1789,6 +1789,29 @@ fn sandbox_mode_from_permission_profile(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn permission_profile_is_safely_represented_by_sandbox_mode(
|
||||
permission_profile: &PermissionProfile,
|
||||
cwd: &std::path::Path,
|
||||
) -> bool {
|
||||
let Some(sandbox_mode) = sandbox_mode_from_permission_profile(permission_profile, cwd) else {
|
||||
return false;
|
||||
};
|
||||
let projected_profile = match sandbox_mode {
|
||||
codex_app_server_protocol::SandboxMode::ReadOnly => PermissionProfile::read_only(),
|
||||
codex_app_server_protocol::SandboxMode::WorkspaceWrite => {
|
||||
PermissionProfile::from_legacy_sandbox_policy_for_cwd(
|
||||
&codex_protocol::protocol::SandboxPolicy::new_workspace_write_policy(),
|
||||
cwd,
|
||||
)
|
||||
}
|
||||
codex_app_server_protocol::SandboxMode::DangerFullAccess => PermissionProfile::Disabled,
|
||||
};
|
||||
permission_profile.network_sandbox_policy() == projected_profile.network_sandbox_policy()
|
||||
&& permission_profile
|
||||
.file_system_sandbox_policy()
|
||||
.is_semantically_equivalent_to(&projected_profile.file_system_sandbox_policy(), cwd)
|
||||
}
|
||||
|
||||
fn permission_profile_id_from_active_profile(active: ActivePermissionProfile) -> String {
|
||||
active.id
|
||||
}
|
||||
@@ -3001,6 +3024,10 @@ mod tests {
|
||||
sandbox_mode_from_permission_profile(&permission_profile, cwd.as_path()),
|
||||
Some(codex_app_server_protocol::SandboxMode::ReadOnly)
|
||||
);
|
||||
assert!(!permission_profile_is_safely_represented_by_sandbox_mode(
|
||||
&permission_profile,
|
||||
cwd.as_path(),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user