mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
## What changed Add `codex_history::CompactionCheckpoint` to keep a checkpoint and its recorded producer model hash together, with shared checks for usability and reviewer compatibility. Replace `ConversationHistorySnapshot::latest_compaction_model_hash()` with `latest_compaction()` and use the shared abstraction in Guardian context selection, review sessions, and parent compaction reuse. Preserve selection of the latest checkpoint even when unusable, and leave missing producer metadata unknown. ## Testing Add coverage showing that the latest checkpoint retains its own provenance even with missing or empty encrypted content, and that compatibility requires matching producer and reviewer hashes. Adapt existing history, migration, and parent compaction tests to the new API. GitOrigin-RevId: 98e794644edf979c98fcc8294baa48ff82ea0ed0
47 lines
1.8 KiB
Rust
47 lines
1.8 KiB
Rust
//! Latest-checkpoint selection keeps structural validity and producer provenance together.
|
|
|
|
use super::*;
|
|
use crate::CodexHarnessMetadata;
|
|
use codex_protocol::ResponseItemId;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn latest_checkpoint_keeps_its_own_producer_even_when_unusable() {
|
|
let older = ResponseItemEnvelope {
|
|
item: ResponseItem::Compaction {
|
|
id: Some(ResponseItemId::new("old")),
|
|
encrypted_content: "older checkpoint".to_owned(),
|
|
internal_chat_message_metadata_passthrough: None,
|
|
},
|
|
metadata: Some(CodexHarnessMetadata {
|
|
compaction_model_hash: Some("producer".to_owned()),
|
|
..Default::default()
|
|
}),
|
|
};
|
|
for content in [None, Some(String::new()), Some("new checkpoint".to_owned())] {
|
|
let usable = content.as_ref().is_some_and(|text| !text.is_empty());
|
|
let latest = ResponseItem::ContextCompaction {
|
|
id: Some(ResponseItemId::new("new")),
|
|
encrypted_content: content,
|
|
internal_chat_message_metadata_passthrough: None,
|
|
};
|
|
let items = [older.clone(), latest.clone().into()];
|
|
let checkpoint = CompactionCheckpoint::latest(&items).expect("latest checkpoint");
|
|
assert_eq!(
|
|
checkpoint,
|
|
CompactionCheckpoint {
|
|
item: &latest,
|
|
model_hash: None
|
|
},
|
|
);
|
|
assert_eq!(checkpoint.is_usable(), usable);
|
|
assert!(!checkpoint.is_compatible_with(Some("producer")));
|
|
}
|
|
let items = [older];
|
|
let checkpoint = CompactionCheckpoint::latest(&items).expect("older checkpoint");
|
|
assert!(checkpoint.is_usable());
|
|
assert!(checkpoint.is_compatible_with(Some("producer")));
|
|
assert!(!checkpoint.is_compatible_with(Some("different")));
|
|
assert!(!checkpoint.is_compatible_with(/*reviewer_model_hash*/ None));
|
|
}
|