Repository navigation
fix(voice): prevent choppy audio in realtime calls - #125620
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 2:52 AM ET / 06:52 UTC. ClawSweeper reviewWhat this changesThis PR revises realtime voice resampling, telephony pacing and playback acknowledgements, TTS format handling, and audio backpressure to reduce choppy or corrupted call audio. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer-owned merge review. The earlier containerized μ-law finding is fixed on the current head, but protocol-contract verification and a maintainer proof decision remain before merge. Priority: P1 Review scores
Verification
How this fits togetherRealtime audio passes through OpenAI voice bridges or telephony TTS, then through resampling, buffering, pacing, and Twilio media streams. These paths determine whether callers hear continuous audio and whether playback ends correctly on completion or interruption. flowchart LR
A[Provider audio] --> B[Resampling and buffering]
B --> C[Realtime voice bridge]
C --> D[Telephony pacer]
D --> E[Twilio media stream]
E --> F[Playback mark acknowledgement]
Decision needed
Why: The changed tail-flush boundary depends on an external protocol implementation, and the repository policy requires direct source inspection before a merge verdict; only a maintainer can provide or waive that evidence. Before merge
Agent review detailsSecurityNone. PR surfaceSource +457, Tests +591, Other 0. Total +1048 across 24 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Verify the Codex completion-event contract and obtain a redacted production-gateway call trace confirming smooth audio, completion marks, and barge-in before landing the coherent owner-boundary repair. Do we have a high-confidence way to reproduce the issue? No live reproduction was available in this read-only checkout, but the changed source and focused regressions define concrete pacing, resampling, format, and completion paths. Is this the best way to solve the issue? Unclear: the owner-boundary repair is coherent in the inspected source and resolves the prior finding, but the required external protocol and real-call confirmation are still missing. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5dcc91df998f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Handled all substantive ClawSweeper moves through head
Final exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32108370728. Final ClawSweeper review reports no actionable findings on |
|
Merged via squash.
|
* fix(voice-call): pace realtime audio from stream clock * fix(voice): preserve resampler state across audio chunks * fix(voice-call): honor telephony TTS audio formats * fix(voice-call): await acknowledged stream playback * fix(voice): bound realtime input audio backlog * chore(voice-call): shrink assertion baseline and localize tts format error * test(voice-call): split playback-mark coverage into its own suite * test(voice-call): drop helper left unused by suite split * test(openai): scope queued audio copy assertion * fix(openai): flush realtime resampler at response end * fix(voice-call): reject containerized mulaw TTS
What Problem This Solves
Fixes an issue where users on realtime voice calls would hear choppy, gapped, or corrupted audio even when upstream synthesis was continuous. This was observed on the production gateway on 2026-08-17/18. Review traced the symptom to five independent mechanisms in the outbound pacer, per-chunk resampling, telephony TTS format handling, Twilio playback completion, and bounded audio buffering.
Why This Change Was Made
The voice pipeline now keeps one continuous timing and DSP state across each stream: outbound telephony frames are paced from a monotonic stream clock with a 160 ms lead window and overdue catch-up; sample-rate conversion preserves sinc taps and fractional phase across chunks; telephony TTS honors raw mu-law versus PCM/container format contracts; Twilio playback waits for acknowledged completion marks and aborts cleanly on interruption or partial send failure; and input/reconnect queues remain bounded while retaining the freshest audio.
Codex OSS uses WebRTC for realtime calls (
codex-rs/codex-api/src/endpoint/realtime_call.rs), where RTP transport owns media pacing. Twilio Media Streams expose audio over WebSocket instead, so OpenClaw must pace those frames in userspace.User Impact
Realtime and streaming voice calls sound audibly smoother, without timer-lateness gaps or resampling seams. Azure raw 8 kHz mu-law and Gradium
ulaw_8000telephony TTS are passed through correctly instead of being double-companded into garbage audio. Barge-in and playback completion are deterministic, and prolonged backpressure no longer permits unbounded stale audio growth.No configuration changes are required.
Evidence
extensions/voice-call/src/webhook/realtime-audio-pacer.tsuses an absolute monotonic stream clock, a 160 ms lead window, and send-all-overdue catch-up instead of chaining relative 20 ms timers for each 160-byte frame. Fake-timer regressions cover timer lateness and catch-up inextensions/voice-call/src/webhook/realtime-audio-pacer.test.ts.src/talk/audio-codec.tsaddscreateStreamingPcmResampler, preserving sinc filter history and fractional phase across chunks. It is wired into the 48 kHz/24 kHz werift peer path inextensions/openai/realtime-quicksilver-peer.runtime.tsand both 8 kHz/24 kHz telephony directions inextensions/openai/realtime-quicksilver-bridge.ts.src/talk/audio-codec.test.tsproves chunked output is equivalent to one-shot resampling without seam discontinuities.extensions/voice-call/src/telephony-tts.tspasses through Azureraw-8khz-8bit-mono-mulawand Gradiumulaw_8000, converts PCM, and rejects container formats with a typed error.extensions/voice-call/src/telephony-tts.test.tscovers all three outcomes.extensions/voice-call/src/media-stream.tsandextensions/voice-call/src/providers/twilio.tswait for Twilio's echoed completion mark, fall back after audio duration plus 2 seconds, ignore stale marks after clear, race barge-in against in-flight synthesis, and abort/clear partial chunk-send failures. Coverage includesextensions/voice-call/src/media-stream.playback-marks.test.tsandextensions/voice-call/src/providers/twilio.test.ts.extensions/openai/realtime-voice-bridge.tsdrops input frames above a 1 MiB WebSocketbufferedAmountthreshold with rate-limited warnings, whilesrc/talk/realtime-session-lifecycle.tsapplies drop-oldest overflow semantics so reconnect queues retain the freshest audio.Local proof is green: 180+ focused tests across 12 files, including DSP-equivalence and fake-timer pacing regressions that fail on the pre-fix implementations by construction;
pnpm build;pnpm plugin-sdk:surface:check; andpnpm check:changed. Codex autoreview completed clean on the full branch; the later three commits only clean up repository gates (baseline shrink/un-export, playback-mark suite split for the max-lines cap, and unused-helper removal).Live-call listening proof is infeasible from this development checkout because the Twilio credentials and tailnet access live on the operator's production gateway. The deterministic fake-timer, DSP-equivalence, format-contract, playback-mark, abort, backpressure, and overflow regressions cover the changed mechanisms; they are not presented as live proof.
AI-assisted: yes. The branch was reviewed and validated as described above.