Keep only heard assistant speech in history after interruptions #804
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #804"
general
weight: 0.35
jackboyla
Closes #801.
Problem
After a barge-in, the next model request's history did not match what the user heard. On
main:conversation.item.truncatewas a no-op.Resulting behavior
incompleteassistant message. No marker is added to the text; this is the maintainer's "played text only" decision.- If the last segment was still being synthesized, its full duration is estimated from the session's measured speaking rate, or 12 chars/s before one is measured. Unsynthesized words are therefore not kept.
- If no audio was sent, no assistant message is kept.
response.canceland flushes its player): the WebSocket transport estimates playback from send times, assuming real-time playback from the moment each chunk is sent. On server-VAD barge-in andresponse.cancel, the audio not yet played by that estimate is removed from the newest items, the same way WebRTC removes its discarded RTP audio. The estimate assumes the client stops playback at that point.conversation.item.truncatecuts an ended item's history to the transcript heard beforeaudio_end_ms. It is measured against the item's original audio, so it replaces the server's WebSocket estimate instead of compounding it. That includes restoring, in its original place, a reply the estimate removed entirely. An explicitconversation.item.delete, an evicted or compacted turn, or any new item reusing the id prevents the restore, and a late report never edits that new item. That includes replies that completed while their audio was still buffered. An item with no heard audio is removed from model history but, as after a truncation to 0 ms, still exists on the wire.- No
conversation.item.truncatedacknowledgement is sent.conversation.item.retrieve(added in #810) returns a cut item with its heard transcript andincompletestatus, and a removed one asincompletewith an empty transcript (not an error, so these checks don't count in/v1/usageerror metrics).conversation.item.deleteremoves it for good.response.canceloroutput_audio_buffer.cleardiscards queued RTP audio, the discarded duration is removed from the newest items. This matches OpenAI's description of server-side truncation for WebRTC.local/talkclient tracks played bytes per item and sendsconversation.item.truncatewhen it clears interrupted playback. This covers both the in-process path and the echo-cancellation worker path. It then sendsconversation.item.retrieveand redraws the interrupted reply's terminal line with the text the model history kept, marked[interrupted](or prints it on a new line if other output followed).input_audio_buffer.speech_started, so that retrieve sees the cut.msg_id. The Realtime item id stays an alias, because replayed Responses assistant messages are believed to needmsg-prefixed ids. This was not verified against the live API.The mapping is documented in the Realtime README under "Interrupted replies". Each transcript segment is recorded with the audio delivered after it. Fully played segments are kept whole. The segment playing at the cutoff keeps whole words in proportion to its played duration, rounding down.
Diagram
Where the played position comes from and how it becomes the heard text, using the example from the tests: a reply interrupted at 2.60 s keeps "Sure, here are five ways to improve it. First,". (PDF)
<img src="https://gist.githubusercontent.com/andimarafioti/f41191c2d3c5e2e07087a268fd13b447/raw/be111d7772e3901631e995093b34d8385a175805/interrupted-reply-history.png" alt="Handbook-style page: interrupted reply history functional diagram and a reply cut at 2.60 seconds" width="720">
Known limitation: Agents SDK < 0.20 over WebSocket
The server sends a cancelled reply's
response.output_audio.donebeforeinput_audio_buffer.speech_started.@openai/agents-realtimebelow 0.20.0 resets its playback item onoutput_audio.done. So on server-VAD barge-in it sends no truncate and emits noaudio_interrupted. Apps that flush their player on that event keep playing the cancelled reply, while the server's playback estimate cuts its history. Those apps lose some heard speech from history rather than keeping unheard speech.OpenAI does not document the order of these events, so the wire order is unchanged. SDK 0.20.0+ tracks playback past
output_audio.doneand truncates whatever the order (checked in the published packages). Since #810, the demo and CI pin 0.21.0, so this only affects apps on older SDK versions.WebRTC, the browser demo and the packaged client are not affected. The README documents this.
Review
Eleven independent review passes, each a fresh reviewer:
| Pass | Finding | Disposition |
|---|---|---|
| 1 | A reply cancelled mid-synthesis kept its unsynthesized words. | Fixed with the speaking-rate duration estimate. |
| 2 | Responses replay would use
item_ids. | Fixed: generatedmsg_ids, with the Realtime id kept as an alias. || 3 | The README overstated stock-SDK coverage. | Corrected. |
| 4 |
demo/README.mdwas stale. | Fixed. Also documented thatoutput_audio_buffer.clearalone leaves the active reply untouched. || 5 | Approve. | Documented how an unheard item is removed. (Later changed: retrieve now returns it as an empty
incompleteitem instead ofconversation_item_not_found.) || 6 | Approve. | No changes needed. |
| 7 (WebSocket playback estimate) | Stock SDK < 0.20 keeps playing after server-VAD barge-in, so the estimate cuts speech its users heard. | Documented in the README and above. Also added a router-level
speech_startedtest with a realWebSocketTransport. || 8 (maintainer review of
f066e2e2) | A client truncate could not restore a reply the estimate had removed entirely. | Fixed: removed replies remember their position and are restored on a later non-empty truncate; explicit deletes stay final. Regression tests added. || 9 | Restoring after the turn was evicted put the reply at the start of history; a reused id could clash. | Both now skip the restore, with tests. Not fixed: after a
previous_item_idinsert right before the reply, the restored reply lands before the inserted item. || 10 (maintainer review of
60991ef4) | A new assistant message reusing a removed reply's id was overwritten by a late playback report. | Fixed: the restore record is checked before any lookup or edit, so any item holding the id is left untouched. Regression test added. || 11 | A removed reply that opened the conversation could be restored after its turn was evicted or compacted. | Fixed: eviction and compaction drop records for replies whose turn they remove. Tests added. |
Deferred as optional:
response.cancelsent with no active response also applies the WebSocket estimate, so a client that sends it without flushing its player loses heard speech from history.incomplete.conversation.item.deletebehaviour and is unverified against the live API.Validation
-
tests/openai_realtime/test_interrupted_playback_history.py- 4 in
test_audio_client.py- 4 in
test_webrtc.pyc7c3e8d1and pass here.ruff check,ruff format --checkandmypy src/are clean.pytest tests/on the final head: 3695 passed, 10 skipped. The only failures seen were pre-existing flakes, reproduced on unmodifiedmain:- MiniMax
test_stalled_request_is_closed_and_worker_released[session_end], filed as #802.-
test_audio_output_batches_immediately_available_chunks, intermittent under load.test:agents:adapter63/63,test:ui3/3,test:agents:ws2/2,test:agents:webrtc1/1 on@openai/agents0.21.0 (stock SDK transports against the real server).- real-device playback with the echo-cancellation worker
- browser WebRTC jitter-buffer offset
- a live Responses API call with the
msg_ids- LLM reply quality after truncation