Skip to content

Add SSE auto-reconnect to survive connection drops#489

Merged
rjroy merged 1 commit into
mainfrom
sse-auto-reconnect
Mar 23, 2026
Merged

Add SSE auto-reconnect to survive connection drops#489
rjroy merged 1 commit into
mainfrom
sse-auto-reconnect

Conversation

@rjroy

@rjroy rjroy commented Mar 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds exponential backoff reconnect (1s-16s, 5 attempts) to useChat when SSE stream drops unexpectedly (ECONNRESET)
  • Adds mount-reconnect: returning to a session with an existing sessionId probes the stream to recover in-progress or completed responses
  • Enables fire-and-forget usage: send a message, close the app, come back for the answer

Test plan

  • Existing tests updated and passing (2035 total)
  • New tests: mount recovery, no-reconnect without session, reconnect on stream drop, no-reconnect after user abort
  • Typecheck, lint, build all pass
  • Manual: send a message, kill the browser tab mid-stream, reopen and verify response appears

🤖 Generated with Claude Code

The SSE stream between client and daemon would silently die on
ECONNRESET, leaving the user with a frozen UI while the daemon
continued processing. Now useChat automatically reconnects with
exponential backoff (1s-16s, 5 attempts) and recovers state via
the daemon's existing snapshot mechanism.

Also adds mount-reconnect: returning to an active or completed
session probes the stream endpoint to pick up the response,
enabling fire-and-forget usage (send a message, close the app,
come back for the answer).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Mar 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nextjs/hooks/useChat.ts 77.77% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@rjroy rjroy merged commit e70a27b into main Mar 23, 2026
2 checks passed
@rjroy rjroy deleted the sse-auto-reconnect branch March 23, 2026 04:32
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.

1 participant