Repository navigation
fix(openai): prevent realtime barge-in truncation errors - #125502
Conversation
Clamp OpenAI Realtime barge-in truncation to the audio duration produced for each assistant item. This prevents interruption failures observed live when 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 10:17 PM ET / August 18, 2026, 02:17 UTC. ClawSweeper reviewWhat this changesThe PR tracks decoded assistant audio per OpenAI Realtime item, clamps barge-in truncation to that duration, and passes the browser sideband’s negotiated PCM16 format into the bridge. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessNo blocking correctness findings. This maintainer-owned PR repairs a current-main OpenAI Realtime truncation defect and addresses the prior sideband PCM finding; it should remain open for maintainer approval after exact-head checks complete. Priority: P1 Review scores
Verification
How this fits togetherOpenAI Realtime voice bridges receive decoded provider audio while call and browser transports report playback time. On barge-in, the bridge cancels output and sends OpenAI a truncation boundary that must not exceed produced audio. flowchart LR
A[OpenAI audio deltas] --> B[OpenAI voice bridge]
C[Playback timestamp] --> B
D[Negotiated audio format] --> B
B --> E[Produced audio duration]
E --> F[Barge-in handling]
F --> G[OpenAI truncation event]
Decision needed
Why: The patch is technically sound and has reported live provider proof, but the protected maintainer workflow requires a human merge decision. Before merge
Agent review detailsSecurityNone. PR surfaceSource +8, Tests +59. Total +67 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the format-aware, provider-owned duration boundary after exact-head CI is green; no smaller downstream transport change can know the decoded OpenAI item duration. Do we have a high-confidence way to reproduce the issue? Yes—the current-main clock-only calculation and the focused overrun cases give a high-confidence reproduction path; the PR also reports a successful live provider probe. Is this the best way to solve the issue? Yes—the provider bridge owns both decoded item bytes and negotiated format, while transport timestamps alone cannot establish the safe OpenAI truncation limit. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 448eb4165312. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
The browser sideband negotiated PCM16, but its bridge defaulted to G.711 for duration accounting. Propagate the negotiated format so truncation uses the actual PCM duration and closes ClawSweeper's in-scope finding.
|
Land-ready verification for exact head
Production LOC is +35/-27 (net +8); tests are +86/-27 (net +59). I accept the small production increase because the OpenAI provider must retain one canonical per-item decoded-duration fact, and the browser sideband must pass its already-negotiated format into that owner. Transport timestamps or marks alone cannot establish the provider-safe upper bound. Known proof gap: the exact patched commit was not redeployed for another full clawstudio-to-Twilio phone call. The changed provider contract was exercised against the live OpenAI Realtime service, while Twilio timestamp/mark handling and the browser PCM factory path have focused deterministic coverage. |
|
Merged via squash.
|
…5502) * fix(openai): clamp realtime barge-in truncation Clamp OpenAI Realtime barge-in truncation to the audio duration produced for each assistant item. This prevents interruption failures observed live when 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp. * fix(openai): propagate PCM sideband audio format The browser sideband negotiated PCM16, but its bridge defaulted to G.711 for duration accounting. Propagate the negotiated format so truncation uses the actual PCM duration and closes ClawSweeper's in-scope finding.
What Problem This Solves
Fixes an issue where users interrupting OpenAI Realtime voice playback could hit a provider rejection instead of cleanly truncating the assistant response. A live clawstudio observation on 2026-08-17 showed OpenAI reject
conversation.item.truncatewithAudio content of 3700ms is already shorter than 3760ms.The voice-call transport forwards Twilio's inbound
media.timestamp, which is a stream-relative presentation clock. The OpenAI bridge had used elapsed clock time directly asaudio_end_ms: 29,600 decoded G.711 µ-law bytes represented 3,700 ms of audio while the transport clock had advanced to 3,760 ms. OpenAI requiresaudio_end_msnot to exceed the item's actual audio duration.Why This Change Was Made
The OpenAI provider now owns and tracks decoded audio bytes per assistant item, then clamps the transport-clock estimate to the duration actually produced for negotiated G.711 µ-law and PCM16 audio. The GA browser sideband also passes its negotiated 24 kHz PCM16 format into the bridge so the same owner-boundary accounting applies there. Current transport marks establish outstanding playback but do not carry byte-position duration, so widening voice-call would duplicate provider-specific state.
Voice-call transport and disconnect-grace behavior are unchanged. xAI behavior and files are explicitly out of scope.
Production LOC: +35/-27 (net +8). Tests: +86/-27 (net +59). The production growth records the provider-owned duration fact and propagates the already-negotiated PCM16 format required by the external truncation contract.
Provenance: the elapsed-clock approach originated in direct commit
a23ab9b906dc6a4f6b24bb3f681f395eb792dbcdon 2026-04-04 by Peter Steinberger (no associated PR found), and was carried forward by Peter Steinberger's PR #122414, merged by Peter Steinberger on 2026-08-12. This PR is authored bysteipete.External contracts:
AI-assisted: yes. The code and behavior were reviewed and verified by the maintainer.
User Impact
Interrupting an OpenAI Realtime voice response now sends a truncation position that cannot run past the audio OpenAI actually produced, preventing the provider error and allowing barge-in to complete normally for G.711 µ-law and PCM16 sessions.
Evidence
conversation.item.truncatebecause 3,700 ms of decoded audio was paired with a 3,760 ms transport-clock timestamp.node scripts/run-vitest.mjs extensions/openai/realtime-voice-bridge-events.test.tsfailed exactly 2 cases (received 3760 vs expected 3700); 15 passed.extensions/openai/realtime-voice-bridge-events.test.tsandextensions/openai/realtime-voice-response-control.test.ts.3760instead of3700while 17 other tests passed. The fixture produces 177,600 PCM16 bytes (3,700 ms) with a 3,760 ms playback clock.extensionsandextensionTestsgates.git diff --checkpassed before commit and again after rebasing onto currentorigin/main.conversation.item.truncated; 1 live test passed. The temporary probe was deleted and no secret was printed.