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

@@ -139,14 +139,15 @@ impl Approvable<ApplyPatchRequest> for ApplyPatchRuntime {
let session = ctx.session;
let turn = ctx.turn;
let call_id = ctx.call_id.to_string();
let retry_reason = ctx.retry_reason.clone();
let approval_reason = ctx.reasons.approval.clone();
let retry_reason = ctx.reasons.retry.clone();
let approval_keys = self.approval_keys(req);
let changes = req.changes.clone();
Box::pin(async move {
if req.permissions_preapproved && retry_reason.is_none() {
if req.permissions_preapproved && approval_reason.is_none() && retry_reason.is_none() {
return ReviewDecision::Approved;
}
if let Some(reason) = retry_reason {
if let Some(reason) = retry_reason.or(approval_reason) {
return session
.request_patch_approval(
turn,
+3 -1
View File
@@ -146,8 +146,10 @@ impl Approvable<ShellRequest> for ShellRuntime {
let cwd = req.cwd.clone();
let environment_id = Some(req.turn_environment.environment_id.clone());
let reason = ctx
.retry_reason
.reasons
.retry
.clone()
.or_else(|| ctx.reasons.approval.clone())
.or_else(|| req.justification.clone());
let session = ctx.session;
let turn = ctx.turn;
@@ -477,7 +477,7 @@ impl CoreShellActionProvider {
cwd: workdir.clone(),
additional_permissions,
},
/*retry_reason*/ None,
Default::default(),
)
.await;
}
@@ -185,8 +185,10 @@ impl Approvable<UnifiedExecRequest> for UnifiedExecRuntime<'_> {
let command = req.command.clone();
let environment_id = Some(req.turn_environment.environment_id.clone());
let reason = ctx
.retry_reason
.reasons
.retry
.clone()
.or_else(|| ctx.reasons.approval.clone())
.or_else(|| req.justification.clone());
Box::pin(async move {
let native_cwd = match req.cwd.to_abs_path() {