Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Allow Guardian sync review across compaction hash differences (#47272)

felixxia-oai99784bd09b23
diff --git a/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs b/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
index 7128381526..560d9628db 100644
--- a/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
+++ b/codex-rs/app-server/tests/suite/v2/guardian_v2_history_tests.rs
@@ -80,16 +80,16 @@ enum CheckpointReuse {
enum ReviewCheckpoint {
Valid,
EmptyContent,
- IncompatibleReviewer,
+ DifferentReviewerHash,
UnknownReviewer,
EmptyReviewerHash,
}
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::EmptyContent; "empty checkpoint fails closed")]
-#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::IncompatibleReviewer; "incompatible sync reviewer fails closed")]
-#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::UnknownReviewer; "unknown sync compatibility fails closed")]
-#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::EmptyReviewerHash; "empty sync compatibility fails closed")]
-#[test_case(ContextPath::Legacy, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::IncompatibleReviewer; "legacy sync compatibility is unchanged")]
+#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::DifferentReviewerHash; "different sync hash preserves retained evidence")]
+#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::UnknownReviewer; "unknown sync hash preserves retained evidence")]
+#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::EmptyReviewerHash; "empty sync hash preserves retained evidence")]
+#[test_case(ContextPath::Legacy, CheckpointReuse::Enabled, Some("matching"), Some("different"), 0, EvidenceSize::Normal, ReviewCheckpoint::DifferentReviewerHash; "legacy sync compatibility is unchanged")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Disabled, Some("matching"), Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "disabled Luna reuse requires sync")]
#[test_case(ContextPath::Legacy, CheckpointReuse::Disabled, Some("matching"), Some("matching"), 0, EvidenceSize::Normal, ReviewCheckpoint::Valid; "legacy disabled Luna reuse still samples")]
#[test_case(ContextPath::ThreadOwned, CheckpointReuse::Enabled, Some("matching"), Some("matching"), 0, EvidenceSize::OversizedInstruction, ReviewCheckpoint::Valid; "instruction budget preserves fresh low score")]
@@ -127,14 +127,14 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
let requires_sync = matches!(context_path, ContextPath::ThreadOwned) && !compatible;
let oversized_instruction = matches!(evidence_size, EvidenceSize::OversizedInstruction);
let reviewer_hash = match review_checkpoint {
- ReviewCheckpoint::IncompatibleReviewer => Some("different-reviewer"),
+ ReviewCheckpoint::DifferentReviewerHash => Some("different-reviewer"),
ReviewCheckpoint::UnknownReviewer => None,
ReviewCheckpoint::EmptyReviewerHash => Some(""),
ReviewCheckpoint::Valid | ReviewCheckpoint::EmptyContent => Some("matching"),
};
+ // Sync review accepts any hash metadata; only the checkpoint payload must be usable.
let reject_sync_checkpoint = matches!(context_path, ContextPath::ThreadOwned)
- && (!matches!(review_checkpoint, ReviewCheckpoint::Valid)
- || parent_hash != Some("matching"));
+ && matches!(review_checkpoint, ReviewCheckpoint::EmptyContent);
let answer = match evidence_size {
EvidenceSize::Normal | EvidenceSize::OversizedInstruction => {
USER_INPUT_RESTRICTION.to_owned()
@@ -158,7 +158,7 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
match review_checkpoint {
ReviewCheckpoint::EmptyContent => checkpoint["encrypted_content"] = json!(""),
ReviewCheckpoint::Valid
- | ReviewCheckpoint::IncompatibleReviewer
+ | ReviewCheckpoint::DifferentReviewerHash
| ReviewCheckpoint::UnknownReviewer
| ReviewCheckpoint::EmptyReviewerHash => {}
}
@@ -415,24 +415,16 @@ async fn guardians_retain_evidence_after_compaction_and_resume(
.await??;
let assessment: ItemGuardianApprovalReviewCompletedNotification =
serde_json::from_value(notification.params.expect("review completion"))?;
- let reason = match review_checkpoint {
- ReviewCheckpoint::EmptyContent => {
- "parent compaction checkpoint is unusable for Guardian review"
- }
- ReviewCheckpoint::Valid
- | ReviewCheckpoint::IncompatibleReviewer
- | ReviewCheckpoint::UnknownReviewer
- | ReviewCheckpoint::EmptyReviewerHash => {
- "parent compaction checkpoint is incompatible with the Guardian review model or its compatibility is unknown"
- }
- };
assert_eq!(
assessment.review,
GuardianApprovalReview {
status: GuardianApprovalReviewStatus::Denied,
risk_level: None,
user_authorization: None,
- rationale: Some(format!("Automatic approval review failed: {reason}")),
+ rationale: Some(
+ "Automatic approval review failed: parent compaction checkpoint is unusable for Guardian review"
+ .to_owned(),
+ ),
}
);
}
diff --git a/codex-rs/core/src/guardian/review.rs b/codex-rs/core/src/guardian/review.rs
index 56ae527025..de441feee5 100644
--- a/codex-rs/core/src/guardian/review.rs
+++ b/codex-rs/core/src/guardian/review.rs
@@ -121,7 +121,6 @@ pub(crate) struct GuardianReviewOptions {
pub(super) struct GuardianReviewSessionConfig {
pub(super) spawn_config: crate::config::Config,
pub(super) node_repl_policy: GuardianNodeReplPolicy,
- pub(super) compaction_model_hash: Option<String>,
review_model: ReviewModel,
}
@@ -168,7 +167,6 @@ pub(super) async fn guardian_review_session_config(
}
Ok(GuardianReviewSessionConfig {
spawn_config,
- compaction_model_hash: guardian_model_info.comp_hash.clone(),
node_repl_policy: GuardianNodeReplPolicy::from_messages(model_messages),
review_model,
})
@@ -227,7 +225,6 @@ async fn run_guardian_review_session_before_deadline(
reasons,
schema,
review_model: session_config.review_model,
- compaction_model_hash: session_config.compaction_model_hash,
reasoning_summary: context.reasoning_summary,
personality: context.personality,
external_cancel,
diff --git a/codex-rs/core/src/guardian/review_session.rs b/codex-rs/core/src/guardian/review_session.rs
index b186804af7..4b14ab2360 100644
--- a/codex-rs/core/src/guardian/review_session.rs
+++ b/codex-rs/core/src/guardian/review_session.rs
@@ -113,7 +113,6 @@ pub(crate) struct GuardianReviewSessionParams {
pub(crate) reasons: ApprovalRequestReasons,
pub(crate) schema: Value,
pub(crate) review_model: ReviewModel,
- pub(crate) compaction_model_hash: Option<String>,
pub(crate) reasoning_summary: ReasoningSummaryConfig,
pub(crate) personality: Option<Personality>,
pub(crate) external_cancel: Option<CancellationToken>,
diff --git a/codex-rs/core/src/guardian/review_session_context.rs b/codex-rs/core/src/guardian/review_session_context.rs
index c8073e78aa..8e099d65e4 100644
--- a/codex-rs/core/src/guardian/review_session_context.rs
+++ b/codex-rs/core/src/guardian/review_session_context.rs
@@ -48,9 +48,7 @@ impl ReviewContextPolicy {
pub(super) fn parent_compaction(
self,
history: &ContextManager,
- reviewer_compaction_hash: Option<&str>,
) -> anyhow::Result<Option<ResponseItem>> {
- let strict = self == Self::ThreadOwned;
if self == Self::Legacy {
return Ok(None);
}
@@ -60,21 +58,16 @@ impl ReviewContextPolicy {
return Ok(None);
};
let valid = checkpoint.is_usable();
- if !valid && !strict {
+ if !valid && self == Self::LegacyWithCheckpointReuse {
+ // Legacy review can use its retained transcript without this checkpoint.
return Ok(None);
}
anyhow::ensure!(
valid,
"parent compaction checkpoint is unusable for Guardian review"
);
- if strict {
- // A resumed parent may now use a different model. Compare the actual
- // checkpoint producer with the selected reviewer, not the live parent model.
- anyhow::ensure!(
- checkpoint.is_compatible_with(reviewer_compaction_hash),
- "parent compaction checkpoint is incompatible with the Guardian review model or its compatibility is unknown"
- );
- }
+ // The synchronous reviewer can consume checkpoints across advertised comp_hash
+ // values. Let the backend validate the payload; review errors still fail closed.
Ok(Some(checkpoint.item.clone()))
}
}
diff --git a/codex-rs/core/src/guardian/review_session_setup.rs b/codex-rs/core/src/guardian/review_session_setup.rs
index 5108bcd487..acdb5df36d 100644
--- a/codex-rs/core/src/guardian/review_session_setup.rs
+++ b/codex-rs/core/src/guardian/review_session_setup.rs
@@ -22,7 +22,6 @@ impl PreparedGuardianContext {
config: Config,
history: &ContextManager,
node_repl_policy: &GuardianNodeReplPolicy,
- compaction_model_hash: Option<&str>,
) -> anyhow::Result<Self> {
let (reset_version, history_reset) = parent.history_reset().await;
// Preparation may have raced with a history reset before capturing the reviewer context.
@@ -33,7 +32,7 @@ impl PreparedGuardianContext {
GuardianContextMode::from_history(history.conversation_history_snapshot().as_ref());
let context_policy = ReviewContextPolicy::for_context(context_mode, &config.features);
let root_authorization_version = context_policy.root_authorization_version(&parent).await;
- let parent_compaction = context_policy.parent_compaction(history, compaction_model_hash)?;
+ let parent_compaction = context_policy.parent_compaction(history)?;
let mut key = GuardianReviewSessionReuseKey::from_spawn_config(
&config,
parent.inherited_instructions().await,
@@ -222,7 +221,6 @@ pub(super) async fn prepare_review(
params.spawn_config.clone(),
&params.parent_history,
&params.node_repl_policy,
- params.compaction_model_hash.as_deref(),
)
.await?;
Ok(PreparedReview {
@@ -257,7 +255,6 @@ pub(super) fn prepare_prewarm(
config.spawn_config,
&history,
&config.node_repl_policy,
- config.compaction_model_hash.as_deref(),
)
.await
})
diff --git a/codex-rs/core/src/guardian/review_session_tests.rs b/codex-rs/core/src/guardian/review_session_tests.rs
index 455c5709e5..44647cb48e 100644
--- a/codex-rs/core/src/guardian/review_session_tests.rs
+++ b/codex-rs/core/src/guardian/review_session_tests.rs
@@ -49,7 +49,6 @@ async fn run_review_preserves_evidence_during_parent_compaction() {
.unwrap();
params.parent_session = Arc::clone(&parent);
params.parent_context = GuardianReviewContext::from(Arc::clone(&turn));
- params.compaction_model_hash = Some("matching".to_owned());
let evidence: ResponseItem = serde_json::from_value(serde_json::json!({
"type": "function_call_output", "call_id": "prior-inspection", "output": EVIDENCE
}))
@@ -251,7 +250,6 @@ async fn test_review_params() -> GuardianReviewSessionParams {
model_overridden: false,
model_override: None,
},
- compaction_model_hash: None,
reasoning_summary,
personality,
external_cancel: None,
@@ -478,7 +476,7 @@ async fn encrypted_parent_compaction_requires_original_item_id(thread_context_en
}]);
assert_eq!(
policy
- .parent_compaction(&history, Some("compatible"))
+ .parent_compaction(&history)
.expect("valid checkpoint"),
Some(item)
);
@@ -493,7 +491,7 @@ async fn encrypted_parent_compaction_requires_original_item_id(thread_context_en
.into(),
);
history.replace_annotated(items);
- let result = policy.parent_compaction(&history, Some("compatible"));
+ let result = policy.parent_compaction(&history);
if thread_context_enabled {
assert!(result.is_err());
} else {