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
This commit is contained in:
jif
2026-11-30 12:52:50 +00:00
committed by copyberry
parent ae78265f08
commit acd1a3794b
6 changed files with 25 additions and 36 deletions
@@ -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(
+6 -15
View File
@@ -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,
@@ -91,26 +91,25 @@ pub(crate) async fn handoff_scenario(native_history: bool) -> Result<Vec<Respons
.await?;
let root = test.session_configured.thread_id;
let mut created = test.thread_manager.subscribe_thread_created();
// Allow the setup handoffs. Match the trailing native evidence output so
// Match the handoff output just before the closing approval marker so
// historical calls cannot swallow the final command's separate denial.
wiremock::Mock::given(wiremock::matchers::method("POST"))
.and(wiremock::matchers::path("/v1/responses"))
.and(|request: &wiremock::Request| {
request_body(request).is_some_and(|body| {
let Some([.., output, closing]) = body["input"].as_array().map(Vec::as_slice) else {
return false;
};
body["client_metadata"]["x-openai-subagent"] == "guardian"
&& body["input"]
.as_array()
.and_then(|items| items.last())
.is_some_and(|item| {
item["type"] == "function_call_output"
&& matches!(
item["call_id"].as_str(),
Some(
"spawn-alpha" | "spawn-leaf" | "spawn-beta" | "send-alpha"
| "followup-alpha"
)
)
})
&& closing["role"] == "user"
&& closing["content"][0]["text"]
.as_str()
.is_some_and(|text| text.starts_with(">>> 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![
@@ -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,
@@ -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) --
+2 -2
View File
@@ -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 {