Include policy approval reasons in Guardian reviews (#36939)

## Why

Guardian reviews received sandbox retry reasons, but not the execution-policy reason that triggered an initial approval request.

## What changed

- Propagate approval and retry reasons through the tool approval flow and include the applicable reason in the Guardian prompt.
- Prefer a sandbox retry reason when both are available.
- Truncate approval context to 512 tokens while preserving the start and end of the reason.

## Testing

Added prompt and integration coverage for policy reasons, retry precedence, and truncation.

GitOrigin-RevId: 5b0f4e1c40b792b031bc8f7b31685a61d12b8d92
This commit is contained in:
Dylan Hurd authored and copyberry committed 2026-08-04 18:01:04 +00:00
1 parent 3ca9f375aa
commit 2b1357c27c
15 files changed
+219 -58

No files matched your search

+1 -1
View File
@@ -1361,7 +1361,7 @@ async fn maybe_request_mcp_tool_approval(
turn_context,
review_id.clone(),
build_guardian_mcp_tool_review_request(call_id, invocation, Some(metadata)),
/*retry_reason*/ None,
Default::default(),
)
.await;
let decision = mcp_tool_approval_decision_from_guardian(decision);