mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
## What changed Introduce `ItemIdGenerator` and pass the runtime-owned generator through sessions, model clients, history, hooks, tool outputs, and memory requests. Keep UUIDv7 generation as the default and replace direct calls to `ResponseItemId::new` with the shared callable. Preserve existing item IDs and backfill missing or empty IDs through the same generator, including forked history before reconstruction and persistence. ## Testing Extend coverage for UUIDv7 IDs on user messages, agent messages, and additional tools, and assert that forked model context matches the backfilled items persisted to history. GitOrigin-RevId: 0dd9ccf0f46f0f1005a6acfc740133b03ce82259
47 lines
1.9 KiB
Rust
47 lines
1.9 KiB
Rust
//! Latest-checkpoint selection keeps structural validity and producer provenance together.
|
|
|
|
use super::*;
|
|
use crate::CodexHarnessMetadata;
|
|
use codex_protocol_test_support::uuid_v7_item_id_generator_for_test;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn latest_checkpoint_keeps_its_own_producer_even_when_unusable() {
|
|
let older = ResponseItemEnvelope {
|
|
item: ResponseItem::Compaction {
|
|
id: Some(uuid_v7_item_id_generator_for_test()("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(uuid_v7_item_id_generator_for_test()("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));
|
|
}
|