mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
## Why Accepted handoffs and saved transcript chunks need to appear in realtime history. Their text can come from the same user message that model history uses, avoiding a second persisted copy for the receipt. ## What changed - Reconstruct `turnInputAccepted` and transcript chunk receipts from user messages annotated with realtime provenance. Use the stored observation time when restoring the realtime clock. - Replace `sessionEndInputSaved` in the app-server protocol with `sessionInputSaved` and a `reason` of `chunk` or `sessionEnd`. Update the generated schemas and bindings. ## Testing Add coverage for reconstructing both receipt types, preserving rollout order in paginated realtime history, and restoring observation time across a restart after wall-clock rollback. GitOrigin-RevId: fcb4e0e539f4e4066726e83fa1e945fb659a2ca8
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
#![cfg(test)]
|
|
|
|
//! Checks clock rollback and restoration from durable history checkpoints.
|
|
|
|
use super::ObservationClock;
|
|
use codex_history::RolloutItem;
|
|
use codex_protocol::realtime::RealtimeItem;
|
|
use codex_protocol::realtime::RealtimeItemContent;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn observation_time_survives_clock_rollback_and_owner_restart() {
|
|
let mut clock = ObservationClock::default();
|
|
assert_eq!(
|
|
[
|
|
clock.observe(/*wall_clock_ms*/ 100),
|
|
clock.observe(/*wall_clock_ms*/ 90),
|
|
clock.observe(/*wall_clock_ms*/ 110)
|
|
],
|
|
[100, 100, 110]
|
|
);
|
|
|
|
let mut clock = ObservationClock::default();
|
|
clock.restore(&[
|
|
RolloutItem::RealtimeItem(RealtimeItem {
|
|
id: "sealed".into(),
|
|
realtime_session_id: "voice".into(),
|
|
observed_at_ms: Some(110),
|
|
content: RealtimeItemContent::RealtimeSessionStarted,
|
|
}),
|
|
serde_json::from_value(serde_json::json!({
|
|
"type": "response_item",
|
|
"payload": {"type": "message", "id": "msg_input_1", "role": "user", "content": [{"type": "input_text", "text": "hello"}]},
|
|
"metadata": {"realtime_handoff": {"event_id": "receipt", "realtime_session_id": "voice", "observed_at_ms": 115, "handoff_id": "handoff", "mode": "start", "source_event_ids": []}}
|
|
}))
|
|
.expect("read annotated handoff input"),
|
|
RolloutItem::RealtimeItem(RealtimeItem {
|
|
id: "legacy".into(),
|
|
realtime_session_id: "legacy-voice".into(),
|
|
observed_at_ms: None,
|
|
content: RealtimeItemContent::RealtimeSessionStarted,
|
|
}),
|
|
]);
|
|
assert_eq!(
|
|
[
|
|
clock.observe(/*wall_clock_ms*/ 80),
|
|
clock.observe(/*wall_clock_ms*/ 120)
|
|
],
|
|
[115, 120]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn compaction_retains_the_floor_when_older_events_are_omitted() {
|
|
let compacted = serde_json::from_value::<RolloutItem>(serde_json::json!({
|
|
"type": "compacted",
|
|
"payload": {
|
|
"message": "checkpoint",
|
|
"replacement_history": [],
|
|
"window_number": 1,
|
|
"resume_metadata": {
|
|
"observation_clock_floor_ms": 150,
|
|
"multi_agent_version": null,
|
|
"last_started_turn_id": null,
|
|
"previous_turn_settings": null
|
|
}
|
|
}
|
|
}))
|
|
.expect("read persisted checkpoint");
|
|
let mut clock = ObservationClock::default();
|
|
clock.restore(&[compacted]);
|
|
assert_eq!(
|
|
[
|
|
clock.observe(/*wall_clock_ms*/ 100),
|
|
clock.observe(/*wall_clock_ms*/ 200)
|
|
],
|
|
[150, 200]
|
|
);
|
|
}
|