Capture Guardian review checkpoints from live context (#46512)

## Why

Committing a Guardian review snapshot currently flushes and reloads the transcript from storage, even though the completed model context is already available in memory.

## What changed

- Build forkable checkpoints directly from live session state, preserving model history, retained Guardian context, world state, turn context, and token usage.
- Preserve compaction window metadata and MCP resource origins in the checkpoint.
- Recognize prior user turns inside compacted replacement history.

## Testing

Add round-trip checkpoint tests for legacy and thread-owned Guardian context without storage, including preservation after live history is mutated. Extend the review compaction test to assert that checkpoints do not load history from storage.

GitOrigin-RevId: cb2638ca93bba6ab4472de50c7e2913e1a2f25a8
This commit is contained in:
jif
2026-09-18 23:37:35 +00:00
committed by copyberry
parent 05a93a8a1d
commit 0f7c8608bd
8 changed files with 198 additions and 36 deletions
@@ -381,6 +381,12 @@ impl ContextManager {
self.world_state_baseline = Some(snapshot);
}
pub(crate) fn world_state_checkpoint(&self) -> Option<WorldStateItem> {
self.world_state_baseline
.clone()
.map(|snapshot| WorldStateItem::full(snapshot.into_object()))
}
pub(crate) fn set_token_usage_full(&mut self, context_window: i64) {
match &mut self.token_info {
Some(info) => info.fill_to_context_window(context_window),