Clarify recovery guidance for stale Guardian authorization (#62099)

## What changed

Give `StaleAuthorization` failures specific guidance explaining that the action did not run and the failure is not a policy denial. Instruct the agent to retry once through Guardian if current instructions authorize the action, resolve unclear authorization before proceeding, and avoid bypassing approval or repeatedly retrying a failed review.

## Testing

Extend the authorization refresh tests to verify the blocked tool output includes this guidance when repeated authorization changes exhaust the review budget, for both approval and denial responses.

GitOrigin-RevId: f6fcbe46fdb5131f70ee905220a58c7331b543fd
This commit is contained in:
RJ
2026-11-17 19:09:21 +00:00
committed by copyberry
parent 0122b120cd
commit 6d40c0ac9b
2 changed files with 32 additions and 2 deletions
@@ -308,9 +308,28 @@ async fn guardian_refreshes_subagent_authorization(change: Change) -> Result<()>
);
}
let requests = streaming.requests().await;
let requests = requests
.iter()
.map(|request| serde_json::from_slice::<Value>(request))
.collect::<std::result::Result<Vec<_>, _>>()?;
if matches!(change, Change::Repeated | Change::RepeatedDenial) {
let tool_output = requests
.iter()
.filter_map(|request| request["input"].as_array())
.flatten()
.find(|item| {
item["type"] == "function_call_output" && item["call_id"] == "write-marker"
})
.context("worker did not receive the blocked tool output")?;
let output = tool_output.to_string();
assert!(output.contains("authorization changed before approval could be applied"));
assert!(output.contains("retry once through Guardian"));
assert!(output.contains("this is not a policy denial"));
assert!(output.contains("Do not bypass approval or repeatedly retry a failed review"));
assert!(output.contains("The action did not run"));
}
let guardian_requests = requests
.iter()
.map(|request| serde_json::from_slice::<Value>(request).expect("valid Responses request"))
.filter(|request| request["client_metadata"]["x-openai-subagent"] == "guardian")
.count();
assert_eq!(guardian_requests, attempts);
@@ -22,6 +22,12 @@ const REVIEW_FAILURE_INSTRUCTIONS: &str = concat!(
"This is a review failure, not a determination that the action is unsafe. ",
"Do not bypass the approval check; resolve the error or ask the user for guidance.",
);
const STALE_AUTHORIZATION_INSTRUCTIONS: &str = concat!(
"The action did not run. Guardian could not complete its review because authorization ",
"changed; this is not a policy denial. If current instructions authorize the action, ",
"retry once through Guardian. If authorization is unclear, resolve that uncertainty before ",
"proceeding. Do not bypass approval or repeatedly retry a failed review.",
);
const INPUT_BUDGET_MESSAGE: &str =
"the complete action and minimum review context exceed the reviewer input budget";
@@ -153,6 +159,11 @@ pub fn complete_review(
analytics.decision = GuardianReviewDecision::Denied;
analytics.terminal_status = GuardianReviewTerminalStatus::FailedClosed;
let rationale = format!("Automatic approval review failed: {message}");
let instructions = if matches!(error, GuardianReviewError::StaleAuthorization) {
STALE_AUTHORIZATION_INSTRUCTIONS
} else {
REVIEW_FAILURE_INSTRUCTIONS
};
// Keep the existing blocked status for client compatibility.
if let Some(event) = event.as_mut() {
event.status = GuardianAssessmentStatus::Denied;
@@ -160,7 +171,7 @@ pub fn complete_review(
}
return ReviewCompletion {
decision: Some(ReviewDecision::denied(format!(
"{rationale}\n{REVIEW_FAILURE_INSTRUCTIONS}"
"{rationale}\n{instructions}"
))),
event,
warning: Some(rationale),