Repository navigation
fix(xai): prevent realtime retries from reviving closed sessions - #117399
Conversation
* origin/main: refactor(doctor): unify legacy auth migration ownership (#117361) fix(plugins): surface actionable doctor warnings (#117357) fix(ci): use corrected Kova release evaluator (#116920) fix(ci): stabilize release validation assertions (#117377) refactor(memory): use sqlite transcript identities (#117334) fix(plugins): require tracked owners for targeted updates (#117333)
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 8:23 AM ET / 12:23 UTC. ClawSweeper reviewWhat this changesThe PR gives xAI realtime voice connections an explicit provider-local lifecycle so canceled, closed, and replaced sockets cannot revive or mutate the active session during retries. Merge readinessKeep this PR open for normal maintainer review, not cleanup: current main still has bridge-wide connection flags and a reused reconnect controller, so late socket callbacks can affect a replacement connection. The branch moves those facts into the xAI provider lifecycle, fences events by connection identity, and adds focused ordering regressions; I found no discrete correctness defect in the patch. Priority: P1 Review scores
Verification
How this fits togetherThe xAI bundled plugin creates a realtime voice bridge that resolves credentials, opens a WebSocket, processes provider events, and forwards audio, transcripts, tool results, and close outcomes to the voice runtime. This change sits between socket callbacks and bridge state, deciding whether each connection event can affect the current voice session. flowchart LR
A[Voice runtime calls bridge] --> B[xAI realtime voice bridge]
B --> C[Connection lifecycle owner]
C --> D[Credential resolution and WebSocket]
D --> E[Provider socket events]
E --> F{Current connection and active phase?}
F -->|Yes| G[Audio, transcripts, tool results, close outcome]
F -->|No| H[Ignore stale callback]
G --> A
Decision needed
Why: The implementation is a substantive state-transition refactor on a maintainer-labeled realtime provider path; automation can establish the repair shape and evidence, but the final landing decision remains an explicit maintainer responsibility. Before merge
Agent review detailsSecurityNone. PR surfaceSource +276, Tests +316. Total +592 across 6 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep lifecycle ownership inside the xAI provider, land it after exact-head validation completes, and keep the separate xAI resumed-response backend failure tracked by #116663 out of this connection-ownership repair. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main lets any socket callback mutate bridge-wide connection flags and run retry work, while the added focused tests model a deferred stale close after a replacement connects. This read-only review did not execute the live xAI path locally. Is this the best way to solve the issue? Yes: a provider-local lifecycle is the narrowest maintainable owner for socket identity, retry state, and terminal outcomes; current xAI state is bridge-wide, while importing the OpenAI extension's private helper would violate extension boundaries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 142ad75c4336. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…nect-lifecycle * origin/pr-117399-direct: fix(xai): preserve immediate restart ownership test(xai): cover realtime lifecycle ownership fix(xai): own realtime connection lifecycle
Related: #116201
What Problem This Solves
Fixes an issue where xAI realtime voice users could have late connection events, overlapping connect calls, or retry callbacks mutate a session after it had been replaced, cancelled, or closed.
Why This Change Was Made
Adds a provider-local connection lifecycle with explicit
idle,connecting,ready,retry-wait, andterminalstates. The xAI adapter now translates socket and provider events into lifecycle facts, fences events by connection and socket identity, owns retry state in one place, and gives failure precedence over later cancel/close events.The change stays inside the xAI provider. It adds no provider, config, environment-variable, or plugin SDK surface.
User Impact
xAI realtime voice connect, retry, cancel, close, and failure behavior is deterministic and idempotent. Concurrent connects share one attempt, stale events are ignored, explicit reconnects replace pending retry waits, and terminal outcomes are reported once.
Evidence
58/58passed.f117c2166debfe2b0580fd58b9800fbdf02a9862:pnpm check:changedpassed on Blacksmith Testbox, including extension typechecks, test typechecks, lint, formatting, plugin boundaries, dead-code checks, database-first guard, sidecar checks, and runtime import cycles.close(); connect()ownership race; commit378e7d6b2c9fixes it. The follow-up review was clean with no P0/P1 findings.a84302cd73aa23b5c050ba755f3b15973e63f215failed at the same final checkpoint:378e7d6b2c9and refreshed headf117c2166de; the merge from currentmaintouched no xAI or realtime voice files.AI-assisted: yes. The implementation, tests, live results, and known provider-side limitation were reviewed before submission.