mirror of
https://github.com/openai/codex.git
synced 2026-11-16 14:55:43 +00:00
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:
1 parent
d761097734
commit
99cda7a9a5
4 files changed
+11
-4
No files matched your search
@@ -82,6 +82,8 @@ pub(crate) struct ContextManager {
|
|||||||
retain_inherited_user_messages: bool,
|
retain_inherited_user_messages: bool,
|
||||||
/// Bumped whenever history is rewritten, such as compaction or rollback.
|
/// Bumped whenever history is rewritten, such as compaction or rollback.
|
||||||
history_version: u64,
|
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.
|
/// Monotonic user-input/reset revision, independent of compaction's history generation.
|
||||||
user_message_revision: u64,
|
user_message_revision: u64,
|
||||||
token_info: Option<TokenUsageInfo>,
|
token_info: Option<TokenUsageInfo>,
|
||||||
@@ -180,6 +182,7 @@ impl ContextManager {
|
|||||||
guardian_context_mode: GuardianContextMode::Legacy,
|
guardian_context_mode: GuardianContextMode::Legacy,
|
||||||
retain_inherited_user_messages: false,
|
retain_inherited_user_messages: false,
|
||||||
history_version: 0,
|
history_version: 0,
|
||||||
|
reset_version: 0,
|
||||||
user_message_revision: 0,
|
user_message_revision: 0,
|
||||||
token_info: TokenUsageInfo::new_or_append(
|
token_info: TokenUsageInfo::new_or_append(
|
||||||
&None, &None, /*model_context_window*/ None,
|
&None, &None, /*model_context_window*/ None,
|
||||||
@@ -497,6 +500,7 @@ impl ContextManager {
|
|||||||
}
|
}
|
||||||
self.items = Arc::new(items);
|
self.items = Arc::new(items);
|
||||||
self.history_version = self.history_version.saturating_add(1);
|
self.history_version = self.history_version.saturating_add(1);
|
||||||
|
self.reset_version = self.history_version;
|
||||||
self.world_state_baseline = None;
|
self.world_state_baseline = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ pub struct GuardianReviewSessionReuseKey {
|
|||||||
// Only include settings that affect spawned-session behavior and parent
|
// Only include settings that affect spawned-session behavior and parent
|
||||||
// history rewrites that invalidate existing reviewer context.
|
// history rewrites that invalidate existing reviewer context.
|
||||||
parent_history_version: u64,
|
parent_history_version: u64,
|
||||||
|
parent_reset_version: u64,
|
||||||
root_authorization_version: Option<crate::codex_thread::GuardianAuthorizationVersion>,
|
root_authorization_version: Option<crate::codex_thread::GuardianAuthorizationVersion>,
|
||||||
node_repl_auto_review_required: bool,
|
node_repl_auto_review_required: bool,
|
||||||
node_repl_policy: String,
|
node_repl_policy: String,
|
||||||
@@ -242,6 +243,7 @@ impl GuardianReviewSessionReuseKey {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
root_authorization_version: None,
|
root_authorization_version: None,
|
||||||
|
parent_reset_version: 0,
|
||||||
parent_history_version: match ReviewContextPolicy::for_context(
|
parent_history_version: match ReviewContextPolicy::for_context(
|
||||||
context_mode,
|
context_mode,
|
||||||
&spawn_config.features,
|
&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_eligibility(context.model_info.computer_use_review_required())
|
||||||
.with_node_repl_policy(node_repl_policy);
|
.with_node_repl_policy(node_repl_policy);
|
||||||
key.root_authorization_version = root_authorization_version;
|
key.root_authorization_version = root_authorization_version;
|
||||||
|
key.parent_reset_version = history.reset_version;
|
||||||
let host = parent
|
let host = parent
|
||||||
.services
|
.services
|
||||||
.thread_extension_data
|
.thread_extension_data
|
||||||
|
|||||||
@@ -2718,7 +2718,7 @@ async fn guardian_reuses_prompt_cache_key_and_appends_prior_reviews() -> anyhow:
|
|||||||
));
|
));
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
fourth_metadata.guardian_session_kind,
|
fourth_metadata.guardian_session_kind,
|
||||||
Some(codex_analytics::GuardianReviewSessionKind::TrunkReused)
|
Some(codex_analytics::GuardianReviewSessionKind::TrunkNew)
|
||||||
));
|
));
|
||||||
ThreadId::from_string(
|
ThreadId::from_string(
|
||||||
first_metadata
|
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!(first_metadata.had_prior_review_context, Some(false));
|
||||||
assert_eq!(second_metadata.had_prior_review_context, Some(true));
|
assert_eq!(second_metadata.had_prior_review_context, Some(true));
|
||||||
assert_eq!(third_metadata.had_prior_review_context, Some(false));
|
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!(
|
assert_eq!(
|
||||||
first_metadata.guardian_thread_id,
|
first_metadata.guardian_thread_id,
|
||||||
second_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,
|
second_metadata.guardian_thread_id,
|
||||||
third_metadata.guardian_thread_id
|
third_metadata.guardian_thread_id
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_ne!(
|
||||||
third_metadata.guardian_thread_id,
|
third_metadata.guardian_thread_id,
|
||||||
fourth_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"],
|
third_body["prompt_cache_key"],
|
||||||
fourth_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!(
|
assert!(
|
||||||
second_body.to_string().contains(concat!(
|
second_body.to_string().contains(concat!(
|
||||||
"Use prior reviews as context, not binding precedent. ",
|
"Use prior reviews as context, not binding precedent. ",
|
||||||
|
|||||||
Reference in new issue
Block a user