Decouple session isolation from subagent attribution (#44521)

## Why

Session isolation relied on Guardian source attribution. An explicit policy lets callers control inherited capabilities independently of how a session is attributed.

## What changed

- Add `SessionIsolation` with default `Inherit` and opt-in `Isolated` modes, captured at session startup through `ExtensionDataInit`.
- Use the policy to control inherited instructions, extensions, execution rules, and MCP resources. Isolated sessions retain managed execution rules and omit executor-discovered MCP servers.
- Explicitly isolate Guardian reviewers while preserving source-based fallback for older callers and saved reviewers.

## Testing

Extend delegate tests to cover isolation independently of attribution, update execution-policy coverage to supply the explicit policy, and assert that managed reviewers do not inherit the parent's configured MCP tools.

GitOrigin-RevId: f0ab42fa2f0237860ec661e72693ab191216afbf
This commit is contained in:
jif authored and copyberry committed 2026-09-10 12:52:27 +00:00
1 parent 9688359977
commit ed6dde9fda
14 files changed
+83 -18

No files matched your search

+15 -2
View File
@@ -1932,13 +1932,26 @@ impl ThreadManagerState {
environments,
inherited_environments: captured_environments,
user_instructions: supplied_user_instructions,
thread_extension_init,
mut thread_extension_init,
client_mcp_extensions,
reserved_thread_id,
disabled_plugin_ids,
} = options;
let inherited_environments = captured_environments.or(inherited_environments);
let session_source = session_source.unwrap_or_else(|| self.session_source.clone());
// Older callers and saved reviewers identify isolation through their source.
// New internal callers supply an explicit runtime policy before startup.
let isolation = thread_extension_init
.get::<codex_extension_api::SessionIsolation>()
.map(|policy| *policy)
.unwrap_or_else(|| {
if crate::guardian::is_basic_session_source(&session_source) {
codex_extension_api::SessionIsolation::Isolated
} else {
codex_extension_api::SessionIsolation::Inherit
}
});
thread_extension_init.insert(isolation);
let environments = environments.unwrap_or_else(|| {
default_thread_environment_selections(
self.environment_manager.as_ref(),
@@ -1989,7 +2002,7 @@ impl ThreadManagerState {
extensions,
mcp_manager,
multi_agent_version,
) = if crate::guardian::is_basic_session_source(&session_source) {
) = if isolation == codex_extension_api::SessionIsolation::Isolated {
(
LoadedUserInstructions::default(),
None,