fix(app): recover from a silently dead event stream - #39349
Open
Luppa90 wants to merge 1 commit into
Open
Conversation
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. 👍 |
Luppa90
force-pushed
the
fix-event-stream-stall
branch
from
July 28, 2026 20:12
b9a3cfb to
31d07d4
Compare
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 a run that kept going lost the deltas its timeline was waiting on. Reconcile against the server on reconnect: clear status for runs that are no longer active and reload the timelines held locally. Drive that repair from the transport rather than from the server's server.connected frame. The failure being recovered from is a stream that stops delivering, so a repair waiting to be told about the reconnect is exactly the one that never runs. It fires when a replacement attempt opens, before any byte arrives, and talks plain HTTP so it still completes when the replacement stream delivers nothing either. Reload by what is held locally rather than by status, since a directory bootstrap racing the repair also rewrites session_status from the server and would otherwise leave a finished session reading idle with its timeline still frozen mid-message.
Luppa90
force-pushed
the
fix-event-stream-stall
branch
from
July 30, 2026 18:23
31d07d4 to
2c6b52b
Compare
6 tasks
6 tasks
6 tasks
6 tasks
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: the spinner keeps spinning, the timeline stops, and only a page refresh reveals the run finished long ago.
A dead event stream is undetectable. The SSE consumer reads the response body with no timeout, so a socket that dies without a FIN/RST parks
reader.read()forever — no error is thrown, so the reconnect loop inserver-sdk.tsxis never re-entered. Heartbeats can't help, because v2 sends them as SSE comment frames which the parser discards without yielding an event, leaving liveness invisible at the event level. So this tracks the stream at the byte level (comment frames included) via a fetch wrapper, and a per-attempt watchdog aborts after 45s of silence, dropping into the existing reconnect path. The watchdog aborts a controller captured per attempt, so a stale timer can't kill a healthy successor connection.Reconnecting alone repairs nothing.
session_statusis written only bysession.execution.*events, so a run that finishes during the outage staysbusyforever, and a run that keeps going has lost the deltas its timeline was waiting on. So the client reconciles against the server on reconnect: statuses the server no longer reports active are cleared, and locally-held timelines are reloaded.Two details in that repair are load-bearing, and both were found by a fix that looked right and didn't work:
server.connectedframe. The failure being recovered from is a stream that stops delivering, so a repair that waits to be told about the reconnect is exactly the one that never runs. It fires when a replacement attempt opens, before any byte arrives, and talks plain HTTP so it still completes when the replacement stream delivers nothing either. It also deliberately does not go through the active-sessions query: routing it there made it conditional on that query being idle, and a first fetch that never settles disabled the repair permanently.bootstrapDirectoryalso rewritessession_statusfrom the server on reconnect and then callsresolve(), which refreshes session info but never messages. When it lands first, a finished session already readsidle, so a status-keyed reload skips it — clearing the spinner while leaving the timeline frozen mid-message.Sessions in
retrykeep their status, since retries run inside the execution fiber and the server still reports them active on both protocols.How did you verify your code works?
event stream stalled, reconnecting {idle: 48870}→event stream re-established, repairing state {attempt: 2}→ a bare/session/status→repaired state after event stream reconnect {active: [...], resynced: [...]}→ session reloads. The frozen tab recovers on its own, with no page refresh./session/statusin the network log — the SDK only appends?directory=when constructed with one, so the repair's request is distinguishable from the directory-scoped bootstrap calls.session-timeline-transport.spec.ts,remote-tab-busy.spec.ts), including reconnect-after-close, reconnect-after-error, and heartbeat delivery.bun testfor the app package, typecheck, prettier and oxlint are clean. The only failing test is the pre-existingari18n parity gap, which fails identically ondev.Worth stating plainly: the transport-driven trigger is verified in live use, not by a unit test — the reconnect path needs a real stream to exercise.
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