Repository navigation
fix(discord): isolate voice connections and close auto-join race - #87530
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep open: this PR targets a real Discord multi-account voice bug, but the current head is still not merge-ready because account-scoped voice connections are added without making the gateway adapter account-safe, lifecycle-started auto-join remains fire-and-forget during cleanup, and the after-fix proof is not a real multi-account Discord voice run. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes for source-level reproduction: the PR adds per-account @discordjs/voice groups, while the unchanged adapter dispatch still forwards guild voice-state packets without checking the owning bot user id. I did not run a live two-account Discord voice session in this read-only review. Is this the best way to solve the issue? No. Grouping @discordjs/voice connections by account is the right layer for the registry collision, but the best fix must also carry ownership into adapter dispatch and make lifecycle-started auto-join owned through cleanup. Security review: Security review cleared: The diff touches Discord plugin runtime and tests only; I found no concrete secret-handling, dependency source, workflow, package, permission, or supply-chain regression. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 91f5a65df9f8. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08e8c4d4cf
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| const scheduleVoiceAutoJoin = (label: string, delayMs: number) => { | ||
| const startedAt = Date.now(); | ||
| setTimeout(() => { |
There was a problem hiding this comment.
Unref or cancel delayed auto-join timers
When voice is enabled and the Discord monitor exits before this 75s fallback fires (for example an abort/reload or a startup failure after the voice manager is created), the ref'ed timeout keeps Node's event loop alive even though lifecycle cleanup has already torn the manager down (extensions/discord/src/monitor/provider.lifecycle.ts:556 and extensions/discord/src/voice/manager.ts:347). The callback will mostly no-op later, but the process/test can hang until the longest delayed autoJoin fires; store these handles and clear them on cleanup or call unref() for fire-and-forget safety nets.
Useful? React with 👍 / 👎.
|
ClawSweeper PR egg: 🎁 locked until real behavior proof passes. Details
|
Behavior proof & fix summaryFixed in this update (commit Real-world reproductionCherry is the 3rd Discord account; OpenClaw staggers startup by 20s per account. By the time Cherry's provider starts, the Discord READY event has already fired, so The timers work correctly. The issue raised by Codex was about process-exit safety. FixAdded
Note on the Codex "first join succeeds → retry overwrites session" concern: |
2920af3 to
fb6b0ec
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Note on
|
d8559e3 to
f671e90
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f671e90cf4
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void params.voiceManager | ||
| .autoJoin() |
There was a problem hiding this comment.
Await or cancel lifecycle-started auto-join
Fresh evidence after the prior timer comments: this new lifecycle-owned path still starts autoJoin() fire-and-forget, so if the lifecycle is already aborted or fails immediately after this point while autoJoin() is awaiting fetchChannel/entersState, finally calls destroy() without waiting for that join task. DiscordVoiceManager.joinUnlocked only checks this.destroyed after joinVoiceChannel and the Ready wait, so the bot can still join voice during shutdown and remain there until the voice connect timeout; gate this on the abort signal or make the lifecycle await/cancel the auto-join task before destroying the manager.
Useful? React with 👍 / 👎.
f671e90 to
dc20431
Compare
|
ClawSweeper applied the proposed close for this PR.
|
dc20431 to
28f13b9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28f13b990b
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -568,6 +573,7 @@ export class DiscordVoiceManager { | |||
| const joinedConnection = voiceSdk.joinVoiceChannel({ | |||
| channelId, | |||
| guildId, | |||
| group: voiceConnectionGroup, | |||
There was a problem hiding this comment.
Filter adapter voice-state events by bot
Adding the per-account group separates the @discordjs/voice registry, but it does not make the gateway adapter account-safe: dispatchVoiceGatewayEvent still forwards every guild VOICE_STATE_UPDATE to adapter?.onVoiceStateUpdate?.(data) based only on guildId. In a guild where two configured bot accounts join voice, account B can receive account A's voice-state event before its own while joining; @discordjs/voice treats that packet as the connection's own state and can combine A's session/user with B's voice-server update, leaving B stuck before Ready. Please pass/filter the bot user id into the voice adapter before calling onVoiceStateUpdate.
Useful? React with 👍 / 👎.
28f13b9 to
5802e2a
Compare
|
Exact-head land-ready proof for
Known proof gap: this maintainer host has no configured two-account Discord voice guild. Focused tests exercise the exact dependency registry and lifecycle contracts. |
|
Merged via squash.
|
…nclaw#87530) * fix(discord): isolate voice connections by account Co-authored-by: geekhuashan <[email protected]> * chore: defer Discord voice accounts changelog * fix(discord): own auto-join cleanup in lifecycle * test(discord): bind lifecycle voice mocks --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
OpenClaw can run multiple Discord bot accounts in one guild, but
@discordjs/voicestores connections by(group, guildId)and defaults every caller to the samedefaultgroup. One account can therefore reuse or destroy another account's voice connection. Auto-join can also miss startup when the Discord gateway is already READY before the voice listener is registered.Why This Change Was Made
The connection owner now supplies a stable
openclaw:<accountId>group for lookup, join, and cleanup. The gateway lifecycle also checks its initial readiness after taking ownership of voice cleanup. This closes the ordering race directly, keeps failure cleanup symmetric, and removes the earlier 6-, 8-, and 75-second timing workarounds.User Impact
Discord accounts sharing a guild keep independent voice connections. Configured voice auto-join starts whether readiness happened just before listener registration or arrives later through READY/RESUMED. No configuration or command changes are required.
Evidence
@discordjs/voice0.19.2 source inspection confirmed its process-global registry is keyed by guild plus caller-provided group and defaults todefault.5802e2a8b244fa6f932507731767983a741202c5: https://github.com/openclaw/openclaw/actions/runs/28756233240Implementation
Release-note context and contributor credit are preserved here; the thanked changelog bullet is queued with the final batch to avoid active-main ordering races.