Repository navigation
perf(history): load recent turns first across clients - #302
Merged
Merged
Conversation
nixuuu
marked this pull request as ready for review
November 6, 2026 20:38
nixuuu
force-pushed
the
perf/tail-first-3
branch
from
November 6, 2026 21:04
332d328 to
a17eed6
Compare
nixuuu
added a commit
that referenced
this pull request
Nov 6, 2026
Jump to latest can leave the reader above the end when the composer expands or virtual rows change height during navigation. ### Cause and fix The old jump took one native smooth-scroll target before the new layout settled. `settle()` ignored corrections for a 1 s lease, and only `scrollend` explicitly completed navigation. If the browser cancels that scroll without the completion event, the last measurement can be swallowed by the lease; its expiry schedules no correction. This leaves `stuck = true` while the actual scroll position is short of the end. Ordinary isolated idle cases reached the bottom; the exact natural sequence on the reported nightly remains unconfirmed. The cancelled-scroll/missing-event path below is reproducible with fault injection. Replace end navigation with a frame-driven animation using existing motion tokens. Each frame reads the current end, every write is attributed to the feed, and completion calls the normal end settlement directly. Reader gestures, row navigation and fold anchoring cancel it. Far jumps and reduced motion retain the instant path. Track the actual derived footer reservation in the post-DOM correction effect, including the delayed footer-height commit. Extract unchanged keyboard targeting helpers to keep the component within the size limit; document the behavior in Polish. ### Browser evidence Used the isolated long-thread route with production feed/composer/state logic, 120 variable-height turns loaded tail-first (24 initially), older pages through `view.history.load()`, work folds/tool groups, markdown tables/code blocks, real composer compaction, draft/empty states, queue and secret panels. Temporary fixture changes and traces are excluded from the commit. Sampled `scrollHeight - scrollTop - clientHeight` about every 100 ms for 2 s. For a 1000 px start, explicitly cancel native scrolling at 350 ms and suppress `scrollend`: | Approx. time (ms) | Before gap (px) | After gap (px) | | --- | ---: | ---: | | 0 | 1000 | 1000 | | 100 | 910.5 | 304 | | 200 | 518 | 56 | | 300 | 235 | 3.5 | | 400 | 145 | 0 | | 500–2000 | 145 | 0 | - Desktop 1440 px and phone 390 px: 1, 3 and 6 turns up, plus near smooth jumps and far instant jumps, compact/expanded composer, empty/draft. All finish at the native end position; raw values are 0–0.5 CSS px from fractional scroll geometry, matching normal stream following. - Visible live-answer growth checked separately: near/far jumps on both widths finish at the same end. Scrolling up during streaming preserves the measured row with 0 px displacement on both widths. History prepend (24 → 48 turns) moves the anchor by less than 0.21 px. Opening work/tool folds keeps the header at 0 px displacement; keyboard paging and interrupting a jump keep reader control. - Simulated reduced motion takes the instant path. A footer growing from 211 to 423 px at 650 ms, after the jump completed, retains a 0 px gap through 2 s. Preview limitations: its container-scroll action emits trusted scroll events but no wheel event, so gesture attribution also used a dispatched wheel event. CPU throttling and native reduced-motion emulation were unavailable. Reduced motion was simulated through the media query and disabled CSS transitions. This checks the shared web UI in Chromium; an Electron binary and the user's exact browser build were unavailable. ### Validation Passed: `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`, `bun run format:check`, `bun run check:tmp`, and the web build. The full run processed 1,717 tests across 280 files with 0 failures (158 opt-in/skipped tests) and no test temp directories left behind. Test temp data stayed inside the worktree, with Git parent discovery bounded at that directory so plain-folder fixtures do not inherit the repository origin. No UI/component tests added. Copy audit (docs/copy.md §8): **no UI text changed**. Related: #302 (tail-first history coverage; not identified as the introducing change).
This was referenced Nov 13, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 15, 2026
## Change Navigating away while a draft, history request, or queue gesture was pending could resume callbacks against another conversation or destroyed Svelte derived values. - Capture the bot, draft, and pending-message baseline before draft synchronization. Sending from bot A still delivers and acknowledges A's draft after navigation to B; completion cannot alter B's pending messages or sending indicator. - Dispose queue pointer listeners when the panel unmounts or its queue changes. Pointer cancellation restores the preview without saving, and deferred positioning cannot revive a finished gesture. - Bind quote navigation to the original thread lifetime and check it after history and render waits. Navigation cancels the jump silently instead of expanding/scrolling the next thread or showing a stale missing-source toast. Document the lifecycle rules for retained callbacks and asynchronous work. These fixes address confirmed navigation races; they do not establish the cause of every reported `derived_inert` warning. Fixes: #449 Fixes: #302 ## Verification - Web typecheck: `bun run --cwd apps/web typecheck` — zero errors and warnings. - Scoped oxlint, oxfmt, and `git diff --check` passed. - Temporary reproductions using the production code and Svelte runtime confirmed the failures before the fixes and zero `derived_inert` warnings afterward. Covered bot delivery/retry across navigation, queue disposal/cancellation, and quote cancellation during history loading and feed reveal, including genuine missing-source results. - Chromium with mocked backend responses: queue drop, cancellation, unmount, and replacement passed at desktop and phone widths in light and dark themes. Normal drop writes once; the cancellation cases write nothing. Timeline scrolling and fold expansion also produced no `derived_inert` warnings in the exercised fixture. - No UI copy changes. Reproduction scripts, screenshots, and logs remain outside the repository. Full repository checks and builds are left to CI; packaged desktop and a live gateway were not exercised for these fixes.
nixuuu
added a commit
that referenced
this pull request
Nov 20, 2026
## Change - Web and desktop show the loaded timeline immediately. Scrolling up to a gap reads one older page. “Show earlier work” loads the selected turn, including turns that span several pages. On mobile, a gesture toward the history edge loads at most one page. - Web, desktop and mobile keep the live stream open when an older page covers the changes already received. If the stream advanced past the page, the client replays from the page checkpoint to recover concurrent edits and deletions. - Desktop persists a bounded history tail. Web and desktop limit inactive expanded content to 32 items and 8 MiB and cancel obsolete reads on reset. An oversized result stays available while in use. Clients reuse the measured size of an unchanged snapshot when leaving a conversation. - Header-only updates preserve the timeline rows. Unchanged controls and heartbeats still run validation and connection diagnostics while avoiding redundant view updates. ## Verification - Chromium on Linux, 2,160 items and 19 subagents. Opening the thread issued 0 older-page requests, down from 16 (453,590 response bytes). Checked scroll restoration, a multi-page turn, a quote, retry after a failed read and a timeline that fits on screen. Tested wide and narrow viewports in both themes. - Android emulator. A layout change after scrolling issued 0 history reads, down from 16. A gesture fetched one page on the existing stream. Twelve pairs of unchanged controls and heartbeats produced 0 React commits, down from 21. Sending a message and resuming from the background advanced and restored the live checkpoint. - With 4,608 synthetic items, 32 exits from an unchanged cached thread required 0 full encodings, down from 32. In a 10,000-item renderer probe, median header-update processing fell from 3.10 ms to 0.007 ms. Forty-eight expanded outputs of 512 KiB retained 7.5 MiB of inactive content, down from 24 MiB. - Targeted domain, history cache, gRPC replay, continuity, work-window and mobile synchronization checks passed, along with web, mobile and domain typechecks and repository lint on the edited files. The concurrent-deletion test compares a paged-and-resumed client with a continuously connected client. - Copy audit (§8) passed. The former idle “Loading earlier work…” label now reads “Show earlier work” and acts as a button. “Loading earlier work…” appears during a read and “Retry” after failure. The native equivalent uses the existing “Show earlier messages” button. - The Windows Electron and day-long Windows session remain unmeasured. Native testing used Android. Additional Expo ESLint reported pre-existing hook findings. Fixes: #300 Fixes: #302 Fixes: #541 Fixes: #556 Fixes: #672 Fixes: #687
nixuuu
added a commit
that referenced
this pull request
Nov 28, 2026
## Change Mobile bot chats used the end of the rendered list to request older messages. Approval cards can predate the oldest loaded message, leaving the reader scrolling through Slack activity while earlier messages are still missing. Request the next page when the viewport reaches the oldest loaded message, including when a collapsed event group represents it. After a page arrives, check each visible row's key and position against the updated list so a stale scroll sample cannot trigger another request. ## Verification - On an Android API 36 emulator, a collapsed group above 48 older cards triggered one page request. Scrolling to the next boundary triggered one more. A longer conversation opened without a page request. The harness used the production list and paging hook with synthetic history. - Three tests passed across the gateway bot chat history and domain event group suites. Mobile typecheck and scoped lint passed. - iOS runtime behavior remains unverified locally. Repository-wide checks run in CI. Fixes: #302
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Web, Electron and mobile now request the latest 24 complete turns or 50 bot/exchange messages when no usable cache exists. Scrolling upward or choosing Show earlier messages grows the cached window, preserving the reader's position and the journal checkpoint. Cached content still renders first; actions and pending approvals wait for the main live state.
Thread search explicitly reads earlier pages through to the beginning and searches user inputs plus agent answers, including inherited history. Web results reveal the matching turn/item, and quoted-item navigation fetches missing history before opening its fold. The usage panel labels partial totals as Tokens of loaded turns. Offline linked threads page the local mirror; an opaque offline checkpoint preserves the loaded window until the home returns. Desktop bot-list reconciliation also removes unopened archived/deleted/moved bot projections from disk.
Measurements and restart findings
Fixture: real gateway/Postgres, 1,500 completed turns / 3,000 input-and-answer messages with approximately 2 KiB answer/tool-like text. Single samples on development clients, loopback link, warmed web code.
A cold web route compilation took 1,541.6 ms after the change; this is excluded from the warmed-code comparison. Android's initial 50-message bot tail took 428.1 ms and 118,257 protobuf bytes.
Actual Android force-stop/relaunch preserved both caches: thread reopen sent a 433-byte delta; bot reopen sent a 310-byte delta with zero messages. Cached bot content reached its first frame before that delta arrived. No cache key, epoch, startup eviction or disk-read-order defect was found. An obsolete dev binary initially buffered small streams; checks were repeated on the current EAS development build without rebuilding native code.
Web prepend kept a measured input row at exactly the same y position (164 px before and after). Bot prepend increased scrollTop by exactly the added content height (34,500 px).
Cache and compatibility
Mobile retains its existing separate budgets: threads 16 entries / 64 MiB on disk (16 MiB per entry), 6 / 24 MiB in memory; bot chats/exchanges share 16 / 32 MiB (8 MiB per entry). Storage is app-private Expo cache files, survives normal restarts, and may be evicted by the OS. Electron adds a shared 32-entry / 96 MiB private disk LRU, 16 MiB per entry. Browser content stays memory-only. Entries contain public, redacted projections; unpair/revocation clears both stores, and Electron mode changes clear persistence too.
Old clients and gateways continue full loads. Online linked-computer paging/cursors pass through to the home; offline thread reads page the mirror. Incompatible history or journal gaps replace the window with a fresh tail. No migration or new native dependency.
Verification
Rebased the complete stack onto the mobile motion changes (#297/#298) and floating composer (#292). The history footer retains the initial skeleton and empty-chat prompt. Thread and bot feeds keep their arrival animations, compacting composer and measured spacer. In newest-first histories, only keys before the first previously seen row can rise; appended older pages and replacements without overlapping rows appear immediately. Other animated lists retain their existing behavior.
Rebase verification: install, gen:check, typecheck, lint, format:check and Expo lint on each stage; full check:tmp and web production build on the top. Android Fold dev build against a temporary real gateway: 120 complete thread turns and 180 bot messages, multiple scroll-up page boundaries, recorded checks of stable anchoring and no arrival animation on older pages, retained floating-composer spacing. No native rebuild needed; the test pairing, servers and port forwards were removed afterward.
Full
check:tmp: 1,559 passed, 158 opt-in/live skips, zero failures; no project temp files left behind. All other top-stage gates passed.Copy audit: loading a full empty view → existing skeleton; Show earlier messages / Search thread name the action; Syncing… is quiet and reserves its space; Could not load earlier messages. Try again. states failure and recovery. Tokens of loaded turns avoids presenting a partial sum as a total. Sentence case, existing thread/bot glossary, accessible names and no humour. Short and long fixture content inspected at desktop/phone widths.
Limits and unverified work
No packaged Electron shell restart/paint measurement or physical-device measurement. Browser/native checks used development builds. Search is client-side and explicitly downloads earlier pages; it is not a server-side full-text index and does not search tool blobs. Mobile keeps its existing read-only search results (web results jump to the timeline); mobile has no pre-existing quoted-source reveal control. A single huge turn remains atomic, so its first page can still be large. These do not affect ordinary tail/delta reads.