Invalidate Guardian review sessions after parent history resets (#45413)

## Why

A summary-free parent context reset could reuse a Guardian review session and carry forward rationale from before the reset.

## What changed

Track destructive history replacements with `reset_version` and include it in the Guardian session reuse key. Ordinary input and compaction preserve this version.

## Testing

Update the review-session reuse test to require a new Guardian thread after a summary-free reset, with no prior review context or previous rationale.

GitOrigin-RevId: bd05c149774839f68b75294751f7619ba7ce0bfe
This commit is contained in:
jif authored and copyberry committed 2026-09-14 12:11:26 +00:00
1 parent d761097734
commit 99cda7a9a5
4 files changed
+11 -4

No files matched your search

@@ -206,6 +206,7 @@ pub struct GuardianReviewSessionReuseKey {
// Only include settings that affect spawned-session behavior and parent
// history rewrites that invalidate existing reviewer context.
parent_history_version: u64,
parent_reset_version: u64,
root_authorization_version: Option<crate::codex_thread::GuardianAuthorizationVersion>,
node_repl_auto_review_required: bool,
node_repl_policy: String,
@@ -242,6 +243,7 @@ impl GuardianReviewSessionReuseKey {
) -> Self {
Self {
root_authorization_version: None,
parent_reset_version: 0,
parent_history_version: match ReviewContextPolicy::for_context(
context_mode,
&spawn_config.features,
@@ -40,6 +40,7 @@ impl PreparedSession {
.with_node_repl_policy_eligibility(context.model_info.computer_use_review_required())
.with_node_repl_policy(node_repl_policy);
key.root_authorization_version = root_authorization_version;
key.parent_reset_version = history.reset_version;
let host = parent
.services
.thread_extension_data
+4 -4
View File
@@ -2718,7 +2718,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
));
assert!(matches!(
fourth_metadata.guardian_session_kind,
Some(codex_analytics::GuardianReviewSessionKind::TrunkReused)
Some(codex_analytics::GuardianReviewSessionKind::TrunkNew)
));
ThreadId::from_string(
first_metadata
@@ -2744,7 +2744,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
assert_eq!(first_metadata.had_prior_review_context, Some(false));
assert_eq!(second_metadata.had_prior_review_context, Some(true));
assert_eq!(third_metadata.had_prior_review_context, Some(false));
assert_eq!(fourth_metadata.had_prior_review_context, Some(true));
assert_eq!(fourth_metadata.had_prior_review_context, Some(false));
assert_eq!(
first_metadata.guardian_thread_id,
second_metadata.guardian_thread_id
@@ -2753,7 +2753,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
second_metadata.guardian_thread_id,
third_metadata.guardian_thread_id
);
assert_eq!(
assert_ne!(
third_metadata.guardian_thread_id,
fourth_metadata.guardian_thread_id
);
@@ -2796,7 +2796,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
third_body["prompt_cache_key"],
fourth_body["prompt_cache_key"]
);
assert!(fourth_body.to_string().contains("third guardian rationale"));
assert!(!fourth_body.to_string().contains("third guardian rationale"));
assert!(
second_body.to_string().contains(concat!(
"Use prior reviews as context, not binding precedent. ",