Skip to content

fix(discord): OAuth GPT-Live voice can't select the Gateway-relay bridge, and misses auto-join on a disconnected startup - #138441

Closed
almostjulian wants to merge 1 commit into
openclaw:mainfrom
almostjulian:fix/discord-gateway-relay-callback-autojoin
Closed

almostjulian wants to merge 1 commit into
openclaw:mainfrom
almostjulian:fix/discord-gateway-relay-callback-autojoin

Conversation

@almostjulian

Copy link
Copy Markdown

What Problem This Solves

Resolves two problems in Discord realtime voice startup:

  1. Discord voice authenticated via OAuth (ChatGPT/Codex-based GPT-Live) never selects
    the OAuth GPT-Live Gateway-relay bridge. The OpenAI provider only selects that bridge
    when the bridge-creation request declares the gateway-relay surface and supplies a
    participant-aware agent-consult callback; Discord's realtime speaker session supplied
    neither, so it silently fell back to a different path even when the Gateway-relay
    route was the intended one for a Gateway-owned client like Discord.
  2. When the Discord gateway connection starts disconnected, and READY arrives while
    runDiscordGatewayLifecycle is still waiting for it (rather than before lifecycle
    setup began), voice auto-join into an already-occupied configured channel is never
    reconciled. The existing reconciliation only fires on the gatewayReadyAtLifecycleStart
    branch, so a channel occupied at the moment READY lands mid-wait can be missed for the
    rest of that session.

Why This Change Was Made

  • Added DiscordRealtimeConsults.runAgentConsult, the Gateway-relay entry point the
    OpenAI provider calls directly instead of routing through Discord's native realtime
    tool-call protocol. It resolves Discord speaker identity through the existing
    forced-consult coordinator, dedupes concurrent identical prompts to one agent turn,
    and fails closed on abort, on a stale provider epoch (reconnect/continuity reset), or
    on missing speaker context. Wired it, plus the gateway-relay surface, into the
    bridge-creation request built by DiscordRealtimeSpeakerSession, and plumbed the new
    optional runAgentConsult field through RealtimeVoiceBridgeSessionParams in
    src/talk/session-runtime.ts so it reaches the provider.
  • Added the missing post-READY auto-join reconciliation as the mirror of the existing
    gatewayReadyAtLifecycleStart branch: when startup began disconnected, reconcile once
    after waitForGatewayReady resolves instead of only before it. The two branches are
    mutually exclusive (gatewayReadyAtLifecycleStart true vs. false), so this cannot
    double-fire against the existing call.

No config surface, schema, or public API changed.

User Impact

  • Discord voice using OAuth can actually reach the intended OAuth GPT-Live Gateway-relay
    bridge with correct Discord participant identity attached to each consult, instead of
    silently running a different bridge path.
  • An occupied, auto-join-configured voice channel is joined reliably after a cold,
    disconnected gateway startup, not only when Discord happened to already be connected
    before lifecycle setup began.

Evidence

Local proof (fresh clone off current main, pnpm install, no unrelated changes):

  • pnpm tsgo:core and pnpm tsgo:extensions: clean, no errors.
  • pnpm test extensions/discord/src/monitor/provider.lifecycle.test.ts extensions/discord/src/voice/realtime-turns.test.ts extensions/discord/src/voice/realtime-consults.test.ts src/talk/session-runtime.test.ts:
    118/118 passing (5 new tests: the post-READY auto-join reconciliation test, a test
    asserting the provider is asked for the gateway-relay surface and exposes
    runAgentConsult, a duplicate-consult dedup test, and two parametrized fail-closed
    tests for abort / continuity-reset).
  • Confirmed all 5 new tests fail on pre-fix code for the intended reason (git stash
    of only the four production files, tests kept, all 5 fail; restored, all 118 pass
    again) before opening this PR.
  • node_modules/.bin/oxfmt on the touched files: no changes needed.
  • node_modules/.bin/oxlint on the touched files: clean.

I don't currently have a way to live-test the OAuth GPT-Live Gateway-relay path itself
(needs a configured Discord bot + ChatGPT/Codex OAuth voice session), so this PR relies
on the unit/integration proof above plus review of the existing, already-tested
Gateway-relay provider-selection logic this change plugs into
(resolveConfiguredRealtimeVoiceProvider, exercised by
extensions/openai/realtime-voice-provider-routing.test.ts, unchanged here). Happy to
do a live pass if a maintainer can point me at a suitable test setup.

…Y auto-join

The OpenAI provider only selects the OAuth GPT-Live Gateway-relay bridge
when a participant-aware runAgentConsult callback and the gateway-relay
surface are both present on the bridge-creation request. Discord's
realtime speaker session built the request without either, so Discord
voice could never select that bridge path.

- Wire DiscordRealtimeConsults.runAgentConsult (new) into the bridge
  request built by DiscordRealtimeSpeakerSession, alongside the
  gateway-relay surface. The new consult runner resolves Discord speaker
  identity through the existing forced-consult coordinator, dedupes
  concurrent identical prompts, and fails closed on abort, on a stale
  provider epoch (reconnect/continuity reset), or on missing speaker
  context.
- Plumb the optional runAgentConsult field through
  RealtimeVoiceBridgeSessionParams in src/talk/session-runtime.ts so it
  reaches the provider's bridge-creation request.

Separately: runDiscordGatewayLifecycle only reconciled voice auto-join
when Discord's gateway was already READY at lifecycle start. When
startup began disconnected, READY arriving during waitForGatewayReady
was never followed by a reconciliation call, so an occupied configured
voice channel could be missed on a cold, disconnected startup. Added
the matching post-READY reconciliation on the other side of the wait.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UMZAfYFwUJfM8wYnseU4ew
@clawsweeper

clawsweeper Bot commented Sep 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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@almostjulian
almostjulian marked this pull request as ready for review September 4, 2026 17:28
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

The OAuth relay work is superseded by a merged, shipped implementation. The claimed remaining startup gap bypasses existing READY and guild-snapshot listeners in its reproduction, so it does not establish a distinct fix worth retaining.

Root-cause cluster
Relationship: superseded
Canonical: #146289
Summary: The merged GPT Live PR supersedes the relay contribution; older merged startup and occupancy work covers the separately claimed auto-join scenario.

Members:

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

Canonical path: Retain the shipped relay implementation and event-owned auto-join flow; investigate any distinct current-release startup failure through actual READY and guild-snapshot dispatch.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Retain the shipped relay implementation and event-owned auto-join flow; investigate any distinct current-release startup failure through actual READY and guild-snapshot dispatch.

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

No current-main reproduction is established: OAuth relay wiring has shipped, and the startup test bypasses the READY and guild-snapshot listeners that perform reconciliation. No tests were executed during this read-only review.

Is this the best way to solve the issue?

No. The merged relay implementation covers the useful change with stronger lifecycle handling; adding another startup reconciliation duplicates the existing event-owned path without demonstrating its failure.

Security review:

Security review needs attention: The superseded callback does not propagate cancellation to agent execution; no dependency or supply-chain changes were introduced.

  • [medium] Delegation cancellation does not stop admitted agent work — extensions/discord/src/voice/realtime-consults.ts:124
    The callback starts runAgentTurn without its AbortSignal, then races only the returned result against abort. Provider supersession or shutdown can therefore leave agent work executing after the caller has cancelled. The shipped replacement forwards cancellation through this boundary.
    Confidence: 0.98

AGENTS.md: found and applied where relevant.

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta: the branch adds relay selection, a consult callback, callback forwarding, startup reconciliation, and five test cases. Checkout and original head both identify the same reviewed commit. (5cc5f0921605)
  • Verified merged replacement: GitHub confirms fix(discord): support continuous GPT Live conversations #146289 merged on September 12. Its body explicitly connects its OAuth routing work to this PR, documents participant authorization and cancellation proof, and explicitly excludes the separate auto-join proposal. That exclusion was investigated independently rather than treated as completed work. (a0cd0b81391c)
  • Current relay implementation: Current main selects the gateway-relay surface in realtime-speaker-config.ts:73, supplies the consult callback in realtime-speaker-session.ts:269, and forwards it through src/talk/session-runtime.ts:255. The current consult owner consumes speaker context, respects disabled delegation, and forwards cancellation to the agent turn. (extensions/discord/src/voice/realtime-consults.ts:124, 094f165494ce)
  • Startup already has event-owned reconciliation: provider.ts:468–471 registers voice listeners before entering the lifecycle wait. READY and RESUMED invoke autoJoin; an available GUILD_CREATE snapshot invokes reconcileAutoJoinGuild. internal/gateway.ts sets readiness and dispatches the same event to those listeners without an intervening await. (extensions/discord/src/voice/listeners.ts:39, 094f165494ce)
  • Startup history and occupancy coverage: Merged fix(discord): isolate voice connections and close auto-join race #87530 explicitly preserves READY/RESUMED handling for readiness arriving later. Merged feat(discord): auto-join occupied voice rooms #125974 owns occupied-room startup reconciliation. Current and released voice-auto-join.test.ts includes an occupied-room join after the startup guild snapshot arrives; manager.ready-listener.test.ts covers READY and RESUMED dispatch. (extensions/discord/src/voice/voice-auto-join.test.ts:126, ec9c1a13db89)
  • Proposed startup reproduction omits production dispatch: The added test changes gateway.isConnected directly and advances timers. It never dispatches READY through the client or installs the voice listeners, so its pre-fix failure demonstrates the added lifecycle call rather than a failure of the real startup flow. (extensions/discord/src/monitor/provider.lifecycle.test.ts:278, 5cc5f0921605)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Codex review notes: model internal, reasoning medium; reviewed against 094f165494ce.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Sep 23, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @almostjulian for identifying these voice startup paths. I checked both claims independently on current main (24015bf60cbb):

Validation: 49 tests passed across manager.ready-listener, voice-auto-join, realtime-speaker-sessions, and OpenAI realtime-voice-provider-routing (73.2 seconds). No live Discord/OAuth meeting was exercised, and contributor code was not run.

Security: no changes to credential eligibility, participant authorization/cancellation, or configured guild/channel targets and allowlists.

Closing as superseded; the useful relay work is already implemented, with no distinct remaining startup fix established. Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants