Repository navigation
fix(xai): report lazy voice bridge connect failure as a terminal error - #123064
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 1:32 PM ET / 17:32 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
How this fits togetherGateway 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +71, Tests +170. Total +241 across 4 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
d1874c8 to
0772f6c
Compare
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.
0772f6c to
50a24b5
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
66486ba to
b2c7521
Compare
|
Merged via squash.
|
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]>
Summary
fix(xai): report a lazy realtime voice bridge
connect()failure as a terminalerrorand close the loaded bridge, instead of leaking it silentlyWhat 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 onreq.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.onCloseis 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 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'sconnect():Trigger condition: any rejection from the real voice bridge's
connect().Root Cause
e35d22807e5(2026-08-05, improve(xai): defer optional capability runtimes #119374, "perf(xai): lazy-load optional capability runtimes").req.onCloseand release the loaded bridge. The connect-failure path marks the generation terminal internally (terminalGeneration = connectGeneration) without performing the external half of the contract.Why This Fix
connect()rejection with a syntheticonClose("error"). Rejected: duplicates terminal-state logic per caller and still leaks the loaded bridge.emitTerminal(connectGeneration, "error"); closeBridge(loadedBridge); throw error;.emitTerminalalready dedupes (one terminal outcome per generation) and clears pending input;closeBridgealready dedupes via a WeakSet. A late provider-reportedonClose("completed")after the failure is ignored, and post-failuresendAudiois dropped by the existing terminal checks.req.onClosedirectly withoutemitTerminal— would bypass the generation guard and could double-report against a concurrent provider close.User Impact
onClose("error"), the loaded bridge is closed immediately, and theconnect()rejection still propagates.erroroutcome 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 importedrealtime-voice-provider.js, the realXaiRealtimeVoiceBridge, and a realwsclient dialing a real closed loopback TCP port — producing a genuineECONNREFUSEDnetwork 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)
After (with fix, rebased on latest main)
Same real rejection on both runs; only the fixed wrapper reports the terminal outcome to the caller. Post-failure
sendAudiois dropped (isConnected()stays false, pending queue cleared by the terminal path).What was not tested: a live connection to
wss://api.x.aiwith real credentials; the failure is exercised at the real transport boundary (TCP refusal) instead, which traverses the identicalconnect()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 testreports voice connect failure as a terminal error(connect rejection propagates, loaded bridge closed once,onClosecalled exactly once with"error", late provider close ignored, post-failuresendAudiodropped).npx oxlint --deny=warnon both changed files — 0 warnings, 0 errors.