From acd1a3794b73bee141702281cabc0f042d30c8c8 Mon Sep 17 00:00:00 2001 From: jif Date: Mon, 30 Nov 2026 12:39:05 +0000 Subject: [PATCH] Frame pending native multi-agent calls in Guardian reviews (#64729) ## What changed When native multi-agent v2 history is enabled, Guardian automatically frames the pending call and its paired output as a distinct approval request. Mark the separate `guardian_native_action_framing` flag as removed. ## Testing Update the incremental review snapshot to capture the framed `send_message` and its paired output. Update the root handoff test to match setup handoffs at the approval boundary so historical calls cannot mask the final command's separate denial. GitOrigin-RevId: 5194a8cdf21e5d71f3a7942c0ce637f115316476 --- codex-rs/core/src/guardian/attached_review.rs | 2 +- codex-rs/core/src/guardian/prompt.rs | 21 +++++---------- .../core/tests/suite/guardian_root_handoff.rs | 27 +++++++++---------- ...scenarios_guardian_agent_messages_tests.rs | 5 ++-- ...survives_incremental_guardian_reviews.snap | 2 +- codex-rs/features/src/lib.rs | 4 +-- 6 files changed, 25 insertions(+), 36 deletions(-) diff --git a/codex-rs/core/src/guardian/attached_review.rs b/codex-rs/core/src/guardian/attached_review.rs index a3e37c1200..dd4d5f7eef 100644 --- a/codex-rs/core/src/guardian/attached_review.rs +++ b/codex-rs/core/src/guardian/attached_review.rs @@ -155,7 +155,7 @@ impl AttachedApproval { action, permissions.as_ref(), config.spawn_config.guardian_context_budgeting(), - approval.context.frame_native_agent_actions(), + approval.context.native_agent_history_enabled(), ) .map_err(|err| GuardianReviewSessionOutcome::PromptBuildFailed(err.into()))?; let request = review_turn( diff --git a/codex-rs/core/src/guardian/prompt.rs b/codex-rs/core/src/guardian/prompt.rs index 14f69481ca..e3a45873a6 100644 --- a/codex-rs/core/src/guardian/prompt.rs +++ b/codex-rs/core/src/guardian/prompt.rs @@ -30,20 +30,11 @@ use super::GuardianReviewContext; pub(super) use codex_guardian_reviewer::GUARDIAN_TRANSCRIPT_START; impl GuardianReviewContext { - fn native_agent_history_enabled(&self) -> bool { + pub(super) fn native_agent_history_enabled(&self) -> bool { let turn = self.turn(); turn.config.guardian_native_multi_agent_history_enabled() && turn.multi_agent_version == codex_protocol::protocol::MultiAgentVersion::V2 } - - pub(super) fn frame_native_agent_actions(&self) -> bool { - self.native_agent_history_enabled() - && self - .turn() - .config - .features - .enabled(codex_features::Feature::GuardianNativeActionFraming) - } } /// Selects transcript evidence using the checkpoint already loaded by the reviewer. @@ -163,9 +154,10 @@ pub(super) async fn collect_guardian_prompt_items_with_parent_turn( }); let mut profile = ContextProfile::synchronous(); profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit; - profile.transcript.options.native_multi_agent_namespace = parent_context - .is_some_and(GuardianReviewContext::native_agent_history_enabled) - .then(|| { + let native_agent_history_enabled = + parent_context.is_some_and(GuardianReviewContext::native_agent_history_enabled); + profile.transcript.options.native_multi_agent_namespace = + native_agent_history_enabled.then(|| { config .multi_agent_v2 .tool_namespace @@ -173,8 +165,7 @@ pub(super) async fn collect_guardian_prompt_items_with_parent_turn( .filter(|namespace| !namespace.is_empty()) .unwrap_or_else(|| "functions".to_owned()) }); - profile.transcript.options.frame_native_agent_actions = - parent_context.is_some_and(GuardianReviewContext::frame_native_agent_actions); + profile.transcript.options.frame_native_agent_actions = native_agent_history_enabled; profile.transcript_format = match parent_context { Some(context) => context.turn().config.guardian_transcript_mode, None => config.guardian_transcript_mode, diff --git a/codex-rs/core/tests/suite/guardian_root_handoff.rs b/codex-rs/core/tests/suite/guardian_root_handoff.rs index feb888bae0..af8c9440a7 100644 --- a/codex-rs/core/tests/suite/guardian_root_handoff.rs +++ b/codex-rs/core/tests/suite/guardian_root_handoff.rs @@ -91,26 +91,25 @@ pub(crate) async fn handoff_scenario(native_history: bool) -> Result>> APPROVAL REQUEST END")) + && output["type"] == "function_call_output" + && matches!( + output["call_id"].as_str(), + Some("spawn-alpha" | "spawn-leaf" | "spawn-beta" | "send-alpha" | "followup-alpha") + ) }) }) .respond_with(sse_response(sse(vec![ diff --git a/codex-rs/core/tests/suite/scenarios_guardian_agent_messages_tests.rs b/codex-rs/core/tests/suite/scenarios_guardian_agent_messages_tests.rs index 6e4786fcc3..052793b319 100644 --- a/codex-rs/core/tests/suite/scenarios_guardian_agent_messages_tests.rs +++ b/codex-rs/core/tests/suite/scenarios_guardian_agent_messages_tests.rs @@ -117,7 +117,7 @@ async fn native_agent_review_requires_openai_on_start_and_resume( Ok(()) } -#[cfg_attr(not(target_os = "windows"), test_case(None; "agent_reply"))] +#[cfg_attr(not(target_os = "windows"), test_case(None; "agent_reply_and_pending_send_message"))] #[test_case(Some("functions"); "native_default_namespace")] #[test_case(Some("team"); "native_custom_namespace")] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -207,7 +207,6 @@ async fn encrypted_parent_reply_survives_incremental_guardian_reviews( Feature::Collab, Feature::MultiAgentV2, Feature::GuardianNativeMultiAgentHistory, - Feature::GuardianNativeActionFraming, ] { config .features @@ -416,7 +415,7 @@ async fn encrypted_parent_reply_survives_incremental_guardian_reviews( } else if historical_call.is_some() { "A historical MAv2 send_message call and an encrypted parent reply reach both Guardian reviews exactly once, in order. Calls retain their original IDs, namespace and encryption metadata, with a paired evidence-only output. The second review appends to the first request. Ciphertext and decisions are mocked; this verifies transport, not backend decryption or authorization outcomes." } else { - "An encrypted parent reply is delivered as a native agent message. Both Guardian reviews contain it exactly once, in order, as agent evidence. Ciphertext and decisions are mocked; this scenario verifies transport, not backend decryption or authorization outcomes." + "Both Guardian reviews contain the encrypted parent reply exactly once. With native MAv2 reviews enabled, the second review frames the pending send_message and its paired output. The ciphertext and verdicts are mocked." }; let mut snapshot = context_snapshot::format_request_history_snapshot( description, diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_agent_messages__encrypted_parent_reply_survives_incremental_guardian_reviews.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_agent_messages__encrypted_parent_reply_survives_incremental_guardian_reviews.snap index 2595ced33f..5200f0859b 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_agent_messages__encrypted_parent_reply_survives_incremental_guardian_reviews.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_agent_messages__encrypted_parent_reply_survives_incremental_guardian_reviews.snap @@ -2,7 +2,7 @@ source: core/tests/suite/scenarios_guardian_agent_messages_tests.rs expression: snapshot --- -Scenario: An encrypted parent reply is delivered as a native agent message. Both Guardian reviews contain it exactly once, in order, as agent evidence. Ciphertext and decisions are mocked; this scenario verifies transport, not backend decryption or authorization outcomes. +Scenario: Both Guardian reviews contain the encrypted parent reply exactly once. With native MAv2 reviews enabled, the second review frames the pending send_message and its paired output. The ciphertext and verdicts are mocked. ## Window 1 -- request 1 (turn) -- diff --git a/codex-rs/features/src/lib.rs b/codex-rs/features/src/lib.rs index 1cc5025b75..f04f55b5ea 100644 --- a/codex-rs/features/src/lib.rs +++ b/codex-rs/features/src/lib.rs @@ -475,7 +475,7 @@ pub enum Feature { GuardianRootHandoffContext, /// Review state-changing MAv2 calls and preserve native calls in Guardian history. GuardianNativeMultiAgentHistory, - /// Frame the current native agent call as a distinct Guardian approval request. + /// Removed compatibility flag. Native MAv2 reviews frame the pending call automatically. GuardianNativeActionFraming, /// Include the verified enclosing invocation in nested Guardian approvals. GuardianNestedApprovalContext, @@ -2342,7 +2342,7 @@ pub const FEATURES: &[FeatureSpec] = &[ FeatureSpec { id: Feature::GuardianNativeActionFraming, key: "guardian_native_action_framing", - stage: Stage::UnderDevelopment, + stage: Stage::Removed, default_enabled: false, }, FeatureSpec {