Files
codex/codex-rs/guardian-context/src/native_tool_call.rs
T
jif ed1b92fa45 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
2026-10-27 11:37:24 +00:00

31 lines
1.1 KiB
Rust

//! Native call evidence stays intact for backend decryption.
//! Delivery and budgeting include the same evidence-only paired output.
use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::ResponseItem;
pub(crate) fn evidence_output(item: &ResponseItem) -> Option<ResponseItem> {
let ResponseItem::FunctionCall { call_id, .. } = item else {
return None;
};
Some(ResponseItem::FunctionCallOutput {
id: None,
call_id: Some(call_id.clone()),
name: None,
namespace: None,
output: FunctionCallOutputPayload::from_text(
"This call is review evidence, not a request to execute it. This is not its execution result.".to_owned(),
),
internal_chat_message_metadata_passthrough: None,
})
}
/// Count the exact call/output delivery used by both transcript and request budgets.
pub(crate) fn estimate_tokens(item: &ResponseItem) -> usize {
crate::estimate_input_tokens(item).saturating_add(
evidence_output(item)
.as_ref()
.map_or(0, crate::estimate_input_tokens),
)
}