Repository navigation
refactor(realtime): share audio duration calculation - #125612
Conversation
Fix xAI barge-in truncation that reported 3760 ms after only 3700 ms of decoded audio. Share exact audio-duration math across OpenAI, xAI, and Google while keeping provider-specific rounding at each caller.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 1:11 AM ET / 05:11 UTC. ClawSweeper reviewWhat this changesThis PR clamps xAI realtime interruption truncation to decoded audio actually produced and shares byte-to-duration arithmetic across xAI, OpenAI, and Google voice providers. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this maintainer-authored PR open for normal exact-head CI and maintainer handling. Source review found no correctness finding: it records the produced-audio fact at the xAI owner and preserves each provider’s existing rounding policy. Priority: P2 Review scores
Verification
How this fits togetherRealtime voice providers stream assistant audio through a relay and truncate provider history when a caller interrupts playback. The shared private Plugin SDK runtime helper converts decoded audio bytes to duration while each provider retains its own interruption and rounding rules. flowchart LR
Audio[Decoded provider audio] --> Format[Negotiated audio format]
Format --> Duration[Shared duration helper]
Audio --> Duration
Duration --> XAI[xAI interruption clamp]
Duration --> OpenAI[OpenAI interruption clamp]
Duration --> Google[Google silence accounting]
XAI --> Truncate[Provider history truncation]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +11, Tests +38. Total +49 across 8 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the xAI item record at its audio producer and the generic duration calculation in the existing private runtime seam, then validate the external protocol references when network access is available before merge. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main uses elapsed relay time alone, while the focused regression fixtures make the relay clock exceed 3700 ms of decoded G.711 or PCM16 audio. Is this the best way to solve the issue? Yes. Recording decoded-byte duration at the xAI audio producer and sharing only stateless duration math is the narrow owner-boundary repair; OpenAI and Google retain their different rounding semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e6a427c493da. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready verification for exact head
Maintainer decisions:
Known proof gap: the exact head was not redeployed for another full Twilio phone call. The provider contracts were exercised live, and the Twilio clock-overrun shape plus both xAI interruption modes have deterministic owner-boundary coverage. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
|
@clawsweeper re-review |
|
🦞🧹 Reason: re-review requires an open issue or PR. |
|
@clawsweeper re-review |
Fix xAI barge-in truncation that reported 3760 ms after only 3700 ms of decoded audio. Share exact audio-duration math across OpenAI, xAI, and Google while keeping provider-specific rounding at each caller.
Historical context: #79980, reported by @rparikh1019.
What Problem This Solves
Fixes an issue where xAI realtime voice users interrupting assistant audio could send an
audio_end_mslater than the audio the provider had actually produced. In the captured regression, both manual G.711 interruption and server-VAD PCM16 interruption reported 3760 ms even though only 3700 ms of decoded audio existed. That can make provider conversation history retain an invalid playback boundary.Why This Change Was Made
The xAI owner now tracks the active assistant item as its item ID, decoded byte count, and relay start timestamp. Manual and server-VAD interruption clamp the truncation point to the smaller of produced audio duration and elapsed relay playback, while xAI lifecycle, playback-mark, cancellation, and error semantics remain local to that provider.
The exact byte/format duration primitive now lives beside
RealtimeVoiceAudioFormatand is exported through the existingopenclaw/plugin-sdk/realtime-voiceseam. It returns fractional milliseconds without rounding. OpenAI and xAI apply caller-ownedMath.floortruncation for provider-safe upper bounds; Google applies caller-ownedMath.roundfor silence accumulation. This public helper pays rent immediately across three current providers and removes duplicated codec arithmetic without adding a new SDK subpath.External contract checks support this boundary: xAI and OpenAI define
audio_end_msas milliseconds actually played and acceptconversation.item.truncate; output deltas carry base64 codec bytes, while completion events carry no duration. Google uses the same byte/format duration primitive for input-silence accounting but retains server-owned interruption behavior.This does not change voice-call disconnect grace, generalize provider interruption state, or move Google/GPT-Live interruption ownership into the shared helper.
Provenance: the xAI clock-only truncation was introduced/carried by #106267 (
6c5084f1adb39088c19788b8fbe200b9c3c382d9), authored and merged by @steipete on 2026-07-13 with Vitor Cepeda Lopes as co-author. The equivalent OpenAI invariant was repaired in #125502; this change reuses that invariant and removes duplicated duration math. Current PR author: @steipete.Production LOC: +57/-46 (net +11). Tests: +47/-9 (net +38). Roughly +4 production lines are the xAI owner repair; the remaining growth establishes and adopts the shared three-consumer SDK contract. No generated tracked file or changelog changed.
User Impact
xAI realtime voice interruptions now truncate provider history only to audio that could actually have played, avoiding the 3700/3760 mismatch. OpenAI retains its existing safe truncation behavior, and Google retains its existing silence and interruption behavior while all three providers share one exact duration calculation.
Evidence
origin/main, the same seven-file suite passed 245 tests; one routed test was added by intervening main history.node scripts/check-changed.mjs: passed for core, coreTests, extensions, and extensionTests.pnpm plugin-sdk:surface:check: passed; 146 public Plugin SDK subpaths verified.pnpm build: passed; 146 Plugin SDK subpaths verified and no ineffective dynamic imports reported. Only existing dependency EVAL warnings appeared.git diff --checkpassed before publication;git diff --check origin/main...HEADpassed after rebase.conversation.item.truncated(2/2 passed). Temporary files were removed and no secret was printed.7afa5a8be9dae380dd6149eb164436179487f5c8.AI-assisted: yes. The author reviewed the implementation, understands the provider ownership boundaries, and verified the change with deterministic and authenticated live evidence.