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

+7 -3
View File
@@ -190,7 +190,6 @@ impl ApprovalResolution {
pub(super) async fn resolve_tool_approval<Rq, Out, T>(
tool: &mut T,
req: &Rq,
permission_request_run_id: &str,
ctx: ApprovalCtx<'_>,
reviewer: ApprovalReviewer,
) -> Result<ReviewDecision, ToolError>
@@ -198,10 +197,15 @@ where
T: ToolRuntime<Rq, Out>,
{
if let Some(permission_request) = tool.permission_request_payload(req) {
let permission_request_run_id = ctx
.reasons
.retry
.as_ref()
.map(|_| format!("{}:retry", ctx.call_id));
match run_permission_request_hooks(
ctx.session,
ctx.turn,
permission_request_run_id,
permission_request_run_id.as_deref().unwrap_or(ctx.call_id),
permission_request,
)
.await
@@ -251,7 +255,7 @@ where
ctx.turn,
review_id,
action,
ctx.retry_reason.clone(),
ctx.reasons.clone(),
)
.await
}