Skip to content

fix(discord): prevent voice replies from cutting off during playback - #130346

Merged
steipete merged 2 commits into
mainfrom
codex/discord-voice-playback-drain
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/discord-voice-playback-drain

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Discord voice replies cut off mid-sentence when the realtime provider generates audio faster than Discord plays it. Redacted production diagnostics captured four replies with 6.8–7.2 seconds of generated audio being stopped after only 1.18–1.36 seconds, even with barge-in disabled. Queued answers could also start before previous playback finished, brief provider stalls could stop the player, and STT/TTS responses had a fixed one-minute completion deadline.

Why This Change Was Made

Discord's playback owner now retains a bounded audio queue, respects writable backpressure, and ends the source only after its queued tail drains. Actual player Idle owns normal completion and releases the next exact-speech answer; provider completion and encoder closure do not. This removes the artificial backpressure cancellation state and its cancellation-race handling.

Realtime players tolerate up to two seconds of missing frames, with a three-second playback watchdog margin and progress-aware draining. STT/TTS playback retains its bounded startup timeout but waits for actual completion, while session shutdown force-stops buffered resources and cancels both startup and completion waits. Pipeline failures release queued speech through the same playback owner. No public config keys, dependencies, persistence, or SDK contracts are added.

User Impact

Discord voice replies finish speaking across normal buffering and brief provider gaps, queued answers no longer replace unfinished speech, and long STT/TTS replies can finish without a one-minute cutoff. Intentional interruption and session shutdown still stop audio promptly. Pending realtime audio remains capped at two minutes, with a visible terminal error on genuine overflow.

Evidence

  • Confirmed the reported failure in the running Discord gateway: audioMs=6800 elapsedMs=1230 chunks=17, followed by output-backpressure and forced response cancellation despite barge-in being disabled. Host, account, channel, and transcript details are omitted.
  • Re-ran ten regressions against the original owners. They failed for the expected backpressure, early completion, encoder-error recovery, jitter, fixed-duration playback, and cancellation defects.
  • Added an integration test using the real Discord audio player, resource, Opus encoder, and session harness, without Discord network access. It supplies the observed 17 × 400 ms burst and checks all 340 source packets are consumed before queued speech advances.
  • All 299 Discord voice tests pass, including the real-player integration test, codec checks, and session lifecycle coverage. The final rebuilt voice end-to-end suite also passed all 30 tests.
  • Production and test TypeScript checks pass. Independent Codex autoreview reported no blocking findings.
  • Changed-check guards, formatting, boundary checks, dead-export checks, and both TypeScript checks pass. The final lint rerun passes across every changed Discord file after removing unused bindings left by test extraction.

The production bot runs an immutable remote deployment. This PR does not replace or restart that operator-owned gateway; post-change channel listening remains a deployment verification step. The regression uses the real encoder/player boundary, and the production logs establish that its burst matches the observed failure.

Production code: +125 / −133 (net −8). Tests and test support: +450 / −130 (net +320), including extraction of the existing batch-playback case into its owning suite. Documentation: +6 / −2.

Preserve realtime PCM through normal backpressure and release queued speech only after the Discord player finishes. Tolerate brief provider stalls, remove the STT/TTS completion deadline, and settle playback immediately on terminal session shutdown.
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord size: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete merged commit 1448da3 into main Aug 26, 2026
137 checks passed
@steipete
steipete deleted the codex/discord-voice-playback-drain branch August 26, 2026 20:29
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…penclaw#130346)

* fix(discord): prevent voice replies from cutting off during playback

Preserve realtime PCM through normal backpressure and release queued speech only after the Discord player finishes. Tolerate brief provider stalls, remove the STT/TTS completion deadline, and settle playback immediately on terminal session shutdown.

* test(discord): remove unused playback test bindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord docs Improvements or additions to documentation maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant