Preserve Guardian review evidence across compaction (#41846)

## Why

Context compaction can replace original conversation items that Guardian still needs to review approval-sensitive actions.

## What changed

- Retain a bounded, chronological review history independently of the model's compacted history.
- Keep separate limits for user messages and other transcript items so tool traffic cannot evict user instructions.
- Use the retained evidence for synchronous and asynchronous Guardian transcripts, while resetting it after rollback or history reconstruction.

## Testing

- Cover retention through compaction and eviction, reset behavior after rollback, independent size limits, and asynchronous transcript construction.

GitOrigin-RevId: c5851e992820504fc18de8cfec7f6f9f1b69f316
This commit is contained in:
jif authored and copyberry committed 2026-08-31 13:57:59 +00:00
1 parent e45226e771
commit 1c1e17782a
15 files changed
+468 -31

No files matched your search

+4 -6
View File
@@ -140,7 +140,7 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
} else {
GUARDIAN_MAX_TOOL_ENTRY_TOKENS
};
let history = session.clone_history().await;
let history = session.conversation_history_snapshot().await;
let root_authorization = session
.services
.agent_control
@@ -151,13 +151,11 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
.services
.thread_extension_data
.get::<GuardianReviewEvidence>()
.map(|evidence| {
evidence.user_input_fragments(history.conversation_history_snapshot().as_ref())
})
.map(|evidence| evidence.user_input_fragments(history.as_ref()))
.unwrap_or_default();
let transcript_entries = collect_guardian_transcript_entries(history.raw_items());
let transcript_entries = collect_guardian_transcript_entries(history.review_items());
let transcript_cursor = GuardianTranscriptCursor {
parent_history_version: history.history_version(),
parent_history_version: history.review_history_version(),
transcript_entry_count: transcript_entries.len(),
};
let planned_action_json = format_guardian_action_pretty(&request)?;
+2 -2
View File
@@ -482,10 +482,10 @@ impl GuardianReviewSessionManager {
pub(crate) async fn shutdown(&self) {
self.cancellation_token.cancel();
self.invalidate_for_node_repl_evidence().await;
self.invalidate().await;
}
pub(crate) async fn invalidate_for_node_repl_evidence(&self) {
pub(crate) async fn invalidate(&self) {
let (review_session, ephemeral_reviews) = {
let mut state = self.state.lock().await;
(