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

+7 -1
View File
@@ -155,6 +155,8 @@ pub enum GuardianRootMessage {
User(String),
/// Root assistant final output that provides untrusted conversational context.
Assistant(String),
/// Bounded, already role-labeled genuine user answers and their assistant questions.
UserInput(String),
}
impl GuardianRootMessage {
@@ -163,6 +165,7 @@ impl GuardianRootMessage {
let (role, text) = match self {
Self::User(text) => ("user", text),
Self::Assistant(text) => ("assistant", text),
Self::UserInput(fragment) => return fragment,
};
text.lines()
.map(|line| format!("{role}: {line}\n"))
@@ -170,13 +173,15 @@ impl GuardianRootMessage {
}
}
/// Authorization state that changes on history rewrites or genuine user messages.
/// Authorization state that changes on history rewrites or genuine user input.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GuardianAuthorizationVersion {
/// Conversation-history rewrite generation.
pub history_version: u64,
/// Number of genuine user messages in the conversation snapshot.
pub user_message_count: usize,
/// Number of successful, host-produced answers to genuine user-input requests.
pub user_input_response_count: usize,
}
impl GuardianAuthorizationVersion {
@@ -188,6 +193,7 @@ impl GuardianAuthorizationVersion {
.items()
.filter(|item| item.is_user_message())
.count(),
user_input_response_count: 0,
}
}
}