Bind Guardian reviews to the action's target environment (#47630)

## Why

Actions targeting a secondary environment could be reviewed with the primary environment's denied-read restrictions. Each review needs the permission context of the environment that owns the action, including when a Guardian session is reused across environments.

## What changed

- Carry `environment_id` through environment-scoped approval requests and their planned-action JSON.
- Select and label permission context using the target environment, explicitly stating when it has no denied-read paths or globs.
- Reject reviews for unavailable target environments and reject environment IDs longer than 256 bytes before Guardian inference, while preserving manual approval routing for oversized IDs.

## Testing

Add coverage for `exec_command`, `apply_patch`, and `request_permissions` reviews switching environments while preserving the existing review prefix. Extend tests for environment-specific restrictions, unavailable environments, action serialization, and the 256-byte ID boundary.

GitOrigin-RevId: ad3292edddb1c6f5b180142c6857cba6f1308328
This commit is contained in:
jif
2026-09-23 19:03:12 +00:00
committed by copyberry
parent e1f3fafad8
commit 851d9e95f1
20 changed files with 488 additions and 98 deletions
+1
View File
@@ -61,6 +61,7 @@ pub(crate) use codex_context_fragments::AdditionalContextDeveloperFragment;
pub(crate) use codex_context_fragments::AdditionalContextUserFragment;
pub use codex_context_fragments::AnsweredQuestion;
pub use codex_context_fragments::ContextualUserFragment;
pub(crate) use codex_guardian_context::PermissionContext as GuardianPermissionContext;
pub(crate) use codex_prompts::MultiAgentRoleInstructions;
pub use codex_prompts::PermissionsInstructions;
pub(crate) use compaction_summary::CompactionSummary;