Skip to content

fix(discord): release voice recordings when speaking-end events are lost - #192932

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-discord-voice-capture-retention-20260919
Nov 4, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-discord-voice-capture-retention-20260919

Conversation

@steipete

@steipete steipete commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Discord voice captures retaining partial recordings indefinitely when a speaker stops or leaves without a speaking-end event, or a receive stream emits an error without closing.

User Impact

Idle speaker subscriptions now close and release their recording buffers. Valid buffered speech still reaches transcription; failed input discards its incomplete segment. Continuous capture remains registered. Existing upload/backlog limits, configured silence grace, and the SDK's 100 ms silence window are preserved, including very short grace settings. No new configuration or migration is required.

Why This Change Was Made

Speaking-start previously canceled the only finalization timer, while packet activity never armed a replacement. The Discord audio worker now refreshes an owned inactivity deadline on packets, restores it on speaking-start, and closes failed input. Physical subscription close remains the owner of reservation removal, independently of delayed decoding or recording work. This removes five production TypeScript lines and keeps runtime changes in the Discord plugin. The only external edit is the explicitly approved test-budget bookkeeping.

Evidence

The missing-end, user-leave, and error-without-close regressions fail on the parent and pass with the fix. A committed synthetic workload exercises four concurrent speakers, real Opus decoding, recording, WAV writes, and cleanup. It also fails on the parent. Existing long-utterance upload limits, receive backlog, and recording backlog tests remain enforced; the backlog fixture now sends ongoing packets instead of simulating speech with a stale speaking flag.

Five interleaved fresh-capture samples per version, plus A/A controls; 4,900 20 ms frames per speaker (98 seconds each). Compiler/import setup excluded; SDK transport and transcription are synthetic. This is owner-boundary proof, not live Discord E2E or whole-Gateway database/workspace scaling.

Metric Parent median / p95 Fix median / p95
Feed wall time 338.696 / 339.992 ms 353.010 / 362.329 ms
Feed CPU 616.638 / 620.894 ms 644.468 / 660.740 ms
Decoded PCM allocation 75,264,000 bytes 75,264,000 bytes
Idle reservations / retained recording PCM 4 / 75,264,000 bytes 0 / 0 bytes

A/A controls: feed wall 336.629→339.504 ms; CPU 634.834→620.894 ms; identical byte counts. Feed overhead is 4.23% wall / 4.51% CPU, below the predeclared 20% investigation threshold. The fixed path settles four WAVs in a median 104.012 ms after the deadline; the parent performs no settlement. Allocation counts decoded PCM, not total V8 allocation or RSS. A separate CPU/heap-profiled run verifies the actual retained chunk arrays reach zero.

Reproduce: OPENCLAW_VOICE_CAPTURE_MEASURE=1 node scripts/run-vitest.mjs extensions/discord/src/voice/voice-capture-retention.perf.test.ts --maxWorkers=1.

Focused receive, lifecycle, capture-state, transport and retention suites: 70 tests passed (40.12 s runner including compilation; owner tests under one second per file). The final profiled finalization/retention/backlog run passed 10 tests in 19.31 s including instrumented imports. Regression growth covers missing lifecycle events, preservation of short configured grace, and a rerunnable full-size buffer-retention workload.

Test audit and budget

The test-audit and simplification passes retain 187 net test lines. Missing speaking-end, member leave, and error without close exercise distinct lifecycle inputs through the manager/worker/receive/recording boundary. The short-grace case protects the existing configuration contract. The four-speaker real-codec workload supplies the requested reproducible retention measurement; existing backlog and upload-limit tests retain long-utterance and reconnect coverage. No duplicate test or test-only production seam was found.

Maintainer approval covers an exact scalar test-budget raise, including inherited debt. After rebasing on f9a25d7c2caccd7fbcd14ab899543d453b54ebb5, the required increase is 188, not 194: this PR adds 187 lines; #192478 (8e1cc8c4) added seven unallocated lines, and #192777 (f9a25d7c2cac) subsequently deleted six. The final count and effective ceiling are both 6,470,174, with zero spare allowance. The scalar changes from 6,326,285 to 6,326,473; existing per-change allocations are untouched. This is the approved maintainer exception, not a waiver of a failing gate.

Resource acceptance

The perf lead explicitly accepts 4.5% CPU overhead against 75.3 MB → 0 of unbounded voice-recording retention observed in production (heap pair on r276). The synthetic owner fixture reproduces the retention and proves cleanup; it does not claim a post-deployment production measurement. No production host was accessed or changed.

Final validation

Rebased onto f9a25d7c2caccd7fbcd14ab899543d453b54ebb5; 13 focused tests pass across finalization, retention, recording backlog, and upload limits. Codex autoreview of the complete rebased candidate is scoped-clean through P2. The exact test-line ratchet passes with zero slack. pnpm check:changed --base f9a25d7c2caccd7fbcd14ab899543d453b54ebb5 completed: every guard, format, extension/test typecheck, extension/script lint, and architecture check passed except the dead-export scan. Its four findings exactly match the independent parent reproduction below. Exact-head CI 41887692472 passed for f34b090c0980716088fe34a6b4c32112fffbff40. Normal auto-merge landed this reviewed head as 58293c5bbec258e97d7a3d461a1209466c4eeda1; no admin bypass or CI rerun was used.

The earlier unused PostgreSQL export was fixed upstream by #192929 (cfb85a1d15e8). The untouched Skill Workshop export, SKILL_WORKSHOP_PLUGIN_ID, originated in #192766 (3e114e23c33c); production and full-tree scans reproduce it on the exact parent f9a25d7c2cac. The full-tree scan additionally finds SETUP_PROOF_ACCOUNT_ID, SETUP_PROOF_LOGIN, and SETUP_PROOF_REPOSITORY in the worker-setup fixture, introduced by #192538 (0b9f3ab3aec3). These are newly observed main regressions, not noise, and remain follow-ups outside this plugin fix's scope. The script export scan passes.

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: M labels Nov 4, 2026
@steipete
steipete marked this pull request as ready for review November 4, 2026 18:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T18:31:48.199005Z f34b090 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 4, 2026
Expire packet-inactive captures even without speaking-end, and close failed input. Preserve the SDK silence window, configured grace, physical finalization ownership and existing recording/backlog bounds. Regressions cover missing end, leave, error, short grace and four concurrent partial recordings retaining 75 MB.
Raise the test-line scalar by the exact 188-line deficit: 187 audited regression lines plus one remaining inherited line after main deleted six of the seven uncovered lines from #192478. Maintainer approved the budget exception.
@steipete
steipete force-pushed the steipete/perf-micro-discord-voice-capture-retention-20260919 branch from 21a497b to f34b090 Compare November 4, 2026 18:29
@steipete
steipete enabled auto-merge (squash) November 4, 2026 18:44
@steipete
steipete merged commit 58293c5 into main Nov 4, 2026
111 checks passed
@steipete
steipete deleted the steipete/perf-micro-discord-voice-capture-retention-20260919 branch November 4, 2026 18:45
@steipete

steipete commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 5, 2026
…ost (openclaw#192932)

* fix(discord): release stalled voice capture buffers

Expire packet-inactive captures even without speaking-end, and close failed input. Preserve the SDK silence window, configured grace, physical finalization ownership and existing recording/backlog bounds. Regressions cover missing end, leave, error, short grace and four concurrent partial recordings retaining 75 MB.

* test(discord): allocate audited voice retention coverage

Raise the test-line scalar by the exact 188-line deficit: 187 audited regression lines plus one remaining inherited line after main deleted six of the seven uncovered lines from openclaw#192478. Maintainer approved the budget exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant