Treat user input answers as Guardian authorization changes (#40623)

## Why

Answers collected by `request_user_input` can change what the user authorizes, but post-tool hooks may replace or reject the tool output that Guardian normally sees.

## What changed

- Record bounded, host-observed answers before post-tool hooks run and provide them as trusted evidence to synchronous and asynchronous Guardian reviews.
- Include root-thread answers in worker review context.
- Count successful answers as authorization changes so earlier review evidence becomes stale, while ignoring empty or unrelated answers.

## Testing

Add coverage for allowed and denied stale reviews, empty and oversized answers, hook-modified output, and root-to-worker propagation.

GitOrigin-RevId: 970c52e40338ecd057c7cd2a69d04b06e97cd068
This commit is contained in:
jif authored and copyberry committed 2026-08-25 15:03:46 +00:00
1 parent c395364915
commit 4b81410a80
9 files changed
+563 -72

No files matched your search

+16
View File
@@ -10,6 +10,7 @@ use serde::Deserialize;
use serde_json::Value;
use crate::compact::content_items_to_text;
use crate::context::GuardianReviewEvidence;
use crate::context::NodeReplReviewEvidence;
use crate::context::NodeReplReviewEvidenceMode;
use crate::context::node_repl_review_evidence_mode;
@@ -145,6 +146,14 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
.root_user_authorization(session.thread_id)
.await
.map(|snapshot| snapshot.messages);
let trusted_user_inputs = session
.services
.thread_extension_data
.get::<GuardianReviewEvidence>()
.map(|evidence| {
evidence.user_input_fragments(history.conversation_history_snapshot().as_ref())
})
.unwrap_or_default();
let transcript_entries = collect_guardian_transcript_entries(history.raw_items());
let transcript_cursor = GuardianTranscriptCursor {
parent_history_version: history.history_version(),
@@ -230,6 +239,13 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
}
push_text(">>> ROOT CONVERSATION END\n".to_string());
}
if !trusted_user_inputs.is_empty() {
push_text(">>> TRUSTED USER ANSWERS START\n".to_string());
for answer in trusted_user_inputs {
push_text(answer);
}
push_text(">>> TRUSTED USER ANSWERS END\n".to_string());
}
push_text(headings.transcript_start.to_string());
for (index, entry) in transcript_entries.into_iter().enumerate() {
let prefix = if index == 0 { "" } else { "\n" };
+1 -2
View File
@@ -31,7 +31,6 @@ use tokio::time::Instant;
use tokio::time::sleep_until;
use tokio_util::sync::CancellationToken;
use crate::codex_thread::GuardianAuthorizationVersion;
use crate::context::GuardianReviewEvidence;
use crate::session::session::Session;
use crate::session::turn_context::TurnContext;
@@ -462,7 +461,7 @@ async fn run_guardian_review(
// Root rewrites and new user messages during this review make its evidence
// stale even if it later completes against a newer prompt snapshot.
let history = session.conversation_history_snapshot().await;
let authorization_version = GuardianAuthorizationVersion::from_history(history.as_ref());
let authorization_version = evidence.authorization_version(history.as_ref());
let root_authorization_version = session
.services
.agent_control