Skip to content

perf: run session state sync in parallel with messages fetch during startup hydration#579

Closed
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-hydrate-parallel
Closed

perf: run session state sync in parallel with messages fetch during startup hydration#579
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/webui-hydrate-parallel

Conversation

@sam-saffron-jarvis
Copy link
Copy Markdown
Contributor

Problem

hydrateActiveSessionAfterStartup runs two network requests sequentially:

  1. loadServerSessionMessages — fetches the session's message history
  2. syncActiveSessionFromServer — fetches /v1/sessions/{id}/state to determine if a response is active

These two requests are completely independent: neither depends on the result of the other. The current serial order wastes one full HTTP round-trip (~100–300 ms) every time a user loads the UI with a specific session URL.

Fix

Start syncActiveSessionFromServer immediately (before awaiting the messages fetch). The state round-trip now overlaps with the messages fetch instead of waiting for it.

Before: fetch_messages ──→ render ──→ fetch_state ──→ process
After:  fetch_messages ─────────────────────────────→ render
        fetch_state ──→ process (in parallel)

Impact

  • Saves ~1 HTTP round-trip latency on every startup that hydrates a _serverOnly session (direct URL navigation, page reload)
  • No change in behavior — JS is single-threaded so there are no data races

…tartup hydration

hydrateActiveSessionAfterStartup serialized two independent network
fetches: first load messages (for _serverOnly sessions), render, then
fetch session state via syncActiveSessionFromServer.

The messages fetch and the session state fetch (/v1/sessions/{id}/state)
are independent — neither depends on the result of the other. Start
syncActiveSessionFromServer immediately so its round-trip overlaps with
the messages fetch, saving approximately one HTTP round-trip worth of
latency (~100-300 ms) for users who navigate directly to a session URL
at startup.
@SamSaffron
Copy link
Copy Markdown
Owner

Consolidated this idea into a single local changeset on main with the other selected PR ideas.

@SamSaffron SamSaffron closed this May 8, 2026
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.

2 participants