Repository navigation
perf(web): cache recent thread snapshots between switches - #272
Merged
Merged
Conversation
nixuuu
marked this pull request as ready for review
November 6, 2026 11:52
nixuuu
added a commit
that referenced
this pull request
Nov 6, 2026
Opening a long bot conversation currently transfers every message again. This adds durable, owner-scoped checkpoints for bot conversations and bot-to-bot exchanges, so clients can request only changed messages and current control state. The bot tables have their own commit-ordered key journal, following the thread mirror epoch/cursor design. A checkpoint binds the owner, view and revision. Message edits, deletion and turn failures produce upserts/removals. A metadata digest confirms approvals, read state, pending cards, configuration, streaming text, routines and reminders; changed control state is replaced atomically. Missing/expired cursors, gaps, another epoch, rewritten exchange membership and moves fall back to a full projection. Linked bot reads pass the cursor to the home through the existing route. Offline reads retain the existing mirror path and gateway action enforcement. Proto additions are opt-in: old clients get full snapshots, and a home ignoring the new fields returns full state that new clients can apply. No link protocol version change. Migration 0091 is the next free number on the rebased dev; schema expectations and generated contracts are included. ### Measurements Single-run development-server measurements with a real local gateway/Postgres and 3,000 stored messages, each containing about 2 KB of long output. Browser first content is measured from route switch to message DOM appearing. SSE bytes include the ready frame and initial state, excluding HTTP/TLS headers and unrelated sidebar polling. The after column uses the whole stack, including the opt-in web client in the next layer. | Measurement | Before | After | |---|---:|---:| | Web warm switch, first content | 3,819.9 ms | 187.2 ms | | Initial bot SSE, unchanged reopen | 7,050,627 B | 393 B | | Web cold route, first content | 4,512.9 ms | 910.2 ms | | Initially mounted message rows | 3,000 | 100 | | Android first content / bytes | Unverified | Unverified | The baseline full protobuf was 6,772,217 B. Cold full history remains approximately 6.77 MB: this does not add server-side pagination. The cold browser sample includes development module loading; these are observations, not statistical latency bounds. Android timing and runtime visuals are unverified: the device tool's dev-client deep link failed with `COMMAND_FAILED: adb exited with code 1`, including its advised debug retry. No SSH/ADB UI fallback was used. ### Verification - Real-gateway integration and schema tests: 28 passed, including edits/deletes/failures, control confirmation, gap/epoch/view fallback, owner isolation, cursor after restart, linked chat/exchange, and a home ignoring the additive request fields. - `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`, `bun run format:check` passed on this stage after rebasing. - Polish protocol/read-path documentation updated. No new UI copy in this layer. The bot mirror publisher still uses its existing full projection protocol; this stack changes UI reads, not partner journal publishing. Live control metadata is a complete replacement when changed, rather than a second journal for approvals and linked thread cards. Related: #271, #272, #273.
This was referenced Nov 13, 2026
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.
Switching back to a recent thread now paints its cached conversation immediately, then opens the BFF stream with that snapshot's journal checkpoint. The cache holds raw protobuf state and applies the shared reducer; unchanged timeline entries keep their identities during live handoff. Reconnect computes a fresh cursor URL, and a mismatched base retries with full state.
The SPA keeps an LRU of 12 threads / 64 MiB encoded protobuf bytes, in memory only. The current screen owns its state separately. No IndexedDB or localStorage is used. The cache clears on document departure and app-shell destruction, including desktop connection selection. Actions continue to reach the authoritative gateway and its current-state checks.
Two synthetic 500-turn / 3,001-item threads, actual development browser and BFF, real gateway and isolated Postgres:
Warm content appears before the network reply. A cold control still took 346 ms / 6,952,212 B. Numbers exclude transport/framing and are synthetic development measurements, not production guarantees. Long local browser rendering did not justify a separate tail-loading stage here.
Verification: install,
gen:check, typecheck (0 Svelte errors/warnings), lint and formatting passed. Top-of-stackcheck:tmp(1,490 passed / 159 skipped / zero failures), web build and Expo lint passed. Visually checked the real browser at 1280×800 and 390×844 in light and dark, including actual title/model/worker, long text and horizontal overflow. With SSE delivery delayed by 2.5 seconds, cached content and the quiet local Syncing state stayed visible; scrollTop remained 54,355 and the first article kept the same DOM node after live handoff. No UI test suite was added. Protocol integration coverage is in the first layer.Copy audit (§8): initial “Connecting…” text → existing timeline skeleton; a warm conversation uses the existing quiet “Syncing…” state. Known thread metadata remains visible. No new glossary term, decorative sentence or colour-only state. Draft stack; do not merge individual layers.