Repository navigation
Conversation
Greptile SummaryThis PR adds a
Confidence Score: 4/5Safe to merge after fixing the two P1 issues; the rest of the implementation is well-structured. Two P1 findings: session.ended is unreachable dead code (clients never receive session summaries), and partial tool-call cancellation resets pendingToolCalls to 0 prematurely, which can trigger incorrect watchdog resets and session rotation. Both are in the new code path only and do not break existing functionality, but they produce wrong behavior for the new feature. src/gateway/voiceclaw-realtime/session.ts (session.ended delivery), src/gateway/voiceclaw-realtime/gemini-live.ts (toolCallCancellation counter and API key URL exposure) Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/session.ts
Line: 326-348
Comment:
**`session.ended` is dead code — never delivered to the client**
`cleanup()` is triggered exclusively from `this.ws.on("close", ...)`. When that event fires the WebSocket `readyState` is already `WebSocket.CLOSED` (3), so the guard `this.ws.readyState === WebSocket.OPEN` is always false and the `session.ended` event is never sent. Clients expecting session summary data (duration, turn count) will never receive it.
The message needs to be sent *before* the connection closes — e.g. from a `disconnect()` method the adapter calls on its own, or emitted by `handleAdapterEvent` when it receives a terminal upstream event, with `cleanup()` only used for resource teardown.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/gemini-live.ts
Line: 314-327
Comment:
**`pendingToolCalls` reset to 0 on partial cancellation**
`this.pendingToolCalls = 0` is applied unconditionally regardless of how many IDs appear in the cancellation message. If Gemini ever sends a partial cancellation (a subset of in-flight call IDs), `pendingToolCalls` becomes 0 while `pendingToolCallIds` still contains the uncancelled IDs. This inconsistency means `resetWatchdog()` and the `rotateAfterToolCalls` deferred-rotation check (in `sendToolResult`) can fire prematurely, triggering a session rotation while tool calls are still genuinely in flight.
Using `this.pendingToolCallIds.size` as the counter, or decrementing only by `ids.length`, keeps both fields consistent.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/gemini-live.ts
Line: 491-495
Comment:
**Client WebSocket left open after all reconnect attempts exhaust**
After all `MAX_RECONNECT_ATTEMPTS` fail, the adapter sends `{ type: "error", code: 502 }` but neither the adapter nor the session closes the client-facing WebSocket. The session appears alive but the Gemini upstream is gone; any subsequent audio or tool results from the client will be silently dropped (`sendUpstream` skips when `upstream` is null). Clients that don't immediately `close()` on receiving an error event will leak an open connection.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Add VoiceClaw realtime brain gateway (NA..." | Re-trigger Greptile |
| private async cleanup(): Promise<void> { | ||
| if (this.closed) { | ||
| return; | ||
| } | ||
| this.clearHandshakeTimer(); | ||
| this.releasePreauthBudget(); | ||
| for (const controller of this.inFlightTools.values()) { | ||
| controller.abort(); | ||
| } | ||
| this.inFlightTools.clear(); | ||
| const transcript = this.adapter?.getTranscript() ?? []; | ||
| this.adapter?.disconnect(); | ||
| this.adapter = null; | ||
| if (transcript.length > 0 && this.ws.readyState === WebSocket.OPEN) { | ||
| this.send({ | ||
| type: "session.ended", | ||
| summary: "Real-time brain session ended.", | ||
| durationSec: Math.round((Date.now() - this.startedAt) / 1000), | ||
| turnCount: transcript.filter((entry) => entry.role === "user").length, | ||
| }); | ||
| } | ||
| this.closed = true; | ||
| } |
There was a problem hiding this comment.
session.ended is dead code — never delivered to the client
cleanup() is triggered exclusively from this.ws.on("close", ...). When that event fires the WebSocket readyState is already WebSocket.CLOSED (3), so the guard this.ws.readyState === WebSocket.OPEN is always false and the session.ended event is never sent. Clients expecting session summary data (duration, turn count) will never receive it.
The message needs to be sent before the connection closes — e.g. from a disconnect() method the adapter calls on its own, or emitted by handleAdapterEvent when it receives a terminal upstream event, with cleanup() only used for resource teardown.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/session.ts
Line: 326-348
Comment:
**`session.ended` is dead code — never delivered to the client**
`cleanup()` is triggered exclusively from `this.ws.on("close", ...)`. When that event fires the WebSocket `readyState` is already `WebSocket.CLOSED` (3), so the guard `this.ws.readyState === WebSocket.OPEN` is always false and the `session.ended` event is never sent. Clients expecting session summary data (duration, turn count) will never receive it.
The message needs to be sent *before* the connection closes — e.g. from a `disconnect()` method the adapter calls on its own, or emitted by `handleAdapterEvent` when it receives a terminal upstream event, with `cleanup()` only used for resource teardown.
How can I resolve this? If you propose a fix, please make it concise.| const cancellation = asRecord(msg.toolCallCancellation); | ||
| if (cancellation) { | ||
| const ids = Array.isArray(cancellation.ids) | ||
| ? cancellation.ids.filter((id): id is string => typeof id === "string") | ||
| : []; | ||
| this.pendingToolCalls = 0; | ||
| for (const id of ids) { | ||
| this.pendingToolCallIds.delete(id); | ||
| } | ||
| if (ids.length > 0) { | ||
| this.sendToClient?.({ type: "tool.cancelled", callIds: ids }); | ||
| } | ||
| this.resetWatchdog(); | ||
| return; |
There was a problem hiding this comment.
pendingToolCalls reset to 0 on partial cancellation
this.pendingToolCalls = 0 is applied unconditionally regardless of how many IDs appear in the cancellation message. If Gemini ever sends a partial cancellation (a subset of in-flight call IDs), pendingToolCalls becomes 0 while pendingToolCallIds still contains the uncancelled IDs. This inconsistency means resetWatchdog() and the rotateAfterToolCalls deferred-rotation check (in sendToolResult) can fire prematurely, triggering a session rotation while tool calls are still genuinely in flight.
Using this.pendingToolCallIds.size as the counter, or decrementing only by ids.length, keeps both fields consistent.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/gemini-live.ts
Line: 314-327
Comment:
**`pendingToolCalls` reset to 0 on partial cancellation**
`this.pendingToolCalls = 0` is applied unconditionally regardless of how many IDs appear in the cancellation message. If Gemini ever sends a partial cancellation (a subset of in-flight call IDs), `pendingToolCalls` becomes 0 while `pendingToolCallIds` still contains the uncancelled IDs. This inconsistency means `resetWatchdog()` and the `rotateAfterToolCalls` deferred-rotation check (in `sendToolResult`) can fire prematurely, triggering a session rotation while tool calls are still genuinely in flight.
Using `this.pendingToolCallIds.size` as the counter, or decrementing only by `ids.length`, keeps both fields consistent.
How can I resolve this? If you propose a fix, please make it concise.| } | ||
| } | ||
| } | ||
| this.isReconnecting = false; | ||
| this.sendToClient?.({ type: "error", message: "Gemini Live reconnect failed", code: 502 }); |
There was a problem hiding this comment.
Client WebSocket left open after all reconnect attempts exhaust
After all MAX_RECONNECT_ATTEMPTS fail, the adapter sends { type: "error", code: 502 } but neither the adapter nor the session closes the client-facing WebSocket. The session appears alive but the Gemini upstream is gone; any subsequent audio or tool results from the client will be silently dropped (sendUpstream skips when upstream is null). Clients that don't immediately close() on receiving an error event will leak an open connection.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/voiceclaw-realtime/gemini-live.ts
Line: 491-495
Comment:
**Client WebSocket left open after all reconnect attempts exhaust**
After all `MAX_RECONNECT_ATTEMPTS` fail, the adapter sends `{ type: "error", code: 502 }` but neither the adapter nor the session closes the client-facing WebSocket. The session appears alive but the Gemini upstream is gone; any subsequent audio or tool results from the client will be silently dropped (`sendUpstream` skips when `upstream` is null). Clients that don't immediately `close()` on receiving an error event will leak an open connection.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1f29963ed
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| export { VOICECLAW_REALTIME_PATH }; | ||
|
|
||
| const wss = new WebSocketServer({ noServer: true }); |
There was a problem hiding this comment.
Set pre-auth frame limits on VoiceClaw upgrade server
The VoiceClaw upgrader creates a dedicated WebSocketServer without maxPayload, so /voiceclaw/realtime uses the ws default frame limit instead of the gateway’s hardened pre-auth limit (MAX_PREAUTH_PAYLOAD_BYTES). Because auth happens after upgrade (in session.config), unauthenticated clients can push much larger frames than intended and consume memory/CPU before any auth gate applies. This should use the same pre-auth payload cap as the main gateway WS path.
Useful? React with 👍 / 👎.
| if (asRecord(msg.goAway)) { | ||
| if (this.pendingToolCalls > 0 || !this.currentlyResumable) { | ||
| this.rotateAfterToolCalls = true; | ||
| return; |
There was a problem hiding this comment.
Reconnect immediately when deferred goAway becomes resumable
When goAway is received while currentlyResumable is false, this path sets rotateAfterToolCalls and returns, but there is no follow-up reconnect when a later sessionResumptionUpdate flips resumable to true. In that sequence (with no tool calls in flight), the adapter never rotates and then treats socket close as a hard error instead of resuming. Trigger reconnect once resumability is restored if rotateAfterToolCalls is already set and no tool calls are pending.
Useful? React with 👍 / 👎.
e87d70c to
bf4cea2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf4cea210d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| for (let attempt = 1; attempt <= MAX_RECONNECT_ATTEMPTS; attempt += 1) { | ||
| try { | ||
| await this.openUpstream(); | ||
| this.isReconnecting = false; | ||
| this.sendToClient?.({ type: "session.rotated", sessionId: `gemini-resumed-${Date.now()}` }); |
There was a problem hiding this comment.
Stop reconnect attempts after session disconnect
When the client WebSocket closes, disconnect() sets this.disconnected = true, but an already-running reconnect() loop still executes openUpstream() and can establish a new Gemini socket after the session is gone. In that case the adapter keeps an orphan upstream connection (and potentially burns provider resources) because sendToClient is already null and nothing closes the newly opened socket. Re-check this.disconnected before each reconnect attempt (and immediately after openUpstream() resolves) to abort and tear down cleanly.
Useful? React with 👍 / 👎.
| this.pendingToolCalls = 0; | ||
| for (const id of ids) { | ||
| this.pendingToolCallIds.delete(id); |
There was a problem hiding this comment.
Keep pending tool-call state consistent on cancellations
This handler unconditionally sets pendingToolCalls to 0 for any toolCallCancellation, even though it only removes the IDs that were actually cancelled from pendingToolCallIds. If Gemini cancels only a subset of calls, the adapter now believes all tool calls are done, which can restart watchdog/reconnect flows too early and mis-handle later results for still-active calls. Update the counter based on cancelled IDs (or derive from the set) instead of zeroing it globally.
Useful? React with 👍 / 👎.
f53320e to
edd7f8c
Compare
|
Codex maintainer review: keep open, but not merge-ready yet. The direction is plausible if we want an explicitly VoiceClaw-compatible gateway endpoint, but the latest diff still has two behavior blockers:
The earlier partial tool-call cancellation concern looks addressed in CI is also red on After those changes: rerun the focused |
edd7f8c to
40e79d2
Compare
|
Landed via squash after rebasing onto current
Local proof:
CI on
Thanks @yagudaev! |
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Adds the VoiceClaw-compatible realtime brain WebSocket endpoint backed by Gemini Live, with owner-auth gating, async OpenClaw tool handoff, docs, and lifecycle tests. Maintainer fixup: terminal upstream errors now send the error, emit session.ended while the client socket is still open, then close the client-facing socket. Co-authored-by: Michael Yagudaev <[email protected]>
Summary
/voiceclaw/realtimeGateway WebSocket path for VoiceClaw-compatible clients to connect directly to Gemini Live.ask_braintool calls into OpenClaw with isolated VoiceClaw session namespaces, auth checks, reconnect handling, and tool cancellation handling.Test plan
pnpm check:changedpnpm buildcc; addressed blocking/medium findingsLinear: NAN-656