mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve pending realtime speech when a call ends (#62299)
## Why A realtime call can end with completed speech that has yet to reach a Codex turn. The next turn needs that context even if the call's transport has already disconnected. ## What changed - For V3 calls with realtime frame history enabled, save pending speech as context for the next turn. Restore it on thread reload and exclude it from the turn count used by rollback. - Drain already received transcript events and settle pending handoffs before saving the call's closing marker. Report recovery required if shutdown cannot confirm that history was saved. - Keep transport detach separate from ending a call. Reattaching restores saved pending speech, and an open call can be ended from persisted history after a reload. Use the call ID for TUI attachments so successive calls on one thread have distinct history. ## Testing Add coverage for queued speech at hangup, reconnect and stop after reload, retries after an uncertain write, and rollback across saved session-end context. GitOrigin-RevId: 657491f1d7e446a1a48e22189758810c8bdd82cb
This commit is contained in:
@@ -297,7 +297,7 @@ else:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_user_prompt_submit_hook(
|
||||
pub(super) fn write_user_prompt_submit_hook(
|
||||
home: &Path,
|
||||
blocked_prompt: &str,
|
||||
additional_context: &str,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use codex_api::RealtimeEvent;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::protocol::ConversationStartParams;
|
||||
use codex_protocol::protocol::ConversationStartTransport;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
@@ -23,6 +24,7 @@ use futures::StreamExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::SystemTime;
|
||||
use tokio::net::TcpListener;
|
||||
@@ -124,7 +126,10 @@ async fn initiated_sideband_delegates_without_callback() -> Result<()> {
|
||||
#[tokio::test]
|
||||
async fn initiated_sideband_backpressure_keeps_events_and_lifecycle_live() -> Result<()> {
|
||||
let api = start_mock_server().await;
|
||||
let test = test_codex().build_with_auto_env(&api).await?;
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let mut transports = Vec::new();
|
||||
for session in ["original", "replacement"] {
|
||||
let (events, incoming) = mpsc::channel(/*buffer*/ 1);
|
||||
@@ -163,6 +168,9 @@ async fn initiated_sideband_backpressure_keeps_events_and_lifecycle_live() -> Re
|
||||
})
|
||||
.await;
|
||||
transports.push((events, commands));
|
||||
if session == "original" {
|
||||
end(&test, session).await?;
|
||||
}
|
||||
}
|
||||
detach(&test, "replacement").await?;
|
||||
for (events, mut commands) in transports {
|
||||
@@ -174,9 +182,9 @@ async fn initiated_sideband_backpressure_keeps_events_and_lifecycle_live() -> Re
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Detach is a history barrier for accepted final speech, including when both caller halves disappear.
|
||||
/// Terminal stop is a history barrier for accepted final speech.
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn initiated_sideband_detach_preserves_queued_transcript_in_history() -> Result<()> {
|
||||
async fn initiated_sideband_end_preserves_queued_transcript_in_history() -> Result<()> {
|
||||
let api = start_mock_server().await;
|
||||
let test = test_codex().build_with_auto_env(&api).await?;
|
||||
test.codex.ensure_rollout_materialized().await;
|
||||
@@ -195,7 +203,7 @@ async fn initiated_sideband_detach_preserves_queued_transcript_in_history() -> R
|
||||
let (outgoing, commands) = mpsc::channel(32);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
let mut start_params = params(&session, "ws://unused.invalid");
|
||||
// Completed turns must persist even when the optional unfinished-tail flush is off.
|
||||
// V3 ignores the old unfinished-tail setting.
|
||||
start_params.flush_transcript_tail_on_session_end = !completed_turn;
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
@@ -211,9 +219,13 @@ async fn initiated_sideband_detach_preserves_queued_transcript_in_history() -> R
|
||||
json!({"type": "input_transcript.added", "item": {"text": text}})
|
||||
};
|
||||
events.try_send(event.to_string())?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::RealtimeConversationRealtime(_))
|
||||
})
|
||||
.await;
|
||||
end(&test, &session).await?;
|
||||
drop(events);
|
||||
drop(commands);
|
||||
detach(&test, &session).await?;
|
||||
let history = test.codex.load_history(/*include_archived*/ false).await?;
|
||||
let tails = history.items.iter().filter(|item| {
|
||||
matches!(item,
|
||||
@@ -227,13 +239,696 @@ async fn initiated_sideband_detach_preserves_queued_transcript_in_history() -> R
|
||||
}).count();
|
||||
assert_eq!(
|
||||
tails, 1,
|
||||
"detach must persist the accepted final transcript exactly once"
|
||||
"terminal stop must persist the accepted final transcript exactly once"
|
||||
);
|
||||
}
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A task-only delegation already parsed before stop is routed while fanout drains.
|
||||
#[tokio::test]
|
||||
async fn terminal_stop_routes_a_parsed_task_only_handoff() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_thread_store::ThreadStore;
|
||||
use core_test_support::responses;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let response = responses::mount_sse_once(&api, responses::sse_completed("queued-task")).await;
|
||||
let store = Arc::new(HostedClockStore::blocking_frame());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.with_model_info_override("gpt-5.5", |model| model.use_responses_lite = false)
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let (events, incoming) = mpsc::channel(1);
|
||||
let (outgoing, _commands) = mpsc::channel(32);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("queued", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
let completed_transcript = "earlier speech ".repeat(400);
|
||||
events
|
||||
.send(
|
||||
json!({"type":"turn.done", "turn":{"role":"user", "transcript":completed_transcript}})
|
||||
.to_string(),
|
||||
)
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), store.wait_for_blocked_frame()).await?;
|
||||
events.send(json!({"type":"delegation.created", "item":{"id":"queued-task", "type":"delegation", "target":"client", "content":[{"type":"input_text", "text":"do this task"}]}}).to_string()).await?;
|
||||
// The one-slot input queue accepting two more events proves the delegation was parsed.
|
||||
for _ in 0..2 {
|
||||
events
|
||||
.send(json!({"type":"session.started", "session":{"id":"queued"}}).to_string())
|
||||
.await?;
|
||||
}
|
||||
let (reply, stopped) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationEnd {
|
||||
realtime_session_id: "queued".to_owned(),
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), events.closed()).await?;
|
||||
store.release_frame();
|
||||
timeout(Duration::from_secs(10), stopped).await???;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
assert_eq!(response.requests().len(), 1);
|
||||
let items = store
|
||||
.load_realtime_session(test.session_configured.thread_id, "queued".to_owned())
|
||||
.await?
|
||||
.expect("started session");
|
||||
assert_eq!(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| matches!(&item.content,
|
||||
RealtimeItemContent::TurnInputAccepted { handoff_id, source_event_ids, .. }
|
||||
if handoff_id == "queued-task" && source_event_ids.is_empty()
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Transport loss must arm recovery even when fanout cannot drain its bounded queue.
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn sideband_loss_with_saturated_fanout_requires_recovery_without_end() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let store = Arc::new(HostedClockStore::blocking_frame());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let (events, incoming) = mpsc::channel(1);
|
||||
let (outgoing, commands) = mpsc::channel(1);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("saturated", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
events
|
||||
.send(
|
||||
json!({"type":"turn.done", "turn":{"role":"user", "transcript":"unfinished"}})
|
||||
.to_string(),
|
||||
)
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), store.wait_for_blocked_frame()).await?;
|
||||
// Fanout's queue holds 256 events; the next event parks its producer, and
|
||||
// the final event occupies the one-slot caller queue.
|
||||
timeout(Duration::from_secs(10), async {
|
||||
for _ in 0..258 {
|
||||
events
|
||||
.send(json!({"type":"session.started", "session":{"id":"saturated"}}).to_string())
|
||||
.await?;
|
||||
}
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.await??;
|
||||
tokio::time::pause();
|
||||
drop(events);
|
||||
drop(commands);
|
||||
// Let the transport watcher and watchdog run as their deadline approaches.
|
||||
for _ in 0..32 {
|
||||
tokio::time::advance(Duration::from_secs(1)).await;
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
tokio::time::resume();
|
||||
let closed = timeout(Duration::from_secs(10), async {
|
||||
loop {
|
||||
if let EventMsg::RealtimeConversationClosed(closed) = test.codex.next_event().await?.msg
|
||||
{
|
||||
break anyhow::Ok(closed);
|
||||
}
|
||||
}
|
||||
})
|
||||
.await??;
|
||||
assert_eq!(closed.reason.as_deref(), Some("history_recovery_required"));
|
||||
store.release_frame();
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Realtime frames carry pending input over at logical end, including after detach.
|
||||
#[tokio::test]
|
||||
async fn frame_enrolled_v3_saves_input_even_when_legacy_flush_setting_is_false() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_protocol::realtime::SessionInputReason;
|
||||
use codex_thread_store::ThreadStore;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let store = Arc::new(HostedClockStore::default());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let (events, incoming) = mpsc::channel(1);
|
||||
let (outgoing, _commands) = mpsc::channel(1);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
let mut start = params("no-flush", "ws://unused.invalid");
|
||||
start.flush_transcript_tail_on_session_end = false;
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: start,
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
events
|
||||
.send(
|
||||
json!({"type":"input_transcript.added", "item":{"text":"save this at hangup"}})
|
||||
.to_string(),
|
||||
)
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::RealtimeConversationRealtime(event)
|
||||
if matches!(event.payload, codex_protocol::protocol::RealtimeEvent::InputTranscriptDelta(_)))
|
||||
}).await;
|
||||
end(&test, "no-flush").await?;
|
||||
let items = store
|
||||
.load_realtime_session(test.session_configured.thread_id, "no-flush".to_owned())
|
||||
.await?
|
||||
.expect("started session");
|
||||
assert!(items.iter().any(|item| matches!(&item.content,
|
||||
RealtimeItemContent::SessionInputSaved { reason: SessionInputReason::SessionEnd, input, .. }
|
||||
if input.contains("save this at hangup")
|
||||
)));
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Thread-scoped Stop recovers the latest open persisted session after Core reload.
|
||||
#[tokio::test]
|
||||
async fn thread_stop_recovers_and_finishes_the_latest_persisted_session() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_protocol::realtime::RealtimeFrameChannels;
|
||||
use codex_protocol::realtime::RealtimeItem;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_protocol::realtime::RealtimeTranscriptRole;
|
||||
use codex_protocol::realtime::RealtimeVoiceTranscript;
|
||||
use codex_protocol::realtime::SessionInputReason;
|
||||
use codex_thread_store::ThreadStore;
|
||||
use core_test_support::responses;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let model = responses::mount_sse_once(
|
||||
&api,
|
||||
responses::sse(vec![responses::ev_response_created("unexpected")]),
|
||||
)
|
||||
.await;
|
||||
let store = Arc::new(HostedClockStore::default());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let thread_id = test.session_configured.thread_id;
|
||||
let session_id = "cold-stop";
|
||||
// Populate only persisted history: this Core runtime has never attached the call.
|
||||
store
|
||||
.seal_realtime_items(
|
||||
thread_id,
|
||||
vec![
|
||||
RealtimeItem {
|
||||
id: "start".to_owned(),
|
||||
realtime_session_id: session_id.to_owned(),
|
||||
observed_at_ms: Some(1),
|
||||
content: RealtimeItemContent::RealtimeSessionStarted,
|
||||
},
|
||||
RealtimeItem {
|
||||
id: "speech".to_owned(),
|
||||
realtime_session_id: session_id.to_owned(),
|
||||
observed_at_ms: Some(2),
|
||||
content: RealtimeItemContent::Frame {
|
||||
channels: RealtimeFrameChannels {
|
||||
voice_transcript: RealtimeVoiceTranscript {
|
||||
role: RealtimeTranscriptRole::User,
|
||||
text: "remember the smaller logo".to_owned(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
)
|
||||
.await?;
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::RealtimeConversationClosed(_))
|
||||
})
|
||||
.await;
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
let items = store
|
||||
.load_realtime_session(thread_id, session_id.to_owned())
|
||||
.await?
|
||||
.expect("persisted session");
|
||||
assert_eq!(
|
||||
items.iter().filter(|item| matches!(&item.content,
|
||||
RealtimeItemContent::SessionInputSaved { reason: SessionInputReason::SessionEnd, input, source_event_ids, .. }
|
||||
if input.contains("remember the smaller logo") && source_event_ids == &["speech".to_owned()]
|
||||
)).count(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| matches!(
|
||||
item.content,
|
||||
RealtimeItemContent::RealtimeSessionClosed { .. }
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
assert!(model.requests().is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A timeout fences an allowing steer hook and lets ordinary turn abort own cleanup.
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn hangup_timeout_aborts_a_turn_with_an_allowing_steer_hook() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_thread_store::LoadThreadHistoryParams;
|
||||
use codex_thread_store::ThreadStore;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::streaming_sse::StreamingSseChunk;
|
||||
use core_test_support::streaming_sse::start_streaming_sse_server;
|
||||
|
||||
core_test_support::skip_if_wine_exec!(Ok(()), "the hook requires host-native Python");
|
||||
let (release_response, response_gate) = oneshot::channel();
|
||||
let (server, _completions) = start_streaming_sse_server(vec![vec![
|
||||
StreamingSseChunk {
|
||||
gate: None,
|
||||
body: responses::sse(vec![responses::ev_response_created("active")]),
|
||||
},
|
||||
StreamingSseChunk {
|
||||
gate: Some(response_gate),
|
||||
body: responses::sse(vec![responses::ev_completed("active")]),
|
||||
},
|
||||
]])
|
||||
.await;
|
||||
let store = Arc::new(HostedClockStore::default());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.with_config(core_test_support::hooks::trust_discovered_hooks)
|
||||
.with_pre_build_hook(|home| {
|
||||
super::hooks::write_user_prompt_submit_hook(home, "never-block", "")
|
||||
.expect("write allowing prompt hook");
|
||||
let script = home.join("user_prompt_submit_hook.py");
|
||||
let original = std::fs::read_to_string(&script).expect("read hook");
|
||||
let gate = format!(
|
||||
"payload = json.load(sys.stdin)\nif 'steer-timeout' in payload.get('prompt', ''):\n import time\n Path(r\"{}\").touch()\n while not Path(r\"{}\").exists():\n time.sleep(0.01)",
|
||||
home.join("hook_started").display(),
|
||||
home.join("hook_release").display(),
|
||||
);
|
||||
std::fs::write(script, original.replace("payload = json.load(sys.stdin)", &gate))
|
||||
.expect("gate allowing steer hook");
|
||||
})
|
||||
.build_with_streaming_server(&server)
|
||||
.await?;
|
||||
let started = test
|
||||
.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "initial active turn".to_owned(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await?;
|
||||
let turn_id = match started {
|
||||
codex_core::TurnInputSubmission::Started { turn_id, .. } => turn_id,
|
||||
other => anyhow::bail!("expected started turn, got {other:?}"),
|
||||
};
|
||||
timeout(
|
||||
Duration::from_secs(10),
|
||||
server.wait_for_request_count(/*count*/ 1),
|
||||
)
|
||||
.await?;
|
||||
let (events, incoming) = mpsc::channel(8);
|
||||
let (outgoing, _commands) = mpsc::channel(8);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("hook-timeout", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
events.send(json!({"type":"delegation.created", "item":{"id":"steer-timeout", "type":"delegation", "target":"client", "content":[{"type":"input_text", "text":"steer-timeout"}]}}).to_string()).await?;
|
||||
wait_for_event(&test.codex, |event| matches!(event,
|
||||
EventMsg::RealtimeConversationRealtime(event)
|
||||
if matches!(&event.payload, RealtimeEvent::HandoffRequested(handoff) if handoff.handoff_id == "steer-timeout")
|
||||
)).await;
|
||||
release_response.send(()).expect("first response gate");
|
||||
let started = test.home.path().join("hook_started");
|
||||
timeout(Duration::from_secs(10), async {
|
||||
while !started.exists() {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
let (reply, mut stopped) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationEnd {
|
||||
realtime_session_id: "hook-timeout".to_owned(),
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
assert!(
|
||||
timeout(Duration::from_millis(100), &mut stopped)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
tokio::time::pause();
|
||||
tokio::time::advance(Duration::from_secs(31)).await;
|
||||
let result = timeout(Duration::from_secs(10), stopped).await;
|
||||
tokio::time::resume();
|
||||
assert!(result??.is_err(), "timeout must require recovery");
|
||||
std::fs::write(test.home.path().join("hook_release"), "")?;
|
||||
wait_for_event(&test.codex, |event| matches!(event, EventMsg::TurnAborted(aborted) if aborted.turn_id.as_deref() == Some(turn_id.as_str()))).await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
assert_eq!(
|
||||
server.requests().await.len(),
|
||||
1,
|
||||
"the released steer must not sample"
|
||||
);
|
||||
let history = store
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id: test.session_configured.thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(history.items.iter().filter(|item| matches!(item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(aborted)) if aborted.turn_id.as_deref() == Some(turn_id.as_str())
|
||||
) || matches!(item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) if completed.turn_id == turn_id
|
||||
)).count(), 1);
|
||||
let session = store
|
||||
.load_realtime_session(test.session_configured.thread_id, "hook-timeout".to_owned())
|
||||
.await?
|
||||
.expect("started session");
|
||||
assert!(!session.iter().any(|item| matches!(&item.content,
|
||||
RealtimeItemContent::TurnInputAccepted { handoff_id, .. } if handoff_id == "steer-timeout"
|
||||
)));
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
server.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reattaching an open logical call does not start a second session; a later cold stop closes it.
|
||||
#[tokio::test]
|
||||
async fn reconnect_restores_sealed_pending_speech_and_rejects_closed_reuse() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_protocol::realtime::SessionInputReason;
|
||||
use codex_thread_store::ThreadStore;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let store = Arc::new(HostedClockStore::default());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
for attach in 0..2 {
|
||||
let (events, incoming) = mpsc::channel(8);
|
||||
let (outgoing, _commands) = mpsc::channel(8);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("reconnect", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
if attach == 0 {
|
||||
events
|
||||
.send(json!({"type":"input_transcript.added", "item":{"text":"use the smaller logo"}}).to_string())
|
||||
.await?;
|
||||
events
|
||||
.send(json!({"type":"turn.done", "turn":{"role":"user","transcript":"use the smaller logo"}}).to_string())
|
||||
.await?;
|
||||
// Detach may discard unsealed deltas; recover only after the frame is durable.
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event,
|
||||
EventMsg::RealtimeConversationRealtime(event)
|
||||
if matches!(&event.payload,
|
||||
codex_protocol::protocol::RealtimeEvent::HistoryItemCompleted(item)
|
||||
if matches!(&item.content, RealtimeItemContent::Frame { .. })
|
||||
)
|
||||
)
|
||||
})
|
||||
.await;
|
||||
}
|
||||
detach(&test, "reconnect").await?;
|
||||
}
|
||||
end(&test, "reconnect").await?;
|
||||
end(&test, "reconnect").await?;
|
||||
let items = store
|
||||
.load_realtime_session(test.session_configured.thread_id, "reconnect".to_owned())
|
||||
.await?
|
||||
.expect("started session");
|
||||
assert_eq!(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| matches!(item.content, RealtimeItemContent::RealtimeSessionStarted))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
items
|
||||
.iter()
|
||||
.filter(|item| matches!(
|
||||
item.content,
|
||||
RealtimeItemContent::RealtimeSessionClosed { .. }
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
let frame = items
|
||||
.iter()
|
||||
.find(|item| matches!(item.content, RealtimeItemContent::Frame { .. }))
|
||||
.expect("sealed frame");
|
||||
assert!(items.iter().any(|item| matches!(&item.content,
|
||||
RealtimeItemContent::SessionInputSaved { reason: SessionInputReason::SessionEnd, input, source_event_ids, .. }
|
||||
if input.contains("use the smaller logo") && source_event_ids.as_slice() == std::slice::from_ref(&frame.id)
|
||||
)));
|
||||
let (_events, incoming) = mpsc::channel(8);
|
||||
let (outgoing, _commands) = mpsc::channel(8);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("reconnect", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
assert!(timeout(Duration::from_secs(10), ready).await??.is_err());
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// An uncertain but committed voice input keeps its place ahead of later typed input on replay.
|
||||
#[tokio::test]
|
||||
async fn committed_handoff_retry_preserves_live_and_recovery_input_order() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_thread_store::LoadThreadHistoryParams;
|
||||
use core_test_support::responses;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let model = responses::mount_sse_sequence(
|
||||
&api,
|
||||
["voice", "typed"].map(responses::sse_completed).into(),
|
||||
)
|
||||
.await;
|
||||
let store = Arc::new(HostedClockStore::failing_after_input_commit());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_model_info_override("gpt-5.5", |model| model.use_responses_lite = false)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let (events, incoming) = mpsc::channel(32);
|
||||
let (outgoing, _commands) = mpsc::channel(32);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("order", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
events
|
||||
.send(json!({"type":"delegation.created","item":{"id":"handoff-A","type":"delegation","target":"client","content":[{"type":"input_text","text":"voice A"}]}}).to_string())
|
||||
.await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
assert_eq!(store.input_attempts(), 2);
|
||||
test.submit_text_turn("typed B").await?;
|
||||
|
||||
let label = |text: &str| {
|
||||
if text.contains("<input>voice A</input>") {
|
||||
Some("A")
|
||||
} else if text == "typed B" {
|
||||
Some("B")
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
let live = model.requests()[1]
|
||||
.message_input_texts("user")
|
||||
.iter()
|
||||
.filter_map(|text| label(text))
|
||||
.collect::<Vec<_>>();
|
||||
let context = test
|
||||
.thread_store
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id: test.session_configured.thread_id,
|
||||
include_archived: true,
|
||||
})
|
||||
.await?;
|
||||
let recovery = context
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::ResponseItem(envelope) => match &envelope.item {
|
||||
ResponseItem::Message { role, content, .. } if role == "user" => Some(content),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.filter_map(|content| match content {
|
||||
ContentItem::InputText { text } => label(text),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!((live, recovery), (vec!["A", "B"], vec!["A", "B"]));
|
||||
detach(&test, "order").await?;
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A failed close is terminal for the current owner; retrying Stop cannot replay an uncertain write.
|
||||
#[tokio::test]
|
||||
async fn failed_close_requires_history_recovery_before_another_call() -> Result<()> {
|
||||
use super::realtime_conversation::realtime_history_store::HostedClockStore;
|
||||
use codex_core::TurnInputRequest;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_protocol::error::CodexErrorDetails;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_thread_store::ThreadStore;
|
||||
use core_test_support::wait_for_event_match;
|
||||
|
||||
let api = start_mock_server().await;
|
||||
let store = Arc::new(HostedClockStore::failing_close());
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_thread_store(store.clone())
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let (_events, incoming) = mpsc::channel(32);
|
||||
let (outgoing, _commands) = mpsc::channel(32);
|
||||
let (reply, ready) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationAttachStream {
|
||||
params: params("failed-close", "ws://unused.invalid"),
|
||||
transport: RealtimeSidebandTransport { incoming, outgoing },
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
timeout(Duration::from_secs(10), ready).await???;
|
||||
|
||||
let (reply, result) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationEnd {
|
||||
realtime_session_id: "failed-close".to_owned(),
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
let error = timeout(Duration::from_secs(10), result)
|
||||
.await??
|
||||
.expect_err("an uncertain close must fail End");
|
||||
assert!(
|
||||
matches!(error.details(), CodexErrorDetails::Fatal(message) if message == "realtime history recovery required; reload the thread before continuing")
|
||||
);
|
||||
let closed = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::RealtimeConversationClosed(closed) => Some(closed.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(closed.reason.as_deref(), Some("history_recovery_required"));
|
||||
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
let repeated = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::RealtimeConversationClosed(closed) => Some(closed.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(repeated, closed);
|
||||
assert_eq!(store.close_attempts(), 1);
|
||||
let history = store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id: test.session_configured.thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
assert!(!history.items.iter().any(|item| matches!(item,
|
||||
RolloutItem::RealtimeItem(item)
|
||||
if matches!(item.content, RealtimeItemContent::RealtimeSessionClosed { .. })
|
||||
)));
|
||||
|
||||
let (_, result) = start(&test, "next-call", "ws://unused.invalid").await?;
|
||||
let error = timeout(Duration::from_secs(10), result)
|
||||
.await??
|
||||
.expect_err("a new attachment must wait for recovery");
|
||||
assert!(matches!(error.details(), CodexErrorDetails::Fatal(_)));
|
||||
let error = test
|
||||
.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||
text: "continue".to_owned(),
|
||||
text_elements: Vec::new(),
|
||||
}]))
|
||||
.await
|
||||
.expect_err("turn input must wait for recovery");
|
||||
assert!(matches!(error.details(), CodexErrorDetails::Fatal(_)));
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct Connection {
|
||||
accept: oneshot::Sender<bool>,
|
||||
messages: mpsc::UnboundedReceiver<Value>,
|
||||
@@ -333,7 +1028,7 @@ fn params(session: &str, url: &str) -> ConversationStartParams {
|
||||
ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
flush_transcript_tail_on_session_end: true,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode: Default::default(),
|
||||
@@ -387,6 +1082,34 @@ async fn detach(test: &TestCodex, session: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn end(test: &TestCodex, session: &str) -> Result<()> {
|
||||
timeout(Duration::from_secs(10), async {
|
||||
loop {
|
||||
let (reply, result) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationEnd {
|
||||
realtime_session_id: session.to_owned(),
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
match result.await? {
|
||||
Ok(()) => return anyhow::Ok(()),
|
||||
Err(error) if is_realtime_busy(&error) => {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
Err(error) => return Err(error.into()),
|
||||
}
|
||||
}
|
||||
})
|
||||
.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_realtime_busy(error: &codex_protocol::error::CodexErr) -> bool {
|
||||
matches!(error.details(), codex_protocol::error::CodexErrorDetails::Io(error)
|
||||
if error.kind() == std::io::ErrorKind::WouldBlock)
|
||||
}
|
||||
|
||||
async fn attached(
|
||||
test: &TestCodex,
|
||||
server: &mut Sideband,
|
||||
@@ -608,11 +1331,22 @@ pub(super) async fn attachment_replacement_scenario() -> Result<Vec<ResponsesReq
|
||||
})
|
||||
.with_config(|config| {
|
||||
config.base_instructions = Some(String::new());
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
});
|
||||
let test = builder.build_with_auto_env(&api).await?;
|
||||
let mut original = Sideband::new().await?;
|
||||
let mut newer = Sideband::new().await?;
|
||||
let (original_id, mut original_messages) = attached(&test, &mut original, "original").await?;
|
||||
let (_, busy) = start(&test, "newer", &newer.url).await?;
|
||||
assert!(is_realtime_busy(
|
||||
&timeout(Duration::from_secs(10), busy)
|
||||
.await??
|
||||
.expect_err("replacement settles first")
|
||||
));
|
||||
end(&test, "original").await?;
|
||||
let (newer_id, mut completion) = start(&test, "newer", &newer.url).await?;
|
||||
let connection = newer.connected().await;
|
||||
assert_eq!(
|
||||
@@ -670,10 +1404,22 @@ pub(super) async fn attachment_replacement_scenario() -> Result<Vec<ResponsesReq
|
||||
#[tokio::test]
|
||||
async fn failed_attachment_leaves_core_disconnected() -> Result<()> {
|
||||
let api = start_mock_server().await;
|
||||
let test = test_codex().build_with_auto_env(&api).await?;
|
||||
let test = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_config(|config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
})
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let mut original = Sideband::new().await?;
|
||||
let mut newer = Sideband::new().await?;
|
||||
let (_, mut current) = attached(&test, &mut original, "original").await?;
|
||||
let (_, busy) = start(&test, "newer", &newer.url).await?;
|
||||
assert!(timeout(Duration::from_secs(10), busy).await??.is_err());
|
||||
end(&test, "original").await?;
|
||||
let (_, result) = start(&test, "newer", &newer.url).await?;
|
||||
let connection = newer.connected().await;
|
||||
assert_eq!(
|
||||
@@ -688,10 +1434,14 @@ async fn failed_attachment_leaves_core_disconnected() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case::test_case(true; "record unfinished tail")]
|
||||
#[test_case::test_case(false; "drop unfinished tail")]
|
||||
#[test_case::test_case(ThreadHistoryMode::Legacy, true; "legacy record unfinished tail")]
|
||||
#[test_case::test_case(ThreadHistoryMode::Legacy, false; "legacy setting ignored for v3")]
|
||||
#[test_case::test_case(ThreadHistoryMode::Paginated, true; "frames record unfinished tail")]
|
||||
#[tokio::test]
|
||||
async fn completed_turns_reach_history_before_the_next_handoff(flush_tail: bool) -> Result<()> {
|
||||
async fn completed_turns_reach_history_before_the_next_handoff(
|
||||
history_mode: ThreadHistoryMode,
|
||||
flush_tail: bool,
|
||||
) -> Result<()> {
|
||||
use codex_protocol::protocol::RealtimeEvent;
|
||||
use core_test_support::responses;
|
||||
use core_test_support::wait_for_event;
|
||||
@@ -704,7 +1454,10 @@ async fn completed_turns_reach_history_before_the_next_handoff(flush_tail: bool)
|
||||
])
|
||||
});
|
||||
let model = responses::mount_sse_sequence(&api, replies.into()).await;
|
||||
let test = test_codex().build_with_auto_env(&api).await?;
|
||||
let test = test_codex()
|
||||
.with_history_mode(history_mode)
|
||||
.build_with_auto_env(&api)
|
||||
.await?;
|
||||
let mut sideband = Sideband::new().await?;
|
||||
let mut params = params("transcript", &sideband.url);
|
||||
params.flush_transcript_tail_on_session_end = flush_tail;
|
||||
@@ -763,15 +1516,13 @@ async fn completed_turns_reach_history_before_the_next_handoff(flush_tail: bool)
|
||||
let unfinished = "a".repeat(12 * 1024);
|
||||
send(json!({"type":"output_transcript.added", "item":{"text":unfinished}}))?;
|
||||
wait_for_event(&test.codex, |event| matches!(event, EventMsg::RealtimeConversationRealtime(event) if matches!(event.payload, RealtimeEvent::OutputTranscriptDelta(_)))).await;
|
||||
detach(&test, "transcript").await?;
|
||||
end(&test, "transcript").await?;
|
||||
test.submit_text_turn("continue").await?;
|
||||
let after_close = transcript(model.last_request().expect("text turn"));
|
||||
assert_eq!(after_close.len(), completed.len() + usize::from(flush_tail));
|
||||
assert_eq!(after_close.len(), completed.len() + 1);
|
||||
assert_eq!(&after_close[..completed.len()], completed.as_slice());
|
||||
if flush_tail {
|
||||
assert!(after_close[completed.len()].contains(&format!(
|
||||
"<transcript_delta>assistant: {unfinished}</transcript_delta>"
|
||||
)));
|
||||
}
|
||||
assert!(after_close[completed.len()].contains(&format!(
|
||||
"<transcript_delta>assistant: {unfinished}</transcript_delta>"
|
||||
)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -12,7 +12,9 @@ use codex_core::TurnInputRequest;
|
||||
use codex_core::TurnInputSubmission;
|
||||
use codex_core::test_support::auth_manager_from_auth;
|
||||
use codex_features::Feature;
|
||||
use codex_history::CodexHarnessMetadata;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_history::RealtimeHandoffMetadata;
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_login::CodexAuth;
|
||||
@@ -88,6 +90,9 @@ use wiremock::matchers::method;
|
||||
use wiremock::matchers::path;
|
||||
use wiremock::matchers::path_regex;
|
||||
|
||||
#[path = "realtime_history_store.rs"]
|
||||
pub(super) mod realtime_history_store;
|
||||
|
||||
const STARTUP_CONTEXT_HEADER: &str = "Startup context from Codex.";
|
||||
const STARTUP_CONTEXT_OPEN_TAG: &str = "<startup_context>";
|
||||
const STARTUP_CONTEXT_CLOSE_TAG: &str = "</startup_context>";
|
||||
@@ -2318,8 +2323,148 @@ async fn conversation_start_uses_openai_env_key_fallback_with_chatgpt_auth() ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn two_existing_calls_on_one_thread_keep_distinct_openings_and_saved_tails() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let calls = [("rtc_first", "first tail"), ("rtc_second", "second tail")];
|
||||
let realtime_server = start_websocket_server_with_headers(calls.iter().map(|(id, tail)| {
|
||||
WebSocketConnectionConfig {
|
||||
requests: vec![vec![
|
||||
json!({"type":"session.updated", "session":{"id":id, "instructions":"fixture"}}),
|
||||
json!({"type":"input_transcript.added", "item":{"text":tail}}),
|
||||
]],
|
||||
response_headers: Vec::new(),
|
||||
accept_delay: None,
|
||||
close_after_requests: false,
|
||||
}
|
||||
}).collect()).await;
|
||||
let api_server = start_mock_server().await;
|
||||
let mut builder = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_config({
|
||||
let url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
config.experimental_realtime_ws_base_url = Some(url);
|
||||
config.realtime.version = RealtimeWsVersion::V3;
|
||||
}
|
||||
});
|
||||
let test = builder.build_with_auto_env(&api_server).await?;
|
||||
test.codex.ensure_rollout_materialized().await;
|
||||
for (call_id, _) in calls {
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: true,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
codex_protocol::protocol::CodexResponseHandoffMode::Thinking,
|
||||
backend_reasoning_status: false,
|
||||
codex_response_handoff_channel_prefixes: None,
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: false,
|
||||
initial_items: Vec::new(),
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: None,
|
||||
realtime_session_id: None,
|
||||
voice_session_id: None,
|
||||
transport: Some(ConversationStartTransport::ExistingCall {
|
||||
call_id: call_id.to_string(),
|
||||
sideband_base_url: None,
|
||||
}),
|
||||
version: Some(RealtimeConversationVersion::V3),
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let started = wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationStarted(event) => Some(event.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(started.realtime_session_id.as_deref(), Some(call_id));
|
||||
// Existing-call attach sends no session.update. Trigger the fixture's transcript.
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationText(ConversationTextParams {
|
||||
text: "ready".into(),
|
||||
role: ConversationTextRole::User,
|
||||
}))
|
||||
.await?;
|
||||
wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationRealtime(RealtimeConversationRealtimeEvent {
|
||||
payload: RealtimeEvent::InputTranscriptDelta(_),
|
||||
}) => Some(()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
wait_for_event_match(&test.codex, |msg| match msg {
|
||||
EventMsg::RealtimeConversationClosed(_) => Some(()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
for (call_id, tail) in calls {
|
||||
let page = test
|
||||
.thread_store
|
||||
.list_realtime(codex_thread_store::ListRealtimeParams {
|
||||
thread_id: test.session_configured.thread_id,
|
||||
session_id: Some(call_id.into()),
|
||||
order: codex_app_server_protocol::ThreadRealtimeOrder::Position,
|
||||
page_size: 20,
|
||||
from_observed_at_ms: None,
|
||||
to_observed_at_ms: None,
|
||||
after_position: None,
|
||||
event_id: None,
|
||||
cursor: None,
|
||||
snapshot_end: None,
|
||||
required_through_position: None,
|
||||
})
|
||||
.await?;
|
||||
let openings = page
|
||||
.data
|
||||
.iter()
|
||||
.filter(|entry| {
|
||||
matches!(
|
||||
entry.item.content,
|
||||
ThreadRealtimeItemContent::RealtimeSessionStarted
|
||||
)
|
||||
})
|
||||
.count();
|
||||
assert_eq!(openings, 1);
|
||||
let tails: Vec<_> = page
|
||||
.data
|
||||
.iter()
|
||||
.filter_map(|entry| match &entry.item.content {
|
||||
ThreadRealtimeItemContent::SessionInputSaved {
|
||||
reason: codex_app_server_protocol::ThreadRealtimeSessionInputReason::SessionEnd,
|
||||
input,
|
||||
..
|
||||
} => Some(input),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let [saved] = tails.as_slice() else {
|
||||
panic!("expected one saved tail for {call_id}, got {tails:?}");
|
||||
};
|
||||
assert!(saved.contains(&format!("user: {tail}")));
|
||||
}
|
||||
test.codex.submit(Op::Shutdown).await?;
|
||||
realtime_server.shutdown().await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn assert_transport_close_tail_flush(
|
||||
flush_transcript_tail_on_session_end: bool,
|
||||
history_mode: ThreadHistoryMode,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
@@ -2345,9 +2490,13 @@ async fn assert_transport_close_tail_flush(
|
||||
]]])
|
||||
.await;
|
||||
|
||||
let mut builder = test_codex().with_config({
|
||||
let mut builder = test_codex().with_history_mode(history_mode).with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
}
|
||||
@@ -2413,14 +2562,25 @@ async fn assert_transport_close_tail_flush(
|
||||
.await;
|
||||
assert_eq!(closed.reason.as_deref(), Some("transport_closed"));
|
||||
// Closed must be a history barrier, including when there is no active turn.
|
||||
let history = test.codex.load_history(/*include_archived*/ false).await?;
|
||||
let tails = history.items.iter().filter(|item| {
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
let ordinary_tails = history.iter().filter(|item| {
|
||||
matches!(item, RolloutItem::ResponseItem(ResponseItemEnvelope { item: ResponseItem::Message { role, content, .. }, .. })
|
||||
if role == "user" && content.iter().any(|item| matches!(item,
|
||||
ContentItem::InputText { text } if text.contains("<source>transcript_tail_flush</source>")
|
||||
&& text.contains("user: transport tail"))))
|
||||
}).count();
|
||||
assert_eq!(tails, usize::from(flush_transcript_tail_on_session_end));
|
||||
let saved_tails = history.iter().filter(|item| {
|
||||
matches!(item, RolloutItem::RealtimeItem(codex_protocol::realtime::RealtimeItem {
|
||||
content: codex_protocol::realtime::RealtimeItemContent::SessionInputSaved { reason: codex_protocol::realtime::SessionInputReason::SessionEnd, input, .. }, ..
|
||||
}) if input.contains("user: transport tail"))
|
||||
}).count();
|
||||
let expected = usize::from(flush_transcript_tail_on_session_end);
|
||||
// Protocol V1 retains the old opt-in transcript flush in either history mode.
|
||||
assert_eq!((ordinary_tails, saved_tails), (expected, 0));
|
||||
assert!(response_mock.requests().is_empty());
|
||||
|
||||
test.submit_text_turn("continue in text").await?;
|
||||
@@ -2438,8 +2598,18 @@ async fn assert_transport_close_tail_flush(
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn conversation_transport_close_tail_flush_is_opt_in() -> Result<()> {
|
||||
assert_transport_close_tail_flush(/*flush_transcript_tail_on_session_end*/ false).await?;
|
||||
assert_transport_close_tail_flush(/*flush_transcript_tail_on_session_end*/ true).await?;
|
||||
for history_mode in [ThreadHistoryMode::Legacy, ThreadHistoryMode::Paginated] {
|
||||
assert_transport_close_tail_flush(
|
||||
/*flush_transcript_tail_on_session_end*/ false,
|
||||
history_mode,
|
||||
)
|
||||
.await?;
|
||||
assert_transport_close_tail_flush(
|
||||
/*flush_transcript_tail_on_session_end*/ true,
|
||||
history_mode,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4919,7 +5089,31 @@ fn message_input_texts(body: &Value, role: &str) -> Vec<String> {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
realtime_handoff_history_scenario(/*block_prompt*/ false).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn realtime_handoff_hook_rejection_has_no_acceptance_receipt() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
core_test_support::skip_if_wine_exec!(
|
||||
Ok(()),
|
||||
"the prompt hook requires host-native Python and filesystem paths"
|
||||
);
|
||||
realtime_handoff_history_scenario(/*block_prompt*/ true).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn realtime_handoff_history_scenario(
|
||||
block_prompt: bool,
|
||||
) -> Result<Vec<responses::ResponsesRequest>> {
|
||||
realtime_handoff_history_scenario_inner(block_prompt).await
|
||||
}
|
||||
|
||||
async fn realtime_handoff_history_scenario_inner(
|
||||
block_prompt: bool,
|
||||
) -> Result<Vec<responses::ResponsesRequest>> {
|
||||
let api_server = start_mock_server().await;
|
||||
let response_mock = responses::mount_sse_once(
|
||||
&api_server,
|
||||
@@ -4931,22 +5125,27 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
)
|
||||
.await;
|
||||
|
||||
let realtime_server = start_websocket_server(vec![vec![vec![
|
||||
json!({
|
||||
"type": "session.updated",
|
||||
"session": { "id": "sess_inbound", "instructions": "backend prompt" }
|
||||
}),
|
||||
json!({
|
||||
"type": "conversation.input_transcript.delta",
|
||||
"delta": "text from realtime"
|
||||
}),
|
||||
json!({
|
||||
"type": "conversation.handoff.requested",
|
||||
"handoff_id": "handoff_inbound",
|
||||
"item_id": "item_inbound",
|
||||
"input_transcript": "text from realtime"
|
||||
}),
|
||||
]]])
|
||||
let realtime_server = start_websocket_server_with_headers(vec![WebSocketConnectionConfig {
|
||||
requests: vec![vec![
|
||||
json!({
|
||||
"type": "session.updated",
|
||||
"session": { "id": "sess_inbound", "instructions": "backend prompt" }
|
||||
}),
|
||||
if block_prompt {
|
||||
json!({"type":"input_transcript.added", "item":{"text":"text from realtime"}})
|
||||
} else {
|
||||
json!({"type":"conversation.input_transcript.delta", "delta":"text from realtime"})
|
||||
},
|
||||
if block_prompt {
|
||||
json!({"type":"delegation.created", "item":{"id":"handoff_inbound", "type":"delegation", "target":"client", "content":[{"type":"input_text", "text":"text from realtime"}]}})
|
||||
} else {
|
||||
json!({"type":"conversation.handoff.requested", "handoff_id":"handoff_inbound", "item_id":"item_inbound", "input_transcript":"text from realtime"})
|
||||
},
|
||||
]],
|
||||
response_headers: Vec::new(),
|
||||
accept_delay: None,
|
||||
close_after_requests: !block_prompt,
|
||||
}])
|
||||
.await;
|
||||
|
||||
let mut builder = test_codex()
|
||||
@@ -4954,17 +5153,46 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
.with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
if block_prompt {
|
||||
core_test_support::hooks::trust_discovered_hooks(config);
|
||||
}
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
config.realtime.version = if block_prompt {
|
||||
RealtimeWsVersion::V3
|
||||
} else {
|
||||
RealtimeWsVersion::V1
|
||||
};
|
||||
}
|
||||
});
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
builder = builder.with_pre_build_hook(move |home| {
|
||||
if block_prompt {
|
||||
super::hooks::write_user_prompt_submit_hook(home,
|
||||
"<realtime_delegation>\n <input>text from realtime</input>\n <transcript_delta>user: text from realtime</transcript_delta>\n</realtime_delegation>", "")
|
||||
.expect("write blocking realtime prompt hook");
|
||||
let script = home.join("user_prompt_submit_hook.py");
|
||||
let existing = fs::read_to_string(&script).expect("read prompt hook");
|
||||
let gate = format!(
|
||||
"import time\nfrom pathlib import Path\nPath(r\"{}\").touch()\nwhile not Path(r\"{}\").exists():\n time.sleep(0.01)\n",
|
||||
home.join("hook_started").display(),
|
||||
home.join("hook_release").display(),
|
||||
);
|
||||
fs::write(script, format!("{gate}{existing}")).expect("gate prompt hook");
|
||||
}
|
||||
});
|
||||
}
|
||||
let test = builder.build_with_auto_env(&api_server).await?;
|
||||
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
flush_transcript_tail_on_session_end: block_prompt,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
@@ -4978,7 +5206,7 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: Some(Some("backend prompt".to_string())),
|
||||
realtime_session_id: None,
|
||||
realtime_session_id: Some("sess_inbound".to_owned()),
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
@@ -5019,11 +5247,65 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
};
|
||||
Uuid::parse_str(&turn_id).context("realtime-routed turn ID should be a UUID")?;
|
||||
|
||||
if block_prompt {
|
||||
let started = test.home.path().join("hook_started");
|
||||
timeout(Duration::from_secs(10), async {
|
||||
while !started.exists() {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.context("prompt hook did not start")?;
|
||||
let (reply, mut stopped) = oneshot::channel();
|
||||
test.codex
|
||||
.submit(Op::RealtimeConversationEnd {
|
||||
realtime_session_id: "sess_inbound".to_owned(),
|
||||
reply,
|
||||
})
|
||||
.await?;
|
||||
// Terminal stop disconnects immediately but waits for the reserved handoff to settle.
|
||||
assert!(
|
||||
timeout(Duration::from_millis(100), &mut stopped)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
// An interrupt must still reach the submission dispatcher while stop is pending.
|
||||
test.codex.submit(Op::Interrupt).await?;
|
||||
timeout(Duration::from_secs(10), stopped).await???;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::RealtimeConversationClosed(_))
|
||||
})
|
||||
.await;
|
||||
assert!(response_mock.requests().is_empty());
|
||||
test.thread_store
|
||||
.flush_thread(test.session_configured.thread_id)
|
||||
.await?;
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
assert!(
|
||||
!history
|
||||
.iter()
|
||||
.filter_map(RolloutItem::realtime_item)
|
||||
.any(|item| matches!(
|
||||
item.content,
|
||||
codex_protocol::realtime::RealtimeItemContent::TurnInputAccepted { .. }
|
||||
)),
|
||||
"a hook-blocked prompt must not become recoverable accepted input"
|
||||
);
|
||||
assert!(history.iter().any(|item| matches!(item,
|
||||
RolloutItem::RealtimeItem(codex_protocol::realtime::RealtimeItem {
|
||||
content: codex_protocol::realtime::RealtimeItemContent::SessionInputSaved { reason: codex_protocol::realtime::SessionInputReason::SessionEnd, input, .. }, ..
|
||||
}) if input.contains("user: text from realtime")
|
||||
)), "rejected handoff speech remains available for closure carryover");
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::TurnComplete(_))
|
||||
})
|
||||
.await;
|
||||
|
||||
test.thread_store
|
||||
.flush_thread(test.session_configured.thread_id)
|
||||
.await?;
|
||||
@@ -5060,7 +5342,46 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
}]
|
||||
);
|
||||
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
let receipt = history
|
||||
.iter()
|
||||
.filter_map(RolloutItem::realtime_item)
|
||||
.map(std::borrow::Cow::into_owned)
|
||||
.find_map(|item| match item.content {
|
||||
codex_protocol::realtime::RealtimeItemContent::TurnInputAccepted {
|
||||
source_event_ids,
|
||||
input,
|
||||
input_item_id,
|
||||
..
|
||||
} => Some((source_event_ids, input, input_item_id)),
|
||||
_ => None,
|
||||
})
|
||||
.expect("accepted handoff is durable");
|
||||
assert_eq!(receipt.0.len(), 1);
|
||||
assert!(history.iter().any(|item| matches!(item,
|
||||
RolloutItem::RealtimeItem(item) if item.id == receipt.0[0]
|
||||
&& matches!(&item.content, codex_protocol::realtime::RealtimeItemContent::Frame { channels } if channels.voice_transcript.text == "text from realtime")
|
||||
)));
|
||||
assert!(history.iter().any(|item| matches!(item,
|
||||
RolloutItem::ResponseItem(item) if item.id().is_some_and(|id| id.as_str() == receipt.2)
|
||||
&& item.metadata.as_ref().is_some_and(|metadata| metadata.realtime_handoff.is_some())
|
||||
)));
|
||||
assert!(
|
||||
!history.iter().any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::RealtimeItem(codex_protocol::realtime::RealtimeItem {
|
||||
content: codex_protocol::realtime::RealtimeItemContent::TurnInputAccepted { .. },
|
||||
..
|
||||
})
|
||||
)),
|
||||
"accepted input must not be persisted again as a standalone receipt"
|
||||
);
|
||||
let request = response_mock.single_request();
|
||||
assert!(request.message_input_texts("user").contains(&receipt.1));
|
||||
let turn_metadata: Value = serde_json::from_str(
|
||||
request
|
||||
.header("x-codex-turn-metadata")
|
||||
@@ -5073,6 +5394,189 @@ async fn inbound_handoff_request_starts_turn_and_promotes_its_artifact() -> Resu
|
||||
== "<realtime_delegation>\n <input>text from realtime</input>\n <transcript_delta>user: text from realtime</transcript_delta>\n</realtime_delegation>"));
|
||||
|
||||
realtime_server.shutdown().await;
|
||||
Ok(response_mock.requests())
|
||||
}
|
||||
|
||||
/// Simulate a stop after ordinary admission persisted the canonical input but
|
||||
/// before sampling. Loading the thread alone does not run inference.
|
||||
#[test_case(false; "local_rollout")]
|
||||
#[test_case(true; "hosted_clock")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn explicit_recovery_dispatches_the_committed_handoff_on_its_receiving_turn(
|
||||
hosted_clock: bool,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let server = responses::start_mock_server().await;
|
||||
let model = responses::mount_sse_once(&server, responses::sse_completed("recovered")).await;
|
||||
let mut builder = test_codex().with_history_mode(ThreadHistoryMode::Paginated);
|
||||
let hosted_store = Arc::new(realtime_history_store::HostedClockStore::default());
|
||||
let voice_server = if hosted_clock {
|
||||
let voice = start_websocket_server(vec![vec![vec![]], vec![vec![]]]).await;
|
||||
let url = voice.uri().to_string();
|
||||
builder = builder
|
||||
.with_thread_store(hosted_store.clone())
|
||||
.with_config(move |config| {
|
||||
config.realtime.version = RealtimeWsVersion::V2;
|
||||
config.experimental_realtime_ws_base_url = Some(url);
|
||||
config.experimental_realtime_ws_startup_context = Some(String::new());
|
||||
});
|
||||
Some(voice)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let test = builder.build_with_auto_env(&server).await?;
|
||||
let thread_id = test.session_configured.thread_id;
|
||||
let turn_id = "receiving-turn";
|
||||
let accepted = "<realtime_delegation>\n <input>recover this</input>\n</realtime_delegation>";
|
||||
let receipt_id = uuid::Uuid::now_v7();
|
||||
let mut input: ResponseItem = serde_json::from_value(json!({
|
||||
"type": "message",
|
||||
"id": codex_protocol::ResponseItemId::for_admitted_user_input(receipt_id),
|
||||
"role": "user",
|
||||
"content": [{"type": "input_text", "text": accepted}],
|
||||
}))?;
|
||||
input.set_turn_id_if_missing(turn_id);
|
||||
test.thread_store
|
||||
.append_items(codex_thread_store::AppendThreadItemsParams {
|
||||
thread_id,
|
||||
items: vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(
|
||||
codex_protocol::protocol::TurnStartedEvent {
|
||||
turn_attribution: None,
|
||||
turn_id: turn_id.to_string(),
|
||||
root_turn_id: Some(turn_id.to_string()),
|
||||
trace_id: None,
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
},
|
||||
)),
|
||||
RolloutItem::ResponseItem(ResponseItemEnvelope {
|
||||
item: input,
|
||||
metadata: Some(CodexHarnessMetadata {
|
||||
realtime_handoff: Some(Box::new(RealtimeHandoffMetadata {
|
||||
event_id: receipt_id.to_string(),
|
||||
realtime_session_id: "voice".to_string(),
|
||||
observed_at_ms: 1_000,
|
||||
handoff_id: "handoff".to_string(),
|
||||
mode: codex_protocol::realtime::RealtimeHandoffMode::Start,
|
||||
source_event_ids: Vec::new(),
|
||||
})),
|
||||
..Default::default()
|
||||
}),
|
||||
}),
|
||||
],
|
||||
})
|
||||
.await?;
|
||||
test.thread_store.flush_thread(thread_id).await?;
|
||||
let path = test.codex.rollout_path();
|
||||
test.codex.shutdown_and_wait().await?;
|
||||
test.thread_manager.remove_thread(&thread_id).await;
|
||||
let context = test
|
||||
.thread_store
|
||||
.load_latest_model_context(codex_thread_store::LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: false,
|
||||
})
|
||||
.await?;
|
||||
let resumed = test
|
||||
.thread_manager
|
||||
.resume_thread_with_history(
|
||||
test.config.clone(),
|
||||
InitialHistory::Resumed(codex_history::ResumedHistory {
|
||||
conversation_id: thread_id,
|
||||
history: Arc::new(context.items),
|
||||
history_revision: context.revision,
|
||||
rollout_path: path,
|
||||
}),
|
||||
auth_manager_from_auth(CodexAuth::from_api_key("dummy")),
|
||||
/*parent_trace*/ None,
|
||||
ClientMcpExtensions::default(),
|
||||
)
|
||||
.await?
|
||||
.thread;
|
||||
assert!(model.requests().is_empty());
|
||||
|
||||
let recovery = resumed
|
||||
.recover_turn_if_idle(codex_core::RecoverTurnRequest {
|
||||
turn_id: turn_id.into(),
|
||||
thread_settings: Default::default(),
|
||||
trace: None,
|
||||
cyber_access_program: None,
|
||||
prompt_cache_ttl: None,
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(
|
||||
recovery,
|
||||
codex_core::StartIfIdleSubmission::Started {
|
||||
turn_id: turn_id.into(),
|
||||
root_turn_id: turn_id.into(),
|
||||
}
|
||||
);
|
||||
wait_for_event(
|
||||
&resumed,
|
||||
|event| matches!(event, EventMsg::TurnComplete(event) if event.turn_id == turn_id),
|
||||
)
|
||||
.await;
|
||||
let messages = model.single_request().message_input_texts("user");
|
||||
assert_eq!(
|
||||
messages
|
||||
.iter()
|
||||
.filter(|text| text.as_str() == accepted)
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
if voice_server.is_some() {
|
||||
assert_eq!(hosted_store.reads(), (0, 0));
|
||||
for call_id in ["first-call", "second-call"] {
|
||||
resumed
|
||||
.submit(Op::RealtimeConversationStart(ConversationStartParams {
|
||||
client_managed_handoffs: false,
|
||||
delegation_ack_filler: None,
|
||||
flush_transcript_tail_on_session_end: false,
|
||||
codex_responses_as_items: false,
|
||||
codex_response_item_prefix: None,
|
||||
codex_response_handoff_mode:
|
||||
codex_protocol::protocol::CodexResponseHandoffMode::Thinking,
|
||||
backend_reasoning_status: false,
|
||||
codex_response_handoff_channel_prefixes: None,
|
||||
model: None,
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
include_startup_context: true,
|
||||
initial_items: Vec::new(),
|
||||
realtime_start_instructions: None,
|
||||
realtime_end_instructions: None,
|
||||
prompt: None,
|
||||
realtime_session_id: Some(call_id.to_string()),
|
||||
voice_session_id: None,
|
||||
transport: None,
|
||||
version: None,
|
||||
voice: None,
|
||||
}))
|
||||
.await?;
|
||||
let observed_at_ms = wait_for_event_match(&resumed, |msg| match msg {
|
||||
EventMsg::RealtimeConversationRealtime(RealtimeConversationRealtimeEvent {
|
||||
payload: RealtimeEvent::HistoryItemCompleted(item),
|
||||
}) if item.realtime_session_id == call_id
|
||||
&& matches!(
|
||||
item.content,
|
||||
codex_protocol::realtime::RealtimeItemContent::RealtimeSessionStarted
|
||||
) =>
|
||||
{
|
||||
Some(item.observed_at_ms)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(observed_at_ms, Some(realtime_history_store::FRAME_FLOOR_MS));
|
||||
resumed.submit(Op::RealtimeConversationClose).await?;
|
||||
wait_for_event(&resumed, |msg| {
|
||||
matches!(msg, EventMsg::RealtimeConversationClosed(_))
|
||||
})
|
||||
.await;
|
||||
}
|
||||
assert_eq!(hosted_store.reads(), (1, 1));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5373,13 +5877,19 @@ async fn conversation_close_routes_only_remaining_transcript_tail_once() -> Resu
|
||||
close_after_requests: false,
|
||||
}])
|
||||
.await;
|
||||
let mut builder = test_codex().with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
}
|
||||
});
|
||||
let mut builder = test_codex()
|
||||
.with_history_mode(ThreadHistoryMode::Paginated)
|
||||
.with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
}
|
||||
});
|
||||
let test = builder.build(&api_server).await?;
|
||||
|
||||
test.codex
|
||||
@@ -5424,21 +5934,23 @@ async fn conversation_close_routes_only_remaining_transcript_tail_once() -> Resu
|
||||
.await;
|
||||
assert_eq!(closed.reason.as_deref(), Some("requested"));
|
||||
|
||||
let history = test.codex.load_history(/*include_archived*/ false).await?;
|
||||
let tails = history.items.iter().filter(|item| {
|
||||
matches!(item, RolloutItem::ResponseItem(ResponseItemEnvelope { item: ResponseItem::Message { role, content, .. }, .. })
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
let tails = history.iter().filter(|item| matches!(item,
|
||||
RolloutItem::ResponseItem(ResponseItemEnvelope { item: ResponseItem::Message { role, content, .. }, .. })
|
||||
if role == "user" && content.iter().any(|item| matches!(item,
|
||||
ContentItem::InputText { text } if text.contains("<source>transcript_tail_flush</source>")
|
||||
&& text.contains("assistant: remaining answer\nuser: remaining question"))))
|
||||
}).count();
|
||||
assert_eq!(tails, 1);
|
||||
ContentItem::InputText { text } if text.contains("<source>transcript_tail_flush</source>") && text.contains("assistant: remaining answer\nuser: remaining question")))
|
||||
)).count();
|
||||
assert_eq!(
|
||||
tails, 1,
|
||||
"protocol V1 saves the tail through legacy history"
|
||||
);
|
||||
assert_eq!(response_mock.requests().len(), 1);
|
||||
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
matches!(event, EventMsg::RealtimeConversationClosed(_))
|
||||
})
|
||||
.await;
|
||||
test.submit_text_turn("continue in text").await?;
|
||||
|
||||
let requests = response_mock.requests();
|
||||
@@ -5868,13 +6380,16 @@ async fn inbound_handoff_request_does_not_block_realtime_event_forwarding() -> R
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(false, false; "without_tail")]
|
||||
#[test_case(true, false; "with_tail")]
|
||||
#[test_case(true, true; "interrupt_after_close")]
|
||||
#[test_case(false, false, ThreadHistoryMode::Legacy; "without_tail")]
|
||||
#[test_case(true, false, ThreadHistoryMode::Legacy; "with_tail")]
|
||||
#[test_case(true, true, ThreadHistoryMode::Legacy; "interrupt_after_close")]
|
||||
#[test_case(false, false, ThreadHistoryMode::Paginated; "v1_steer")]
|
||||
#[test_case(true, false, ThreadHistoryMode::Paginated; "v1_active_tail")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn inbound_handoff_request_updates_realtime_state_during_active_turn(
|
||||
flush_transcript_tail_on_session_end: bool,
|
||||
interrupt: bool,
|
||||
history_mode: ThreadHistoryMode,
|
||||
) -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
@@ -5952,13 +6467,20 @@ async fn inbound_handoff_request_updates_realtime_state_during_active_turn(
|
||||
}])
|
||||
.await;
|
||||
|
||||
let mut builder = test_codex().with_model("gpt-5.4").with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
}
|
||||
});
|
||||
let mut builder = test_codex()
|
||||
.with_history_mode(history_mode)
|
||||
.with_model("gpt-5.4")
|
||||
.with_config({
|
||||
let realtime_base_url = realtime_server.uri().to_string();
|
||||
move |config| {
|
||||
config
|
||||
.features
|
||||
.enable(Feature::RealtimeFramesLocal)
|
||||
.expect("enable local realtime frames");
|
||||
config.experimental_realtime_ws_base_url = Some(realtime_base_url);
|
||||
config.realtime.version = RealtimeWsVersion::V1;
|
||||
}
|
||||
});
|
||||
let test = builder.build_with_streaming_server(&api_server).await?;
|
||||
|
||||
let started = test
|
||||
@@ -6050,6 +6572,21 @@ async fn inbound_handoff_request_updates_realtime_state_during_active_turn(
|
||||
.await
|
||||
.context("steered request did not start")?;
|
||||
|
||||
if history_mode == ThreadHistoryMode::Paginated {
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
assert!(history.iter().filter_map(RolloutItem::realtime_item).any(|item| matches!(
|
||||
&item.content,
|
||||
codex_protocol::realtime::RealtimeItemContent::TurnInputAccepted {
|
||||
turn_id: receiving_turn, mode: codex_protocol::realtime::RealtimeHandoffMode::Steer,
|
||||
source_event_ids, input, ..
|
||||
} if receiving_turn == &turn_id && source_event_ids.len() == 1 && input.contains("steer via realtime")
|
||||
)), "the steering receipt must be durable before the second model request");
|
||||
}
|
||||
|
||||
// Closed and the persisted tail must not wait for the in-flight model response.
|
||||
test.codex.submit(Op::RealtimeConversationClose).await?;
|
||||
let closed = wait_for_event_match(&test.codex, |event| match event {
|
||||
@@ -6059,13 +6596,26 @@ async fn inbound_handoff_request_updates_realtime_state_during_active_turn(
|
||||
.await;
|
||||
assert_eq!(closed.reason.as_deref(), Some("requested"));
|
||||
if flush_transcript_tail_on_session_end {
|
||||
let history = test.codex.load_history(/*include_archived*/ false).await?;
|
||||
assert!(history.items.iter().any(|item| {
|
||||
matches!(item, RolloutItem::ResponseItem(ResponseItemEnvelope {
|
||||
let (history, _, parse_errors) = codex_rollout::RolloutRecorder::load_rollout_items(
|
||||
&test.codex.rollout_path().expect("local rollout path"),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(parse_errors, 0);
|
||||
let ordinary_tails = history
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
matches!(item, RolloutItem::ResponseItem(ResponseItemEnvelope {
|
||||
item: ResponseItem::Message { role, content, .. }, ..
|
||||
}) if role == "user" && content.iter().any(|item| matches!(item,
|
||||
ContentItem::InputText { text } if text.contains("user: final transcript tail"))))
|
||||
}));
|
||||
})
|
||||
.count();
|
||||
let saved_tails = history.iter().filter(|item| {
|
||||
matches!(item, RolloutItem::RealtimeItem(codex_protocol::realtime::RealtimeItem {
|
||||
content: codex_protocol::realtime::RealtimeItemContent::SessionInputSaved { reason: codex_protocol::realtime::SessionInputReason::SessionEnd, input, .. }, ..
|
||||
}) if input.contains("user: final transcript tail"))
|
||||
}).count();
|
||||
assert_eq!((ordinary_tails, saved_tails), (1, 0));
|
||||
}
|
||||
if interrupt {
|
||||
test.codex.submit(Op::Interrupt).await?;
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
//! Hosted realtime test store with a durable clock floor and optional seal failures.
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::realtime::RealtimeItem;
|
||||
use codex_protocol::realtime::RealtimeItemContent;
|
||||
use codex_thread_store::AppendThreadItemsParams;
|
||||
use codex_thread_store::ArchiveThreadParams;
|
||||
use codex_thread_store::CreateThreadParams;
|
||||
use codex_thread_store::DeleteThreadParams;
|
||||
use codex_thread_store::InMemoryThreadStore;
|
||||
use codex_thread_store::ListThreadsParams;
|
||||
use codex_thread_store::LoadThreadHistoryParams;
|
||||
use codex_thread_store::PersistContext;
|
||||
use codex_thread_store::ReadThreadByRolloutPathParams;
|
||||
use codex_thread_store::ReadThreadParams;
|
||||
use codex_thread_store::ResumeThreadParams;
|
||||
use codex_thread_store::StoredModelContext;
|
||||
use codex_thread_store::StoredThread;
|
||||
use codex_thread_store::StoredThreadHistory;
|
||||
use codex_thread_store::ThreadPage;
|
||||
use codex_thread_store::ThreadStore;
|
||||
use codex_thread_store::ThreadStoreError;
|
||||
use codex_thread_store::ThreadStoreFuture;
|
||||
use codex_thread_store::UpdateThreadMetadataParams;
|
||||
use std::any::Any;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
pub(super) const FRAME_FLOOR_MS: i64 = 4_102_444_800_000;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(in crate::suite) struct HostedClockStore {
|
||||
inner: InMemoryThreadStore,
|
||||
enrollment_reads: AtomicUsize,
|
||||
floor_reads: AtomicUsize,
|
||||
fail_close: bool,
|
||||
close_attempts: AtomicUsize,
|
||||
fail_after_input_commit: AtomicBool,
|
||||
input_attempts: AtomicUsize,
|
||||
sealed_inputs: Mutex<HashSet<String>>,
|
||||
block_first_frame: AtomicBool,
|
||||
frame_started: Notify,
|
||||
frame_release: Notify,
|
||||
}
|
||||
|
||||
impl HostedClockStore {
|
||||
pub(in crate::suite) fn blocking_frame() -> Self {
|
||||
Self {
|
||||
block_first_frame: AtomicBool::new(true),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::suite) async fn wait_for_blocked_frame(&self) {
|
||||
self.frame_started.notified().await;
|
||||
}
|
||||
|
||||
pub(in crate::suite) fn release_frame(&self) {
|
||||
self.frame_release.notify_one();
|
||||
}
|
||||
|
||||
pub(in crate::suite) fn failing_close() -> Self {
|
||||
Self {
|
||||
fail_close: true,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::suite) fn close_attempts(&self) -> usize {
|
||||
self.close_attempts.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(in crate::suite) fn failing_after_input_commit() -> Self {
|
||||
Self {
|
||||
fail_after_input_commit: AtomicBool::new(true),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::suite) fn input_attempts(&self) -> usize {
|
||||
self.input_attempts.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(super) fn reads(&self) -> (usize, usize) {
|
||||
(
|
||||
self.enrollment_reads.load(Ordering::Relaxed),
|
||||
self.floor_reads.load(Ordering::Relaxed),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! delegate_store_methods {
|
||||
($(fn $name:ident($param:ident: $params:ty) -> $result:ty;)*) => {
|
||||
$(fn $name(&self, $param: $params) -> ThreadStoreFuture<'_, $result> {
|
||||
self.inner.$name($param)
|
||||
})*
|
||||
};
|
||||
}
|
||||
|
||||
impl ThreadStore for HostedClockStore {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn realtime_frames_enabled(&self, _: ThreadId) -> ThreadStoreFuture<'_, bool> {
|
||||
self.enrollment_reads.fetch_add(1, Ordering::Relaxed);
|
||||
Box::pin(async { Ok(true) })
|
||||
}
|
||||
|
||||
fn realtime_frame_clock_floor(&self, _: ThreadId) -> ThreadStoreFuture<'_, Option<i64>> {
|
||||
self.floor_reads.fetch_add(1, Ordering::Relaxed);
|
||||
Box::pin(async { Ok(Some(FRAME_FLOOR_MS)) })
|
||||
}
|
||||
|
||||
fn seal_realtime_items(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
items: Vec<RealtimeItem>,
|
||||
) -> ThreadStoreFuture<'_, ()> {
|
||||
Box::pin(async move {
|
||||
self.append_items(AppendThreadItemsParams {
|
||||
thread_id,
|
||||
items: items.into_iter().map(RolloutItem::RealtimeItem).collect(),
|
||||
})
|
||||
.await
|
||||
})
|
||||
}
|
||||
|
||||
fn append_items(&self, params: AppendThreadItemsParams) -> ThreadStoreFuture<'_, ()> {
|
||||
if params.items.iter().any(|item| {
|
||||
matches!(item, RolloutItem::RealtimeItem(item) if matches!(
|
||||
item.content, RealtimeItemContent::RealtimeSessionClosed { .. }
|
||||
))
|
||||
}) {
|
||||
self.close_attempts.fetch_add(1, Ordering::Relaxed);
|
||||
if self.fail_close {
|
||||
return Box::pin(async {
|
||||
Err(ThreadStoreError::OutcomeUnknown {
|
||||
message: "injected close failure".to_owned(),
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Box::pin(async move {
|
||||
if params.items.iter().any(|item| {
|
||||
matches!(item, RolloutItem::RealtimeItem(item) if matches!(
|
||||
item.content, RealtimeItemContent::Frame { .. }
|
||||
))
|
||||
}) && self.block_first_frame.swap(false, Ordering::Relaxed)
|
||||
{
|
||||
self.frame_started.notify_one();
|
||||
self.frame_release.notified().await;
|
||||
}
|
||||
self.inner.append_items(params).await
|
||||
})
|
||||
}
|
||||
|
||||
fn load_realtime_session(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
session_id: String,
|
||||
) -> ThreadStoreFuture<'_, Option<Vec<RealtimeItem>>> {
|
||||
Box::pin(async move {
|
||||
let context = self
|
||||
.inner
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: true,
|
||||
})
|
||||
.await?;
|
||||
let items: Vec<_> = context
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|item| item.realtime_item().map(std::borrow::Cow::into_owned))
|
||||
.filter(|item| item.realtime_session_id == session_id)
|
||||
.collect();
|
||||
Ok(items
|
||||
.iter()
|
||||
.any(|item| matches!(item.content, RealtimeItemContent::RealtimeSessionStarted))
|
||||
.then_some(items))
|
||||
})
|
||||
}
|
||||
|
||||
fn load_realtime_session_head(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
) -> ThreadStoreFuture<'_, Option<String>> {
|
||||
Box::pin(async move {
|
||||
let context = self
|
||||
.inner
|
||||
.load_latest_model_context(LoadThreadHistoryParams {
|
||||
thread_id,
|
||||
include_archived: true,
|
||||
})
|
||||
.await?;
|
||||
Ok(context
|
||||
.items
|
||||
.iter()
|
||||
.rev()
|
||||
.filter_map(RolloutItem::realtime_item)
|
||||
.find_map(|item| {
|
||||
matches!(item.content, RealtimeItemContent::RealtimeSessionStarted)
|
||||
.then(|| item.realtime_session_id.clone())
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
fn persist_thread(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
context: PersistContext,
|
||||
) -> ThreadStoreFuture<'_, ()> {
|
||||
self.inner.persist_thread(thread_id, context)
|
||||
}
|
||||
|
||||
fn seal_realtime_input(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
frames: Vec<RealtimeItem>,
|
||||
input: ResponseItemEnvelope,
|
||||
) -> ThreadStoreFuture<'_, ()> {
|
||||
self.input_attempts.fetch_add(1, Ordering::Relaxed);
|
||||
Box::pin(async move {
|
||||
let id = input.item.id().expect("accepted input ID").to_string();
|
||||
// This fixture retries seals serially; do not hold its bookkeeping lock across storage I/O.
|
||||
if self.sealed_inputs.lock().await.contains(&id) {
|
||||
return Ok(());
|
||||
}
|
||||
let mut items = frames
|
||||
.into_iter()
|
||||
.map(RolloutItem::RealtimeItem)
|
||||
.collect::<Vec<_>>();
|
||||
items.push(RolloutItem::ResponseItem(input));
|
||||
self.inner
|
||||
.append_items(AppendThreadItemsParams { thread_id, items })
|
||||
.await?;
|
||||
self.sealed_inputs.lock().await.insert(id);
|
||||
if self.fail_after_input_commit.swap(false, Ordering::Relaxed) {
|
||||
return Err(ThreadStoreError::OutcomeUnknown {
|
||||
message: "injected error after input commit".to_owned(),
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
delegate_store_methods! {
|
||||
fn read_thread(params: ReadThreadParams) -> StoredThread;
|
||||
fn resume_thread(params: ResumeThreadParams) -> Arc<Vec<RolloutItem>>;
|
||||
fn create_thread(params: CreateThreadParams) -> ();
|
||||
fn flush_thread(thread_id: ThreadId) -> ();
|
||||
fn shutdown_thread(thread_id: ThreadId) -> ();
|
||||
fn discard_thread(thread_id: ThreadId) -> ();
|
||||
fn load_history(params: LoadThreadHistoryParams) -> StoredThreadHistory;
|
||||
fn load_latest_model_context(params: LoadThreadHistoryParams) -> StoredModelContext;
|
||||
fn read_thread_by_rollout_path(params: ReadThreadByRolloutPathParams) -> StoredThread;
|
||||
fn list_threads(params: ListThreadsParams) -> ThreadPage;
|
||||
fn update_thread_metadata(params: UpdateThreadMetadataParams) -> Option<StoredThread>;
|
||||
fn archive_thread(params: ArchiveThreadParams) -> ();
|
||||
fn unarchive_thread(params: ArchiveThreadParams) -> StoredThread;
|
||||
fn delete_thread(params: DeleteThreadParams) -> ();
|
||||
}
|
||||
}
|
||||
@@ -4971,6 +4971,24 @@ async fn unshared_apps_catalog_across_turns() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn realtime_handoff_preserves_accepted_context() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
let requests = super::realtime_conversation::realtime_handoff_history_scenario(
|
||||
/*block_prompt*/ false,
|
||||
)
|
||||
.await?;
|
||||
insta::assert_snapshot!(
|
||||
"realtime_turn_input_accepted_context",
|
||||
context_snapshot::format_request_history_snapshot(
|
||||
"A realtime handoff consumes the exact sealed transcript referenced by its durable acceptance.",
|
||||
&requests,
|
||||
&ContextSnapshotOptions::default().rewrite_known_segments(),
|
||||
)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn catalog_plugin_guidance_follows_model_and_survives_resume() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
---
|
||||
source: core/tests/suite/scenarios.rs
|
||||
assertion_line: 4337
|
||||
expression: "context_snapshot::format_request_history_snapshot(\"A realtime handoff consumes the exact sealed transcript referenced by its durable acceptance.\",\n&requests, &ContextSnapshotOptions::default().rewrite_known_segments(),)"
|
||||
---
|
||||
Scenario: A realtime handoff consumes the exact sealed transcript referenced by its durable acceptance.
|
||||
|
||||
## Window 1
|
||||
-- request 1 (turn) --
|
||||
00:message/developer:
|
||||
<MODEL_INSTRUCTIONS>
|
||||
01:message/developer[3]:
|
||||
[01] <realtime_conversation>
|
||||
Realtime conversation started.
|
||||
|
||||
You are operating as a backend executor behind an intermediary. The user does not talk to you directly. ...ediary and may be summarized before the user sees it. [hash=5114d16b52865327]
|
||||
|
||||
When invoked, you receive the latest conversation transcript and any relevant mode or metadata. The inte...void verbose responses that add user-visible latency. [hash=e229c6c9120dff28]
|
||||
|
||||
When user text is routed from realtime, treat it as a transcript. It may be unpunctuated or contain recognition errors.
|
||||
|
||||
- Keep responses concise and action-oriented. Your updates should help the intermediary respond to the user.
|
||||
</realtime_conversation>
|
||||
[02] <PERMISSIONS_INSTRUCTIONS>
|
||||
[03] <tools>
|
||||
Deferred tool namespaces:
|
||||
- multi_agent_v1: Tools for spawning and managing sub-agents.
|
||||
</tools>
|
||||
02:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
03:message/user:
|
||||
<realtime_delegation>
|
||||
<input>text from realtime</input>
|
||||
<transcript_delta>user: text from realtime</transcript_delta>
|
||||
</realtime_delegation>
|
||||
Reference in New Issue
Block a user