Skip to content

perf(tui): open a session with its latest messages and load the rest once it stays open - #53429

Closed
moritzWa wants to merge 1 commit into
anomalyco:devfrom
moritzWa:perf/tui-first-message-page
Closed

moritzWa wants to merge 1 commit into
anomalyco:devfrom
moritzWa:perf/tui-first-message-page

Conversation

@moritzWa

@moritzWa moritzWa commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #53428

Type of change

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

What does this PR do?

Opening a session waited for its last 100 messages. For a long session that fetch is most of the time it takes to open: about 290–430 ms in my logs, against 7–8 ms for the last 20 messages of the same sessions.

  • sync.session.sync(sessionID, { firstPage: true }) loads only the last 20 messages. A later call without firstPage loads the usual 100. A full sync asked for while a first page is still loading runs after it rather than returning early, and it reuses the first page's hydration tracker, so events that arrived in between are still not overwritten by stale server data.
  • The session route opens with a first page, then runs the full sync once the session has stayed open for a second while the terminal is focused. A session you only pass through while switching never loads its full history. A terminal that doesn't report focus counts as focused, so there the full history follows a second later.

Other callers of sync.session.sync are unchanged and still do a full sync.

How did you verify your code works?

Two new tests in test/cli/cmd/tui/sync-live-hydration.test.tsx. One checks that a first page loads the latest 20 messages, that a second first page doesn't fetch again, and that a full sync then loads all 50 (requests made: [20, 100]). The other checks that a full sync asked for while a first page is loading still ends with the full history. The full packages/tui suite (196 tests) passes. Typecheck shows only the dialog-move-session.tsx errors that are already on dev.

I've also used it in my build while switching between long sessions.

Screenshots / recordings

No recording. On demo sessions generated locally both builds open in under a frame, so a video shows no difference. The gap shows up on real long sessions with large tool output, which I can't share. The timings above are from those.

Checklist

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

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(tui): open a session with its latest messages and load the rest once it stays open doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
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.

TUI: opening a long session waits for its last 100 messages before drawing

2 participants