Skip to content

refactor(discord): split voice lifecycle ownership - #122479

Merged
steipete merged 12 commits into
mainfrom
steipete/discord-voice-split-0811
Aug 12, 2026
Merged

steipete merged 12 commits into
mainfrom
steipete/discord-voice-split-0811

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Discord voice races where leaving during a pending join could reconnect later, a stopped session could subscribe after authorization, decoded STT work could outlive leave, followed-user state could resurrect an older move, realtime connect could report ready after close, and provider-reset completions could leak into a newer voice generation.

The previous voice implementation also concentrated connection, follow, receive, realtime, playback, turn, and consult ownership in two files over 4,000 lines, making these lifecycle invariants difficult to express and verify.

Why This Change Was Made

The voice subsystem is split by lifecycle owner into runtime, guild session, following, receive, realtime session, playback, turns, and consult modules. One per-guild generation now authorizes connection publication, capture, realtime state, transcripts, and playback; provider continuity retains its own epoch. Playback and exact-speech state are closed unions rather than parallel booleans.

Discord startup keeps its existing outer lazy boundary, while STT/TTS no longer loads realtime provider and consult machinery: voice-session.ts dynamically imports realtime-session.runtime.ts only for agent-proxy and bidi modes. Generic policy text and the exact-speech scraper remain byte-identical and are explicitly marked for a separate owner-reviewed realtime-voice follow-up.

User Impact

Discord voice leave, follow, capture, and realtime operations are last-event-wins. Stale async work can no longer reconnect, subscribe, transcribe, play, publish readiness, or deliver provider completions after its voice generation has closed.

There is no configuration or Plugin SDK change. Existing voice instructions, consult/control tool schemas, transcript-source behavior, and STT/TTS behavior are preserved.

Evidence

Regression provenance and before/after proof:

  • All six new order-sensitive regressions were run against the mechanical split commit and failed for the intended reason: pending leave (leave returned false), late receiver subscription, post-leave STT execution, stale followed-user publication, ready-after-close, and stale provider transcript delivery.
  • The same six tests pass after the lifecycle-authority commit.
  • Exact source comparison against pre-split realtime.ts confirms the assembled instruction builder and consult/control tool assembly are byte-identical.

Validation on head 4119d4a90a416efa0ed2e2d70d62fc4849f88875:

  • Focused lifecycle/follow/receive batch: 3 files, 100 tests passed.
  • Focused playback/turns/consults batch: 3 files, 76 tests passed.
  • Runtime composition E2E: join → audio ingress → agent dispatch → playback → leave passed.
  • Full Discord batch: 220 files, 2,754 tests passed.
  • Extension package boundary compile: 124 plugins passed.
  • node scripts/check-changed.mjs --base <frozen-merge-base>: green, including dead-code scans, production/test typechecks, extension lint, database-first guard, and zero runtime import cycles.
  • pnpm build: green; no [INEFFECTIVE_DYNAMIC_IMPORT] warning.
  • pnpm lint:tmp:export-name-collisions: green.
  • pnpm check:wrapper-shadowing: green.
  • pnpm plugin-sdk:surface:check: green.
  • pnpm lint:plugins:no-extension-test-core-imports: green.
  • pnpm check:max-lines-ratchet: green against the rebased branch base; the three superseded Discord voice entries were removed.
  • Final branch autoreview: clean, no accepted/actionable findings; TruffleHog clean.

Remote-proof note: Blacksmith Testbox was unavailable because the host lacks the blacksmith executable, and direct AWS Crabbox had no configured broker login. Repository policy therefore routed trusted-source proof to the local fallback above. Hosted exact-head PR CI remains the authoritative merge-tree proof.

LOC classification from git diff --numstat (moves are not discounted):

  • Production: +4,760 / -4,040, net +720.
  • Tests and test support: +6,774 / -6,078, net +696, including one new composition E2E and six regressions.
  • Tooling baseline: +0 / -3, net -3.

The positive production delta is the concrete ownership boundary: eight bounded concept modules, their closed lifecycle states, and narrow injected ports replace the two monoliths. No compatibility alias, fallback stack, new config, or new public API remains.

@clawsweeper

clawsweeper Bot commented Aug 12, 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 channel: discord Channel integration: discord size: XL maintainer Maintainer-authored PR labels Aug 12, 2026
@steipete
steipete marked this pull request as ready for review August 12, 2026 06:07
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 2:14 AM ET / 06:14 UTC.

ClawSweeper review

What this changes

The PR splits Discord voice lifecycle behavior into focused session, receive, following, realtime, playback, turn, and consult modules, using a per-guild generation to reject stale async work.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This active maintainer PR replaces current main’s monolithic Discord voice owner with generation-fenced lifecycle owners; no introduced correctness defect was found, but exact-head CI is still running.

Priority: P1
Reviewed head: 4119d4a90a416efa0ed2e2d70d62fc4849f88875

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-boundary repair with targeted order-sensitive coverage; remaining confidence depends on exact-head CI.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records focused lifecycle and composition validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records focused lifecycle and composition validation.
Evidence reviewed 6 items Current-main async race boundary: Current main awaits realtime authorization before subscribing to a receiver, leaving a window for a stopped session to subscribe later.
Generation lifecycle owner: The branch assigns a generation before joining, publishes only a still-current generation, and marks a pending join stopped when leave wins.
Realtime post-connect fence: The branch verifies entry lifecycle, generation, and session identity after realtime connect before marking the session active.
Findings None None.
Security None None.

How this fits together

Discord voice turns gateway voice state and audio into a guild-scoped session, then dispatches agent work and playback. The changed lifecycle layer controls whether delayed joins, receives, follows, transcripts, and realtime callbacks may still publish after a session changes.

flowchart LR
  A[Discord gateway and audio] --> B[Voice runtime]
  B --> C[Guild voice session]
  C --> D[Generation authority]
  D --> E[Receive and realtime work]
  E --> F[Agent dispatch]
  F --> G[Voice playback]
  H[Leave and follow events] --> D
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head Discord/runtime CI is still in progress, so the reported focused and full-suite results are not yet independently confirmed by current PR checks.
  • Resolve merge risk (P1) - Production code is reported as net +720 lines; the lifecycle-owner split should remain only if these closed state boundaries cannot be expressed without recreating the deleted monoliths.
  • Complete next step (P2) - This protected maintainer PR needs routine exact-head CI completion and maintainer merge handling, not a repair job or cleanup close.
Agent review details

Security

None.

PR surface

Source +1791, Tests -375, Other -3. Total +1413 across 37 files.

View PR surface stats
Area Files Added Removed Net
Source 22 5831 4040 +1791
Tests 14 5703 6078 -375
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 3 -3
Total 37 11534 10121 +1413

Review metrics

Metric Value Why it matters
Production versus test delta production +4,760/-4,040 (net +720); tests/support +6,774/-6,078 (net +696) The positive production delta is justified by the stated split into lifecycle owners, but needs the focused race coverage and exact-head CI to support it.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/discord/src/voice/realtime-turns.wake-name-followup.test.ts, persistent cache schema: extensions/discord/src/voice/realtime.wake-name-followup.test.ts, serialized state: extensions/discord/src/voice/session.ts, unknown-data-model-change: extensions/discord/src/voice/session.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Require exact-head lifecycle proof (recommended)
    Merge after the remaining exact-head Discord voice and runtime CI lanes pass for the reviewed head.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require green exact-head Discord voice lifecycle and runtime CI before merge.

Technical review

Best possible solution:

Retain one per-guild generation as the authoritative lifecycle fact, and merge after exact-head checks validate the owner-level regressions without reintroducing downstream stale-work guards.

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

Yes, from source: current main awaits authorization before receiver subscription, and the PR supplies ordered regressions for leave-vs-join, authorization, decode, follow, and realtime connect. The read-only checkout lacks dependencies, so these scenarios were not rerun here.

Is this the best way to solve the issue?

Yes. Recording authority at the per-guild lifecycle owner is more maintainable than adding separate stale-work guards to receive, following, realtime, and playback consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 77d89b2fa843.

Labels

Label changes:

  • add P1: The PR targets active Discord voice races that can act after a user leaves or moves a session.
  • add merge-risk: 🚨 message-delivery: The changed lifecycle authority determines whether transcripts and playback can still publish to a voice session.
  • add merge-risk: 🚨 session-state: The refactor replaces the per-guild session lifecycle owner and its stale-work authorization checks.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records focused lifecycle and composition validation.

Label justifications:

  • P1: The PR targets active Discord voice races that can act after a user leaves or moves a session.
  • merge-risk: 🚨 message-delivery: The changed lifecycle authority determines whether transcripts and playback can still publish to a voice session.
  • merge-risk: 🚨 session-state: The refactor replaces the per-guild session lifecycle owner and its stale-work authorization checks.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records focused lifecycle and composition validation.

Evidence

What I checked:

Likely related people:

  • steipete: The member-authored 12-commit series creates the lifecycle boundary and its follow-up authority checks. (role: recent area contributor area contributor; confidence: high; commits: b66e01799811, f7e457a2537c, 4119d4a90a41; files: extensions/discord/src/voice/voice-runtime.ts, extensions/discord/src/voice/voice-session.ts)

Rank-up moves

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

  • Wait for remaining exact-head Discord voice and runtime checks to finish green.

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.

@steipete
steipete merged commit 90beb63 into main Aug 12, 2026
179 checks passed
@steipete
steipete deleted the steipete/discord-voice-split-0811 branch August 12, 2026 06:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 12, 2026
Move the exact-speech protocol (typed consult-call outcome instead of
string scraping), agent-proxy session instructions, and consult/wake-name/
barge-in policy defaults from the Discord plugin into src/talk, exported
additively via openclaw/plugin-sdk/realtime-voice. Wake-name enablement now
keys on a supportsActivationNameGating provider capability instead of a
hardcoded provider id. Follow-up to the voice split (#122479).
steipete added a commit that referenced this pull request Aug 12, 2026
Move the exact-speech protocol (typed consult-call outcome instead of
string scraping), agent-proxy session instructions, and consult/wake-name/
barge-in policy defaults from the Discord plugin into src/talk, exported
additively via openclaw/plugin-sdk/realtime-voice. Wake-name enablement now
keys on a supportsActivationNameGating provider capability instead of a
hardcoded provider id. Follow-up to the voice split (#122479).
steipete added a commit that referenced this pull request Aug 12, 2026
* refactor(voice): promote realtime voice policy to talk owner

Move the exact-speech protocol (typed consult-call outcome instead of
string scraping), agent-proxy session instructions, and consult/wake-name/
barge-in policy defaults from the Discord plugin into src/talk, exported
additively via openclaw/plugin-sdk/realtime-voice. Wake-name enablement now
keys on a supportsActivationNameGating provider capability instead of a
hardcoded provider id. Follow-up to the voice split (#122479).

* fix(talk): bind exact-speech bypass to retained session state

Per ClawSweeper review on #122668: the protocol marker is untrusted model
tool-call text; only a parsed answer matching a currently retained
exact-speech text may select the privileged replay path. Unretained
marker calls route to a normal consult.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 13, 2026
* refactor(discord): split voice subsystem by lifecycle owner

* fix(discord): make one generation the voice lifecycle authority

* refactor(discord): delete superseded voice plumbing

* test(discord): split voice coverage by lifecycle owner

* chore(lint): ratchet max-lines baseline after voice split

* fix(discord): re-read voice lifecycle after realtime connect

* test(discord): move wake follow-up coverage to turns owner

* refactor(discord): keep realtime lifecycle state private

* refactor(discord): keep voice test harness type private

* refactor(discord): remove split voice test accessors

* test(discord): type split voice fixtures at owners

* test(discord): trim split voice test imports
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 13, 2026
…w#122668)

* refactor(voice): promote realtime voice policy to talk owner

Move the exact-speech protocol (typed consult-call outcome instead of
string scraping), agent-proxy session instructions, and consult/wake-name/
barge-in policy defaults from the Discord plugin into src/talk, exported
additively via openclaw/plugin-sdk/realtime-voice. Wake-name enablement now
keys on a supportsActivationNameGating provider capability instead of a
hardcoded provider id. Follow-up to the voice split (openclaw#122479).

* fix(talk): bind exact-speech bypass to retained session state

Per ClawSweeper review on openclaw#122668: the protocol marker is untrusted model
tool-call text; only a parsed answer matching a currently retained
exact-speech text may select the privileged replay path. Unretained
marker calls route to a normal consult.
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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant