fix: centralized WebSocket liveness checks and UI status indicator#2
Closed
fix: centralized WebSocket liveness checks and UI status indicator#2
Conversation
…g requests SessionManager loads all persisted Gemini sessions from ~/.gemini/sessions/*.json asynchronously in its constructor via `this.ready = this.init()`. Previously, `sessionManager.ready` was never awaited anywhere, so the server would start accepting WebSocket connections before loadSessions() had completed. This created a race condition on the very first request after a server restart: if a client tried to resume an existing Gemini session, `sessionManager.getSession(sessionId)` would return undefined (the session hadn't been loaded from disk yet), causing the `--resume <cliSessionId>` flag to be silently omitted when spawning the Gemini CLI process. The CLI would then start a blank new session instead of continuing the prior conversation, with no error or indication to the user. The fix adds `await sessionManager.ready` in startServer() immediately after `await initializeDatabase()`, following the same pattern already established for database initialization. This guarantees the session store is fully populated before any request handler can call getSession(), createSession(), or addMessage(). No other providers are affected: Claude, Cursor, and Codex session providers are stateless per-request (they read from disk or SQLite on demand) and have no equivalent eager-loading singleton. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This comprehensive update addresses Issue siteboon#12 and enhances overall system stability: 1. Safe WebSocket Writing: Enhanced WebSocketWriter in server/index.js with readyState checks and try-catch blocks to prevent server crashes on client disconnects. 2. Server-Side Heartbeat: Implemented a ping/pong mechanism to actively detect and terminate dead connections. 3. Automatic Process Cleanup: Updated the disconnect handler to proactively kill orphaned CLI processes (Gemini, Cursor, Codex, Claude) when their associated WebSocket closes. 4. Provider Migration: Migrated all major providers (Gemini, Cursor, Codex, Claude SDK) to use the safe WebSocketWriter instead of raw .send() calls. 5. UI Connection Indicator: Added a visual status dot in the SidebarHeader to indicate WebSocket connectivity state (Green: Connected, Red: Disconnected).
Used StringDecoder from the string_decoder module instead of Buffer.toString() in gemini-cli.js and cursor-cli.js. This ensures that multi-byte characters that are split across process stdout/stderr data chunks are correctly decoded, preventing garbled text at chunk boundaries in streamed LLM responses.
Cleaned up duplicate export keywords from function definitions that were also being exported in the centralized export blocks at the end of the files. This fixes the SyntaxError that was causing the server to crash on startup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This Pull Request addresses several critical stability issues across all LLM providers and adds a visual connection indicator to the UI.
Key Changes
WebSocketWriterinserver/index.jswithreadyStatechecks andtry-catchblocks to prevent unhandled exceptions from crashing the server when a client disconnects.Buffer.toString()withStringDecoderingemini-cli.jsandcursor-cli.jsto correctly handle multi-byte characters split across data chunks.claude-sdk.jsand corrected the Codex SDK import name.SidebarHeader(Green: Connected, Red: Disconnected).Impact