fix(gui): guard session WS onmessage JSON.parse against malformed frames - #365
Open
ChakrawarShubham wants to merge 1 commit into
Open
fix(gui): guard session WS onmessage JSON.parse against malformed frames#365ChakrawarShubham wants to merge 1 commit into
ChakrawarShubham wants to merge 1 commit into
Conversation
The session WebSocket handler at api.ts:1824 called JSON.parse without a try/catch. A single malformed frame from the server would throw an uncaught exception inside the browser event handler, silently killing the onmessage callback — the session would freeze with no error feedback. The sibling connectEvents handler at api.ts:1471 already wraps its JSON.parse in try/catch. This mirrors that same pattern.
ChakrawarShubham
force-pushed
the
fix/ws-onmessage-unguarded-parse
branch
from
July 31, 2026 06:32
03da1d2 to
11f3efa
Compare
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.
Problem
The session WebSocket
onmessagehandler callsJSON.parse(e.data)without atry/catch. A single malformed frame from the server throws an uncaught exception inside the browser event handler, silently killing the callback — the session stops receiving all events (turns, approvals, tool output) and the UI freezes with no error indication.Root cause
The handler at
surfaces/gui/src/api.ts:1824was written without the guard that the siblingconnectEventshandler at line 1471 already has. Both handlers do the same thing — receive a WebSocket frame,JSON.parseit, pass to a handler — but only one was wrapped.Fix
Wrap
JSON.parseintry/catch, mirroring the exact pattern (and comment) already used byconnectEvents:Validation
connectEventshandler has used this pattern since it was written