Skip to content

Conversation

@dwb
Copy link

@dwb dwb commented Feb 11, 2026

Hi, so I didn’t really want this to be this big, but one thing led to another…

It started with wanting to fix reconnection and message catchup on Safari iOS. But then if you come back to the tab and messages catch up, losing your scroll position is quite annoying, so I added scroll position saving. And then the hooks started to look a bit dodgy so did a bit of a refactor.

It all seems to work on my two instances - hope it makes sense. Won’t be offended if you reject / chop it into bits / whatever.

Thanks!

—-

Server: when an SSE stream reconnects with last_sequence_id, query ListMessagesSince to backfill messages written between disconnect and reconnect. Previously these were silently lost, causing invisible gaps. On resume, omit context_window_size (only partial messages available).

Client SSE reconnection: on iOS Safari, backgrounding a tab kills TCP connections but EventSource.readyState still reads OPEN. Track when the page was hidden and force-reconnect if backgrounded for >5s. Suppress auto-scroll during catch-up so the user's scroll position is preserved.

Client scroll position: save to localStorage on scroll settle (100ms debounce) and on visibilitychange/beforeunload. Restore via useLayoutEffect after messages render. Use ResizeObserver on .messages-list to re-scroll to bottom when content expands (images loading, tool outputs rendering) during streaming.

Refactor: replace function-in-ref patterns (reconnectRef, forceReconnectRef, handleManualReconnect) with useCallback hooks with proper dependency arrays. Wrap setupMessageStream in useCallback; nest resetHeartbeatTimeout inside it.

@cla-bot
Copy link

cla-bot bot commented Feb 11, 2026

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: exe.dev user.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@dwb dwb force-pushed the reconnect-improvements branch from a2cb520 to 377cd3c Compare February 11, 2026 22:53
@cla-bot
Copy link

cla-bot bot commented Feb 11, 2026

We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please contact @crawshaw at david@bold.dev to get yourself added.

Server: when an SSE stream reconnects with last_sequence_id, query
ListMessagesSince to backfill messages written between disconnect and
reconnect. Previously these were silently lost, causing invisible gaps.
On resume, omit context_window_size (only partial messages available).

Client SSE reconnection: on iOS Safari, backgrounding a tab kills TCP
connections but EventSource.readyState still reads OPEN. Track when the
page was hidden and force-reconnect if backgrounded for >5s. Suppress
auto-scroll during catch-up so the user's scroll position is preserved.

Client scroll position: save to localStorage on scroll settle (100ms
debounce) and on visibilitychange/beforeunload. Restore via
useLayoutEffect after messages render. Use ResizeObserver on
.messages-list to re-scroll to bottom when content expands (images
loading, tool outputs rendering) during streaming.

Refactor: replace function-in-ref patterns (reconnectRef,
forceReconnectRef, handleManualReconnect) with useCallback hooks with
proper dependency arrays. Wrap setupMessageStream in useCallback;
nest resetHeartbeatTimeout inside it.

Co-authored-by: Shelley <shelley@exe.dev>
@dwb dwb force-pushed the reconnect-improvements branch from 377cd3c to f5806d7 Compare February 12, 2026 20:41
@cla-bot cla-bot bot added the cla-signed label Feb 12, 2026
@crawshaw
Copy link
Contributor

clabot is done, over to @philz

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants