fix(app): recover from a silently dead event stream - #39349
Open
Luppa90 wants to merge 1 commit into
Open
Conversation
The SSE read has no timeout, so a socket that dies without a FIN or RST leaves the consumer parked forever: no error is thrown, the reconnect loop is never re-entered, and the UI freezes mid-message while the run continues server-side. Heartbeats did not help because the v2 server sends them as SSE comment frames, which the parser discards without yielding an event, so liveness was invisible to the app. Track liveness at the byte level instead and abort an attempt after 45s of silence, dropping into the existing reconnect path. Reconnecting alone was not enough. Session status is driven purely by session.execution.* events, so a run that finished during the outage stayed busy forever, and the only resync hook fired solely on the first connect because it was gated on the active-sessions query being unfetched. Reconcile against the server on every reconnect: clear status for runs that are no longer active and reload timelines for runs that are.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #39352
Type of change
What does this PR do?
Fixes the web UI freezing mid-session: spinner keeps spinning, timeline stops, and only a page refresh reveals the run finished long ago.
The SSE consumer has no liveness check, so a socket that dies without a FIN/RST parks
reader.read()forever — no error is thrown, and the reconnect loop inserver-sdk.tsxis never re-entered. Heartbeats don't help because v2 sends them as SSE comment frames, which the parser discards before the app can see them. So this adds a fetch wrapper that tracks the stream at the byte level (comment frames included) and a watchdog that aborts the attempt after 45s of silence (3 missed heartbeats), which drops into the existing reconnect path. The watchdog aborts a per-attempt controller captured in the closure so a stale timer can't kill a healthy successor connection.Reconnecting alone isn't enough:
session_statusis only written bysession.execution.*events, so a run that finished during the outage staysbusyforever, and the active-sessions refetch onserver.connectedwas gated on the query having no data, i.e. it only ever fired on the first connect. Now every reconnect refetches active sessions and reconciles: statuses the server no longer reports are cleared, and still-running sessions with loaded messages get their timeline force-reloaded (their deltas were lost mid-message). Sessions inretryare safe on both protocols — retries run inside the execution fiber, so the server still reports them active.How did you verify your code works?
session-timeline-transport.spec.ts,remote-tab-busy.spec.ts), including reconnect-after-close, reconnect-after-error, and heartbeat delivery.bun test(app package), typecheck, and lint are clean; the only failure is the pre-existingari18n parity gap, which fails identically ondev.Screenshots / recordings
Not a visual change — the fix is that the timeline and spinner recover on their own after a dead connection instead of freezing until a manual refresh.
Checklist