Skip to content

fix(xai): report lazy voice bridge connect failure as a terminal error - #123064

Merged
altaywtf merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/xai-voice-bridge-connect-failure
Aug 15, 2026
Merged

altaywtf merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/xai-voice-bridge-connect-failure

Conversation

@wanyongstar

@wanyongstar wanyongstar commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fix(xai): report a lazy realtime voice bridge connect() failure as a terminal error and close the loaded bridge, instead of leaking it silently

What Problem This Solves

The xAI extension lazily loads its realtime voice runtime: createLazyXaiRealtimeVoiceProvider().createBridge(req) returns a wrapper that only imports the real provider and creates the real bridge on first use. Callers rely on req.onClose(outcome) to learn the terminal state of the bridge.

When the loaded bridge's connect() rejects (network failure, auth rejection, WebSocket error), the wrapper's connect promise rejects — but:

  • req.onClose is never called, so the caller (e.g. the talk/voice session layer) never learns the bridge is dead and waits indefinitely for a terminal outcome.
  • The loaded bridge is never closed, leaking its resources (sockets, timers).
  • Input sent after the failed connect is silently accepted into the pending queue even though the generation is already terminal.

The adjacent queued-flush failure path (failure while replaying pending input after a successful connect) already does all of this correctly — emitTerminal(connectGeneration, "error") + closeBridge(loadedBridge) — which is exactly the contract the connect path violates.

代码证据: in extensions/xai/lazy-capability-providers.ts, createLazyXaiRealtimeVoiceBridge's connect():

try {
  await loadedBridge.connect();
} catch (error) {
  if (connectGeneration === generation) {
    acceptsInput = false;
    terminalGeneration = connectGeneration;
    clearPendingInput();
  }
  throw error;   // no req.onClose("error"), no closeBridge(loadedBridge)
}

Trigger condition: any rejection from the real voice bridge's connect().

Root Cause

  • The lazy voice bridge wrapper was introduced by commit e35d22807e5 (2026-08-05, improve(xai): defer optional capability runtimes #119374, "perf(xai): lazy-load optional capability runtimes").
  • Violated invariant: every code path that terminates a bridge generation must report exactly one terminal outcome via req.onClose and release the loaded bridge. The connect-failure path marks the generation terminal internally (terminalGeneration = connectGeneration) without performing the external half of the contract.
  • The inconsistency with the flush-failure path (same function, ~10 lines below) shows the omission was accidental, not a design choice.

Why This Fix

  • Option A: leave reporting to callers — every caller would need to pair a connect() rejection with a synthetic onClose("error"). Rejected: duplicates terminal-state logic per caller and still leaks the loaded bridge.
  • Option B (chosen): mirror the flush-failure path in the connect catch — emitTerminal(connectGeneration, "error"); closeBridge(loadedBridge); throw error;. emitTerminal already dedupes (one terminal outcome per generation) and clears pending input; closeBridge already dedupes via a WeakSet. A late provider-reported onClose("completed") after the failure is ignored, and post-failure sendAudio is dropped by the existing terminal checks.
  • Not chosen: calling req.onClose directly without emitTerminal — would bypass the generation guard and could double-report against a concurrent provider close.

User Impact

  • Affected scenarios: xAI realtime voice (talk mode) sessions where the voice WebSocket connect fails.
  • Before: the session hangs with no terminal outcome; the underlying bridge is leaked; late audio is silently queued.
  • After: the caller receives exactly one onClose("error"), the loaded bridge is closed immediately, and the connect() rejection still propagates.
  • Behavior change: callers now observe a terminal error outcome for failed voice connects. This is strictly better — the previous behavior was an indefinite hang plus a resource leak.

Evidence

Real stack, no mocks of anything under test: the proof drives the real lazy wrapper (extensions/xai/lazy-capability-providers.ts), the real dynamically imported realtime-voice-provider.js, the real XaiRealtimeVoiceBridge, and a real ws client dialing a real closed loopback TCP port — producing a genuine ECONNREFUSED network failure. The only "fake" element is the absence of a listening server, i.e. the failure itself is a real transport-level connect failure.

Before (on main)

$ node node_modules/tsx/dist/cli.mjs proof-xai-connect-real.mjs
[proof] target: real ws dial to closed port 127.0.0.1:50208
[proof] connect() rejected with: connect ECONNREFUSED 127.0.0.1:50208
[proof] req.onClose calls: []
[proof] isConnected() after failure: false
[proof] RESULT: FAIL - req.onClose must be called exactly once with "error", got []

After (with fix, rebased on latest main)

$ node node_modules/tsx/dist/cli.mjs proof-xai-connect-real.mjs
[proof] target: real ws dial to closed port 127.0.0.1:50749
[proof] connect() rejected with: connect ECONNREFUSED 127.0.0.1:50749
[proof] req.onClose calls: ["error"]
[proof] isConnected() after failure: false
[proof] RESULT: PASS - real connect failure emits exactly one terminal onClose("error") and propagates

Same real rejection on both runs; only the fixed wrapper reports the terminal outcome to the caller. Post-failure sendAudio is dropped (isConnected() stays false, pending queue cleared by the terminal path).

What was not tested: a live connection to wss://api.x.ai with real credentials; the failure is exercised at the real transport boundary (TCP refusal) instead, which traverses the identical connect() rejection path in the real bridge.

Tests and Validation

  • npx vitest run extensions/xai/lazy-capability-providers.test.ts — 30/30 passed, including the regression test reports voice connect failure as a terminal error (connect rejection propagates, loaded bridge closed once, onClose called exactly once with "error", late provider close ignored, post-failure sendAudio dropped).
  • npx oxlint --deny=warn on both changed files — 0 warnings, 0 errors.
  • Before/after real-behavior proof logs are embedded above (real transport failure, not a stubbed provider).

@clawsweeper

clawsweeper Bot commented Aug 13, 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 extensions: xai size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 13, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 1:32 PM ET / 17:32 UTC.

ClawSweeper review

What this changes

The PR makes lazy xAI and Google realtime voice bridges emit error and close callbacks, release failed provider bridges, and discard pending input when connection setup rejects.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open: current main still turns lazy xAI and Google connection rejections into internal terminal state without notifying the talk-session owner or releasing the bridge. The branch repairs that owner boundary consistently and preserves the original connection error.

Priority: P1
Reviewed head: b2c75216a28942e3b38be834b2b5ed9af95e008f

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The branch has focused owner-boundary repair, strong lifecycle coverage, and real transport-failure proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR provides before/after real transport-refusal output through the production lazy xAI wrapper and real ws client, showing the new terminal callback.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR provides before/after real transport-refusal output through the production lazy xAI wrapper and real ws client, showing the new terminal callback.
Evidence reviewed 7 items Current xAI failure gap: Current main marks the generation terminal and clears input after a rejected connect, but does not invoke the terminal callback or close the loaded bridge.
Current Google sibling gap: The Google lazy wrapper has the same rejected-connect pattern: it marks provider termination and clears audio without reporting close or releasing the bridge.
Branch repair: The branch centralizes terminal error handling so callback or cleanup failures cannot replace the original provider rejection.
Findings None None.
Security None None.

How this fits together

Gateway talk sessions create realtime voice bridges through provider plugins and rely on error/close callbacks to end or recover a session. Lazy wrappers defer provider loading but own buffered input and the translation of provider connection failures into terminal lifecycle events.

flowchart LR
  A[Gateway talk session] --> B[Lazy voice bridge]
  B --> C[Provider bridge]
  C --> D{Connection outcome}
  D -->|Connected| E[Ready and forward input]
  D -->|Rejected| F[Report error]
  F --> G[Report terminal close]
  G --> H[Release provider bridge]
Loading

Before merge

  • Resolve merge risk (P1) - Existing consumers of a rejected lazy connect will now receive onError followed by onClose("error"); this is the established terminal-session contract but is a callback-order compatibility change.
  • Resolve merge risk (P1) - The bug fix adds production code (+106/-35) for generation-safe cleanup in two distinct plugin wrappers; the increase is justified by their different lifecycle state and cannot be safely shared across plugin boundaries.
  • Complete next step (P2) - The contributor branch already contains the bounded owner-level repair, so no separate repair job is appropriate.
Agent review details

Security

None.

PR surface

Source +71, Tests +170. Total +241 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 106 35 +71
Tests 2 176 6 +170
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 282 41 +241

Review metrics

Metric Value Why it matters
Production versus test delta production +106/-35; tests +176/-6 The production growth implements generation-safe terminal cleanup in xAI and Google; tests cover connect failures, callback failures, cleanup failures, concurrent connects, and stale generations.

Merge-risk options

Maintainer options:

  1. Accept the terminal callback contract (recommended)
    Merge with the intended behavior that a rejected lazy connection invokes onError then onClose("error") before propagating the same rejection.
  2. Pause for callback-contract reconsideration
    Pause if maintainers intend rejected connect promises to remain the sole failure signal for any existing realtime bridge consumer.

Technical review

Best possible solution:

Merge the two owner-local terminal helpers after exact-head CI passes, retaining the explicit error-before-close ordering and generation guards rather than moving provider lifecycle policy into Gateway callers.

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

Yes. The supplied before/after real loopback-refusal run exercises the xAI lazy wrapper’s rejected-connect path, and current main source independently shows the missing callback and cleanup transitions.

Is this the best way to solve the issue?

Yes. Handling terminal notification and cleanup in the lazy bridge is the narrow owner-boundary repair; caller-side synthetic closes would duplicate lifecycle policy and retain the resource leak.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6b9a6ece4814.

Labels

Label justifications:

  • P1: A failed realtime voice connection can leave an active talk session without a terminal outcome.
  • merge-risk: 🚨 compatibility: The PR changes the observable callback sequence for existing consumers after a rejected lazy bridge connection.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR provides before/after real transport-refusal output through the production lazy xAI wrapper and real ws client, showing the new terminal callback.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides before/after real transport-refusal output through the production lazy xAI wrapper and real ws client, showing the new terminal callback.

Evidence

What I checked:

  • Current xAI failure gap: Current main marks the generation terminal and clears input after a rejected connect, but does not invoke the terminal callback or close the loaded bridge. (extensions/xai/lazy-capability-providers.ts:440, 10a98702b7b8)
  • Current Google sibling gap: The Google lazy wrapper has the same rejected-connect pattern: it marks provider termination and clears audio without reporting close or releasing the bridge. (extensions/google/index.ts:306, 10a98702b7b8)
  • Branch repair: The branch centralizes terminal error handling so callback or cleanup failures cannot replace the original provider rejection. (extensions/xai/lazy-capability-providers.ts:278, b2c75216a289)
  • Google generation isolation: The branch creates a new Google bridge generation after terminal failure and prevents an old rejection from terminating its replacement. (extensions/google/index.ts:342, b2c75216a289)
  • Caller contract: Realtime bridge callbacks expose both onError and onClose, and the session runtime treats onClose as the provider-terminal boundary; the relay caller emits the error then closes its active session. (src/talk/provider-types.ts:149, 10a98702b7b8)
  • Real behavior proof: The PR body supplies before/after output using the real lazy xAI wrapper, real provider bridge, ws client, and a refused loopback TCP connection; only the fixed run records onClose("error"). (b2c75216a289)

Likely related people:

  • steipete: Current-main blame assigns both rejected-connect catches to the provider-seam refactor commit. (role: recent area refactor author; confidence: high; commits: 12ff4be1260f; files: extensions/xai/lazy-capability-providers.ts, extensions/google/index.ts)
  • vincentkoc: The merged lazy-runtime implementation established the affected xAI wrapper architecture and its generation-bound lifecycle behavior. (role: lazy-runtime feature introducer; confidence: high; commits: e35d22807e5f; files: extensions/xai/lazy-capability-providers.ts)

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-14T06:52:50.530Z sha 50a24b5 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T09:32:13.372Z sha 50a24b5 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T05:02:38.583Z sha 50a24b5 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T12:32:13.042Z sha 4feda753d255ce7fa12832205ba8ae0dfcacde4b :: needs changes before merge. :: [P1] Preserve the original relay connection error | [P1] Repair the equivalent Google lazy-connect path
  • reviewed 2026-08-15T12:48:51.863Z sha 5b46e579ccb1465bd8b2b253119cfa86d72f743f :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T12:57:56.867Z sha 8a440b23ff35e400b1e1306fbb61037ce4b31789 :: needs changes before merge. :: [P1] Preserve the completion callback on explicit Google bridge close
  • reviewed 2026-08-15T13:26:59.661Z sha c6a777db7bf5c8075edddb46d785fa3addb86968 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T15:02:53.118Z sha 66486bacca8e8d213d8e60bf3cd430a3f5924263 :: needs maintainer review before merge. :: none

@wanyongstar
wanyongstar force-pushed the fix/xai-voice-bridge-connect-failure branch from d1874c8 to 0772f6c Compare August 13, 2026 15:37
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 Aug 13, 2026
When the loaded realtime voice bridge's connect() rejected, the lazy
wrapper marked the generation terminal internally but never called
req.onClose and never closed the loaded bridge, leaking it and leaving
callers without a terminal outcome. Mirror the queued-flush failure
path: emit a terminal "error" and close the loaded bridge before
propagating the rejection.
@wanyongstar
wanyongstar force-pushed the fix/xai-voice-bridge-connect-failure branch from 0772f6c to 50a24b5 Compare August 14, 2026 06:49
@clawsweeper clawsweeper Bot 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. labels Aug 14, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 🦐 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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 15, 2026
@altaywtf

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 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 exact_review_queue).
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. 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 15, 2026
@altaywtf
altaywtf force-pushed the fix/xai-voice-bridge-connect-failure branch from 66486ba to b2c7521 Compare August 15, 2026 17:25
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 15, 2026
@altaywtf
altaywtf merged commit 8f59226 into openclaw:main Aug 15, 2026
141 of 143 checks passed
@altaywtf

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
openclaw#123064)

* fix(xai): report lazy voice bridge connect failure as terminal error

When the loaded realtime voice bridge's connect() rejected, the lazy
wrapper marked the generation terminal internally but never called
req.onClose and never closed the loaded bridge, leaking it and leaving
callers without a terminal outcome. Mirror the queued-flush failure
path: emit a terminal "error" and close the loaded bridge before
propagating the rejection.

* fix: harden realtime voice connection lifecycle

---------

Co-authored-by: Altay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google extensions: xai merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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.

2 participants