Preserve Guardian authorization evidence across checkpoint migration (#45782)

## Why

Older compaction checkpoints can lack a producer model hash. Enabling thread-owned Guardian context must accommodate those checkpoints without losing user instructions or verified answers.

## What changed

- Select review policy from each history snapshot independently of the session's evidence capture policy.
- Keep legacy review for checkpoints with missing or empty producer hashes when the transcript preserves the evidence. Preserve strict compatibility checks when review depends on retained-only evidence.
- Continue capturing retained instructions and answers during migration, while supplying legacy reviews with runtime answers and subagent reviews with root authorization evidence.
- Record producer model hashes on new compactions regardless of context mode.

## Testing

Add coverage for checkpoint migration across compaction and resume in both history storage modes, snapshot policy stability, retained-evidence preservation, and authorization revalidation for owning sessions and subagents.

GitOrigin-RevId: ec72b4a51d40729173e24ac1b53b7d516ddaa825
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-09-15 20:08:36 +00:00
1 parent 1427825c40
commit 0c3a14bbc2
20 files changed
+564 -85

No files matched your search

@@ -97,7 +97,8 @@ enum ReviewCheckpoint {
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "incompatible checkpoint")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), None, 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "unknown Luna compatibility")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some(""), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "empty Luna compatibility")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, None, Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "unknown producer remains unknown after model switch")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, None, Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "unknown producer preserves retained evidence")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some(""), Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "empty producer preserves retained evidence")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("matching"), 140, EvidenceSize::Normal, ReviewCheckpoint::Valid; "source call evicted")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("matching"), 0, EvidenceSize::OversizedAnswer, ReviewCheckpoint::Valid; "incomplete answers reject fresh low score")]
#[test_case(ContextPath::Legacy, CheckpointReuse::Enabled, Some("matching"), Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "legacy answers remain runtime only")]
@@ -398,7 +399,7 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
.await?;
classifier.allow_luna.notify_one();
}
if reject_sync_checkpoint && (1..=2).contains(&index) {
if reject_sync_checkpoint && index > 0 {
let notification = timeout(
TIMEOUT,
app_server.read_stream_until_matching_notification(
@@ -439,7 +440,7 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
let completed: TurnCompletedNotification =
timeout(TIMEOUT, app_server.read_notification("turn/completed")).await??;
assert_eq!(completed.turn.status, TurnStatus::Completed);
if reject_sync_checkpoint && (1..=2).contains(&index) {
if reject_sync_checkpoint && index > 0 {
// The first review established a cached session before compaction. Neither
// that session nor a new one may review unusable evidence, including after resume.
let reviews = review_requests.lock().expect("request log lock");
@@ -778,10 +779,8 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
.metadata
.as_ref()
.and_then(|metadata| metadata.compaction_model_hash.as_deref()),
matches!(context_path, ContextPath::ThreadOwned)
.then_some(parent_hash)
.flatten(),
"only the enabled path records checkpoint producer provenance",
parent_hash,
"every compaction records its producer provenance",
);
}
}