Preserve Guardian authorization across history compaction (#41660)

## Why

Compaction and host-injected context can rewrite the model-visible conversation
without changing what the user authorized. Treating those updates as authorization
changes prevents Guardian from reusing an otherwise valid review.

## What changed

- Track a host-owned user-message revision separately from the conversation history
  generation.
- Advance the revision for genuine user messages and history resets, while preserving
  it across compaction and internal context injection.
- Use message content-kind metadata to distinguish host context from user input,
  conservatively treating unknown or incomplete metadata as user authorization.

## Testing

Added coverage that cached Guardian authorization survives compaction and internal
context, but is invalidated by user input and rollback.

GitOrigin-RevId: c7960fa182d1686042c23764d2abc58acbc4b882
This commit is contained in:
jif authored and copyberry committed 2026-08-30 11:56:24 +00:00
1 parent 28327355b8
commit 0a12b855a0
14 files changed
+281 -22

No files matched your search

@@ -8,6 +8,10 @@ pub trait ConversationHistorySnapshot: Send + Sync {
/// Returns the generation of the history captured by this snapshot.
fn history_version(&self) -> u64;
/// Host-owned revision captured with this snapshot. Advances on user messages and
/// history resets, but stays unchanged for compaction and internal context.
fn user_message_revision(&self) -> u64;
/// Returns the snapshot's response items in conversation order.
fn items(&self) -> Box<dyn Iterator<Item = &ResponseItem> + Send + '_>;
}