Add opt-in synchronous Guardian review for native tool calls (#57433)

## What changed

- Add `CoreToolRuntime::requires_guardian_review` to review opted-in function calls before dispatch and stop execution when review rejects the call.
- Deliver proposed calls as native review evidence, preserving encrypted argument metadata. When hooks rewrite arguments, review the updated arguments and discard the original encrypted replay content.
- Deduplicate native call evidence against reviewer history and include paired evidence outputs in input budgets.
- Keep review accounting and metrics for native calls without emitting action-specific client assessment events, and omit approval payloads from debug output.

## Testing

Extend regression coverage for rewritten native calls across review retries, denied calls that never execute their handlers, oversized native evidence, and review metrics without client events.

GitOrigin-RevId: c3b22c0220344581c2b38f233001abaed49cba34
This commit is contained in:
jif
2026-10-27 11:37:24 +00:00
committed by copyberry
parent b6ad8ea1fc
commit ed1b92fa45
34 changed files with 669 additions and 184 deletions
+37 -1
View File
@@ -24,6 +24,8 @@ use codex_protocol::protocol::InterAgentCommunication;
use crate::ContextSection;
use crate::ConversationTranscriptEntry;
use crate::ConversationTranscriptEntryKind;
use crate::PlannedAction;
use crate::PlannedActionKind;
use crate::SectionContributor;
use crate::SectionError;
use crate::SectionHistory;
@@ -117,8 +119,23 @@ impl SectionContributor for ConversationTranscriptSection {
}
fn contribute(&self, input: &SectionInput<'_>) -> Result<Option<ContextSection>, SectionError> {
let proposed_call_id = if let Some(PlannedAction {
kind: PlannedActionKind::ToolCall(call),
..
}) = input.planned_action
&& let ResponseItem::FunctionCall { call_id, .. } = call.as_ref()
{
Some(call_id.as_str())
} else {
None
};
Ok(Some(ContextSection::ConversationTranscript {
items: collect_transcript_for_target(input.history, input.transcript, input.target),
items: collect_transcript_for_review(
input.history,
input.transcript,
input.target,
proposed_call_id,
),
}))
}
}
@@ -138,6 +155,15 @@ fn collect_transcript_for_target(
history: &dyn SectionHistory,
config: &ConversationTranscriptConfig,
target: crate::ContextTarget,
) -> Vec<ConversationTranscriptEntry> {
collect_transcript_for_review(history, config, target, /*proposed_call_id*/ None)
}
fn collect_transcript_for_review(
history: &dyn SectionHistory,
config: &ConversationTranscriptConfig,
target: crate::ContextTarget,
proposed_call_id: Option<&str>,
) -> Vec<ConversationTranscriptEntry> {
let mut entries = Vec::new();
let mut tool_names_by_call_id = HashMap::new();
@@ -242,6 +268,16 @@ fn collect_transcript_for_target(
format!("Agent message from {author}:\n{text}"),
)
}
// The proposed call is delivered separately; preserve this cursor position.
ResponseItem::FunctionCall { name, call_id, .. }
if config.options.include_tool_calls
&& proposed_call_id == Some(call_id.as_str()) =>
{
(
ConversationTranscriptEntryKind::ToolCall(format!("tool {name} call")),
TRANSCRIPT_OMISSION_NOTICE.to_owned(),
)
}
ResponseItem::FunctionCall {
name,
namespace,