From 6d40c0ac9b99f4ccb8d432f354c042cd7649e00d Mon Sep 17 00:00:00 2001 From: RJ Date: Tue, 17 Nov 2026 18:40:03 +0000 Subject: [PATCH] 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 --- .../suite/guardian_authorization_refresh.rs | 21 ++++++++++++++++++- .../ext/guardian-reviewer/src/completion.rs | 13 +++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/codex-rs/core/tests/suite/guardian_authorization_refresh.rs b/codex-rs/core/tests/suite/guardian_authorization_refresh.rs index 20be2ba3dc..5091bb4709 100644 --- a/codex-rs/core/tests/suite/guardian_authorization_refresh.rs +++ b/codex-rs/core/tests/suite/guardian_authorization_refresh.rs @@ -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::(request)) + .collect::, _>>()?; + 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::(request).expect("valid Responses request")) .filter(|request| request["client_metadata"]["x-openai-subagent"] == "guardian") .count(); assert_eq!(guardian_requests, attempts); diff --git a/codex-rs/ext/guardian-reviewer/src/completion.rs b/codex-rs/ext/guardian-reviewer/src/completion.rs index 4a3554879b..4955d24a75 100644 --- a/codex-rs/ext/guardian-reviewer/src/completion.rs +++ b/codex-rs/ext/guardian-reviewer/src/completion.rs @@ -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),