Lightweight coding agent that runs in your terminal
Rust
Invalidate Guardian review sessions after parent history resets (#45413)
jif99cda7a9a599
diff --git a/codex-rs/core/src/context_manager/history.rs b/codex-rs/core/src/context_manager/history.rsindex fbd5a428b4..3695fc7b77 100644--- a/codex-rs/core/src/context_manager/history.rs+++ b/codex-rs/core/src/context_manager/history.rs@@ -82,6 +82,8 @@ pub(crate) struct ContextManager {retain_inherited_user_messages: bool,/// Bumped whenever history is rewritten, such as compaction or rollback.history_version: u64,+ /// Last destructive history replacement; ordinary input and compaction preserve it.+ pub(crate) reset_version: u64,/// Monotonic user-input/reset revision, independent of compaction's history generation.user_message_revision: u64,token_info: Option<TokenUsageInfo>,@@ -180,6 +182,7 @@ impl ContextManager {guardian_context_mode: GuardianContextMode::Legacy,retain_inherited_user_messages: false,history_version: 0,+ reset_version: 0,user_message_revision: 0,token_info: TokenUsageInfo::new_or_append(&None, &None, /*model_context_window*/ None,@@ -497,6 +500,7 @@ impl ContextManager {}self.items = Arc::new(items);self.history_version = self.history_version.saturating_add(1);+ self.reset_version = self.history_version;self.world_state_baseline = None;}diff --git a/codex-rs/core/src/guardian/review_session.rs b/codex-rs/core/src/guardian/review_session.rsindex f7d38d20c7..f0c5acd690 100644--- a/codex-rs/core/src/guardian/review_session.rs+++ b/codex-rs/core/src/guardian/review_session.rs@@ -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,diff --git a/codex-rs/core/src/guardian/review_session_factory.rs b/codex-rs/core/src/guardian/review_session_factory.rsindex 894ee52c14..0100cd1568 100644--- a/codex-rs/core/src/guardian/review_session_factory.rs+++ b/codex-rs/core/src/guardian/review_session_factory.rs@@ -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_datadiff --git a/codex-rs/core/src/guardian/tests.rs b/codex-rs/core/src/guardian/tests.rsindex 02c500bd31..358f1dafe7 100644--- a/codex-rs/core/src/guardian/tests.rs+++ b/codex-rs/core/src/guardian/tests.rs@@ -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. ",