Skip to content

fix(discord): bound realtime exact speech retention - #119250

Merged
vincentkoc merged 4 commits into
mainfrom
fix/discord-realtime-exact-speech-bound-20260804
Aug 4, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
fix/discord-realtime-exact-speech-bound-20260804

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Related: #116201

What Problem This Solves

Fixes an issue where Discord realtime voice sessions could retain unbounded completed speech while provider readiness, an active response, or playback prevented delivery. A stalled session could grow memory indefinitely and later emit a large stale backlog.

Why This Change Was Made

DiscordRealtimeVoiceSession now owns a fixed exact-speech budget of 32 messages and 32 KiB measured as UTF-8 bytes. The first overflow is terminal for only that guild session: it clears session-owned speech and playback state, reports one terminal error, and ignores late provider or player events.

The manager's canonical entry.stop() path removes the exact current session and destroys its connection idempotently. This stays Discord-local because the shared talkback queue owns pending questions, not completed speech or Discord playback lifecycle.

Maintainer decision: preserve completed speech exactly while the session remains healthy; do not silently evict, replace, or coalesce it. If the bounded retention contract is exceeded, close only the affected session and leave sibling guild sessions usable.

No provider, config, environment-variable, protocol, public SDK, or docs surface changes.

User Impact

Discord realtime voice can no longer retain an unbounded completed-speech backlog. When the safety bound is exceeded, the affected voice session stops once instead of risking continued memory growth or later speaking stale responses. Other guild voice sessions continue normally.

Evidence

The literal overflow cannot be induced through the current live Discord driver without adding a private playback-stall control and a second driver. The proof is therefore intentionally split: deterministic manager E2E owns the overflow and sibling-isolation invariant; live Discord owns transport regression; live OpenAI owns provider/WebRTC regression. This keeps the PR narrow and avoids a new test-only runtime surface.

Scope: production +40/-0; tests +93/-8; three files.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S maintainer Maintainer-authored PR labels Aug 4, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 4, 2026, 10:21 AM ET / 14:21 UTC.

ClawSweeper review

What this changes

The PR bounds retained completed speech in Discord realtime voice sessions and stops only the overflowing guild session.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open: its Discord-local lifecycle design is sound, but the advertised 32 KiB safety bound counts UTF-16 code units rather than bytes, so multibyte speech can exceed it substantially.

Priority: P1
Reviewed head: 193317fd68c9d3d84854733815b5656a7a97acac
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The lifecycle approach is focused and well-covered, but the byte-accounting defect blocks merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body additionally reports deterministic and live validation on the final head.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body additionally reports deterministic and live validation on the final head.
Evidence reviewed 5 items Current-main defect: Current main appends completed exact speech whenever the bridge is unavailable, an exact response is active, or playback is active, without a message or size bound.
Bound uses the wrong unit: The PR calls the limit 32 KiB but sums string.length; non-ASCII text can fit the code-unit threshold while exceeding the stated byte budget.
Regression coverage is ASCII-only: The new character-budget case uses repeated ASCII, so it cannot detect the multibyte size-accounting gap.
Findings 1 actionable finding [P2] Measure retained speech in bytes, not UTF-16 code units
Security None None.

How this fits together

Discord realtime voice keeps completed model speech until its provider bridge and Discord playback can deliver it. The Discord voice manager owns each guild connection and removes a stopped session from the guild-session map.

flowchart TD
A[Provider or agent speech] --> B[Discord realtime session]
B --> C[Retained exact speech]
C --> D{Within message and byte budget?}
D -->|Yes| E[Provider bridge and playback]
D -->|No| F[Guild session teardown]
F --> G[Connection and session cleanup]
Loading

Decision needed

Question Recommendation
Should a completed-speech overflow preserve exact speech by terminating only the affected guild voice session, rather than dropping or coalescing completed speech? Keep guild-local terminal stop: Preserve completed speech exactly while healthy, then stop only the overflowing guild session when its fixed retention budget is exceeded.

Why: The linked umbrella issue carries a product-decision signal, and this PR makes a user-visible availability tradeoff when the fixed retention limit is exceeded.

Before merge

  • Measure retained speech in bytes, not UTF-16 code units (P2) - This path advertises a 32 KiB safety cap but sums string.length; a multibyte response can pass this check while retaining far more than 32 KiB. Count queued and active text in bytes and add a Unicode overflow case. This concern was visible at the prior reviewed head; git diff confirms this file is unchanged since that review.
  • Resolve merge risk (P1) - The claimed 32 KiB cap is not enforced for multibyte speech, leaving a stalled session able to retain materially more text than the safety contract permits.
  • Resolve merge risk (P1) - An overflow deliberately disconnects the affected guild voice session, so an owner should confirm that terminal behavior remains the intended operator experience.

Findings

  • [P2] Measure retained speech in bytes, not UTF-16 code units — extensions/discord/src/voice/realtime.ts:1002-1007
Agent review details

Security

None.

PR surface

Source +37, Tests +83. Total +120 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 37 0 +37
Tests 1 91 8 +83
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 128 8 +120

Review metrics

Metric Value Why it matters
Production versus test delta production +37/-0; tests +91/-8 The production growth establishes a bounded session-lifecycle owner; the added tests exercise overflow and guild isolation but miss multibyte accounting.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #116201
Summary: This PR is a candidate repair for the linked issue's completed-speech retention branch.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair byte accounting before merge (recommended)
    Measure queued and active speech with one byte metric, update the diagnostic units, and prove multibyte overflow still isolates the affected guild.
  2. Adopt a different overflow policy
    Pause this branch if maintainers prefer dropping or coalescing completed speech over terminating the overflowing guild session.

Technical review

Best possible solution:

Use one byte-based accounting rule for queued and active exact speech, add a multibyte overflow regression, and retain the guild-local terminal teardown policy once confirmed.

Do we have a high-confidence way to reproduce the issue?

Yes in source: current main unconditionally appends completed speech to the retained queue under blocked delivery conditions. The proposed deterministic overflow tests describe the path, but this read-only review did not execute them.

Is this the best way to solve the issue?

No; the session and manager are the right owners, but the implementation must count bytes rather than UTF-16 code units to satisfy its stated 32 KiB bound.

Full review comments:

  • [P2] Measure retained speech in bytes, not UTF-16 code units — extensions/discord/src/voice/realtime.ts:1002-1007
    This path advertises a 32 KiB safety cap but sums string.length; a multibyte response can pass this check while retaining far more than 32 KiB. Count queued and active text in bytes and add a Unicode overflow case. This concern was visible at the prior reviewed head; git diff confirms this file is unchanged since that review.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 52954a1fa8f4.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body additionally reports deterministic and live validation on the final head.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: Unbounded retained speech affects active Discord realtime voice sessions and can cause continuing memory growth and stale playback.
  • merge-risk: 🚨 availability: The new safety path intentionally disconnects a live guild voice session when its retention budget is exceeded.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body additionally reports deterministic and live validation on the final head.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Authored the prior merged exact-speech continuity repair and the current proposed fix. (role: recent exact-speech contributor; confidence: high; commits: 5b7fcce1bb35, 193317fd68c9; files: extensions/discord/src/voice/realtime.ts, extensions/discord/src/voice/manager.e2e.test.ts)
  • Peter Steinberger: Authored the shared realtime voice session-harness refactor underlying this session lifecycle. (role: shared realtime-session refactor author; confidence: high; commits: 2c43e867870d; files: extensions/discord/src/voice/realtime.ts, extensions/discord/src/voice/manager.ts)
  • Wei Songqu: Authored the prior Discord voice connection-isolation repair adjacent to the manager teardown path. (role: connection-isolation contributor; confidence: medium; commits: 46d8e9650346; files: extensions/discord/src/voice/manager.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Count retained completed speech in bytes and add a multibyte overflow regression.
  • After updating the head, obtain one exact-head review and confirm the per-guild terminal-stop policy.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-04T14:03:53.588Z sha 47f8c4f :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 4, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 4, 2026 14:25
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

The byte-accounting finding is fixed at c238564d2707be5527e83b112025443401e7e2fa: retained and incoming exact speech now use UTF-8 byte counts, and the regression uses 32 KiB of multibyte speech so the former code-unit check would fail.

Exact-head proof: 194/194 Discord voice manager tests passed locally and on Blacksmith Testbox: https://github.com/openclaw/openclaw/actions/runs/30919138499

Maintainer decision remains explicit: preserve completed speech while healthy; overflow terminally closes only the affected guild session, with sibling-session continuity covered deterministically.

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

Final exact-head ClawSweeper disposition:

  • The only actionable finding was the closing relation. The PR now uses Related: #116201, so the broader realtime voice retention umbrella remains open.
  • The terminal policy is explicitly accepted: preserve completed speech while healthy, then close only the overflowing guild session rather than silently evicting or coalescing speech.
  • Exact head c238564d2707be5527e83b112025443401e7e2fa has green hosted CI, 194/194 manager tests locally and on Blacksmith Testbox, and a clean 0.99-confidence fix-commit autoreview.

The exact review artifact was produced by https://github.com/openclaw/clawsweeper/actions/runs/30919600251; its direct publication step failed after generation, but the artifact confirms the UTF-8 fix and identifies no remaining code finding.

@vincentkoc
vincentkoc merged commit 9d6d9af into main Aug 4, 2026
128 checks passed
@vincentkoc
vincentkoc deleted the fix/discord-realtime-exact-speech-bound-20260804 branch August 4, 2026 14:56
@vincentkoc vincentkoc added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 4, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
* commit 'ca41781ed5fae6f4505e1e166ccb4216dfb3accb':
  fix(discord): count retained speech bytes
  test(discord): isolate exact speech overflow
  test(discord): cover exact speech overflow
  fix(discord): bound realtime exact speech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant