Skip to content

fix(app): recover from a silently dead event stream - #39349

Open
Luppa90 wants to merge 1 commit into
anomalyco:devfrom
Luppa90:fix-event-stream-stall
Open

fix(app): recover from a silently dead event stream#39349
Luppa90 wants to merge 1 commit into
anomalyco:devfrom
Luppa90:fix-event-stream-stall

Conversation

@Luppa90

@Luppa90 Luppa90 commented Jul 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #39352

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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 in server-sdk.tsx is 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_status is only written by session.execution.* events, so a run that finished during the outage stays busy forever, and the active-sessions refetch on server.connected was 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 in retry are safe on both protocols — retries run inside the execution fiber, so the server still reports them active.

How did you verify your code works?

  • Ran the patched and unpatched UI side by side against real workloads for a day: the unpatched UI froze repeatedly, the patched UI didn't.
  • New unit tests: byte tracking includes heartbeat frames, non-stream fetches pass through untouched, reconcile clears finished-during-outage sessions, reloads still-running ones, and leaves unopened sessions alone.
  • All 9 transport e2e specs pass (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-existing ar i18n parity gap, which fails identically on dev.

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web UI freezes mid-session when the event stream dies silently; only a page refresh recovers

1 participant