Repository navigation
perf(bots): cache web history and open the latest messages - #289
Merged
Merged
Conversation
nixuuu
marked this pull request as ready for review
November 6, 2026 19:11
nixuuu
force-pushed
the
perf/bot-cache-2
branch
from
November 6, 2026 19:14
c0c2b9c to
e2045e2
Compare
nixuuu
added a commit
that referenced
this pull request
Nov 6, 2026
Mobile conversations used a solid composer block that shortened the timeline. Composers now float above the feed and fold while reading history; the main screens also extend their backgrounds and scroll viewports behind the system bars while keeping controls inside safe areas. Rebased onto `dev` after the mobile UI kit landed (Related: #287). Its shared buttons, notices, search/form controls, confirmation host and sheet title/close controls are preserved. Connection banners now participate in the floating header measurement on threads, bot chats, sidebar and Settings. The extracted sidebar footer uses #287's interactive connection status with details and retry; Settings retains its density provider. Full sheets keep the kit's 20 dp content spacing inside the inset-aware modal frame. The final rebase also includes the bot-history changes that landed meanwhile (Related: #288, #289, #290). Bot chats retain the snapshot cache, incremental updates, cached bot names, loading header/avatar, syncing subtitle and live-only approval/send/stop guards beneath the floating layout. ## Composer behavior - Match web `ComposerCompaction`: fold after 96 dp of travel toward older messages, at least 192 dp from the end; expand within 8 dp of the end or on tap, focus, or typing. Only reader gestures fold it; streaming and layout changes do not. Synchronous questions keep it expanded. - Match `VirtualFeed.reservedFooter`: measure the full overlay, retain its largest reserve while reading history, and follow its height at the latest end. The changing spacer is excluded from the visible-message anchor. The latest-message action remains above the composer with an actual Android touch area. - Reuse the web surface, border, light-theme shadow and 32 dp canvas fade. Animate folding with shared 400/350 ms tokens and `smoothOut`; reduced motion uses zero duration. Inputs and folded controls stay mounted. - Mobile additionally keeps any draft, attachment or mention picker expanded, so compaction cannot hide unfinished input. Bot chats retain their native inline pill. This is a deliberate difference from web's ability to fold a draft to one line. ## Insets by screen | Screen | Layout and control insets | | --- | --- | | Thread and existing side thread | Full-window inverted feed under a translucent floating header and composer. Oldest end reserves the measured header plus top inset; latest end reserves the measured composer including bottom inset. Composer controls have side/bottom padding. | | Bot chat | Same overlay, compaction, reserve and safe-area rules as threads, with the inline bot composer. | | Sidebar and thread/bot lists | Full-height list under measured floating header/footer. Content padding makes first/last rows reachable. Footer controls sit above the home indicator. Only the outside edge of each split pane consumes a horizontal inset. | | New thread and side-thread creation | Expanded forms because there is no conversation history to compact. New thread scrolls under its floating header; side-thread creation uses the modal frame. Form content gets safe-area padding. | | Settings | Both columns scroll behind the floating header. Navigation consumes the left outside inset, details the right; a single column consumes both. Forms retain keyboard-overlap handling. | | Pairing and empty home pane | Full-window background and scroll viewport, with content padding protecting controls at both ends and sides. | | Full sheets and compact pickers | Full sheets measure their own modal safe area and scroll under the header. Bottom pickers extend their surface behind the home indicator and inset actions; centered landscape/Fold cards fit the safe rectangle. | `KeyboardArea` keeps its existing keyboard `screenY` calculation. Closed-keyboard safe-area padding now belongs to scroll content and composer controls instead of the viewport. Status-bar icons continue to follow the selected light/dark theme; translucent header surfaces maintain contrast above scrolling content. No new native dependency or native configuration change. ## Verification Reran after the final rebase onto `cf9f6be2`: `bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`, `bun run format:check`, `bunx expo lint` from `apps/mobile`, and the web build. All passed. Expo refreshed the ignored generated route list for the newly merged exchange screen before the passing typecheck. Final `bun run check:tmp`: **1534 passed, 158 skipped, 0 failed**, 1692 tests across 274 files; no test temp directories left behind. The full test run uses a private `TMPDIR` inside the ignored worktree temp directory, with `GIT_CEILING_DIRECTORIES` set to that directory. This prevents deliberately non-Git fixture folders from discovering the checkout above them. Live/provider tests remain opt-in. Self-review and `git diff --check` are clean. Android Fold device observations before the final edge-to-edge expansion: light/dark surfaces, long history, content passing below the composer, folding on scroll, expanding on tap/focus and return to latest, functioning latest-message action, and a visible multiline draft. Screenshots are kept outside the checkout. The recording exporter failed after its documented debug retry. After the UI-kit rebase, the source launched in the free Android Fold emulator using the existing development client. Smoke-checked the edge-to-edge shell in light and dark, readable status icons, inset sidebar footer, the offline connection banner and its details/retry overlay, plus Settings search with the real keyboard open and closed. After the final bot-cache rebase, the bot-chat screen also rendered its loading header and floating composer. The old fixture gateway was offline, so live conversation behavior was not rechecked. Multiline entry could not be verified: Android's `system_server` aborted during the fill attempt, and the tool's debug retry could not find the field after the reset. No new native build or download was needed; the owned emulator and Metro session were shut down afterwards. Device QA remains incomplete: the earlier iOS development-client launch timed out twice, and its notch/Dynamic Island layouts remain unverified. Phone width, conversation keyboard handling, drafts with attachments and mention suggestions, bot/side-thread flows, reaching the bottom during streaming, reduced motion, landscape and Android three-button navigation still need device coverage. The rebase smoke check does not replace those checks. Copy audit (`docs/copy.md` §8): no new user-facing copy; existing English action labels and form text are preserved. No web UI tests or permanent verification artifacts were added. Shared mobile buttons, notices and form controls retain #287's implementation; only the shared sheet's layout delegates to the new modal frame.
nixuuu
added a commit
that referenced
this pull request
Nov 10, 2026
## Change Bot chats now choose their latest visible entries after messages and approval cards have been ordered together. Later user messages, bot replies and routine notifications remain visible after a long history of approvals forwarded from bot-started threads. The root cause is the interaction between `botEntries` and the 100-entry web window introduced in #289. `botEntries` returned messages followed by all approvals. `ChatView` sliced that array before `layoutChat` sorted it. With 50 loaded messages and 105 older approval cards, the selected window contained only approvals, even though the gateway and sidebar had the latest reply. Sorting inside `layoutChat` could not recover discarded entries. The shared projection now orders entries by creation time before callers window them, using the same ordering as the existing layout. The gateway's descending `seq` tail query, cursor/delta merging and routine `message_user` rows retain the latest messages; regression coverage exercises these paths through the real gRPC API and PostgreSQL. Approval resolution does not reorder cards. Mobile already lays out the complete loaded projection before reversing it and does not apply the web's slice; shared domain coverage confirms its last row agrees with the web. The fix is TypeScript only and adds no RPCs, queries, migrations or native changes. ## Verification - Regression failed before the fix: the latest user, bot and routine messages were absent from the visible window. Added domain and real gateway tests for forwarded approvals, the bounded initial page, sidebar agreement, cached deltas, later messages and older-page merges. - `TMPDIR=/var/tmp bun test packages/domain/src/bot-chat/layout.test.ts tests/integration/bot-chat-history.test.ts tests/integration/bot-view-deltas.test.ts`: 9 passed, 0 failed. Existing delta coverage includes restart, linked homes and owner/view scoping. - `bun install --frozen-lockfile`, `bun run typecheck`, `bun run lint`, `bun run format` and `bun run format:check` passed. Fixed the new fixtures' lint spacing findings before the final clean runs. - Real browser with an isolated seeded gateway and scripted worker: temporarily restoring the original projection rendered zero message rows and approved cards at the bottom while the sidebar showed the routine reply. Restoring the fix rendered all 50 loaded messages, with the same latest routine reply as the sidebar. Checked light/dark at 1280×800 and 390×844; the last message remained visible at the bottom without horizontal overflow. Temporary servers and browser tab were closed. - Full-suite `check:tmp`, generated-code checks and production builds remain CI gates per the task's shared-machine limits. No packaged macOS or native mobile device run; the affected colleague's database was unavailable. No new UI text or UI test suite. Fixes: #289
This was referenced Nov 13, 2026
nixuuu
added a commit
that referenced
this pull request
Nov 18, 2026
## Changes - Scope cached and live history to the selected bot or exchange. Switching from a long chat to a shorter one opens the latest messages immediately. - Render both bot chat views with the same virtual feed as threads. Approaching the oldest loaded message fetches up to 50 more messages and keeps the visible row anchored. A failed fetch offers a retry. - Resolve citations to virtual rows and preserve in-progress approval edits and free-text answers across row unmounts. - Make Home and End jump directly to the destination while the scroll area has focus. Rapid alternation can otherwise paint an empty window while Chromium animates across unmounted rows. ## Verification - Rebased on current `dev`. Scoped web typecheck, lint, formatting and diff checks passed. - `bun run check:tmp` passed all 13 tests in `bot-chat-history.test.ts`, `history-pages.test.ts` and `thread-scroll.test.ts`. - Ran the web app with an isolated gateway and PostgreSQL in Chromium at 1280 px and 390 px in light and dark mode. Checked cold and warm switches, six automatically loaded pages, scroll anchoring, retry, exchange history, citation reveal and draft retention. - Built and ran Canopy Desktop in local mode on Linux using Electron 45.2.1. With 1,250 messages in the long chat, 37 of 351 loaded rows were mounted after six pages. Verified switching to a 14-message chat, returning to the latest message and resuming the saved history after restart. - Recorded rapid wheel scrolling, reversals and alternating Home and End in the Linux app. After the keyboard fix, none of 361 captured frames showed a blank message area. Packaged macOS verification remains open. - Repository-wide checks and CI builds remain with GitHub Actions. ## Copy audit Passed the checklist in `docs/copy.md`. Removed “Show earlier messages” because scrolling now loads the next page. Kept “Loading earlier messages…” as the progress announcement. Changed “Could not load earlier messages. Try again.” to the status “Could not load earlier messages.” with a separate “Try again” action. Reused “Jump to latest” from threads. Checked text, wrapping and truncation with short through long bot names at both widths. Fixes: #289
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 bot conversation or exchange now shows its in-memory snapshot immediately and reopens with its checkpoint. The header uses the bot directory/cache for the real name and avatar. Cached messages stay mounted while the live delta arrives; send, approval, retry and stop actions wait for live state.
The separate bot LRU holds up to 16 chats/exchanges and 32 MiB of encoded state, with an 8 MiB entry limit. It is cleared with the SPA shell/pagehide and reconciled against archived, removed and moved bots. There is no IndexedDB. Bot chats and exchanges initially mount the latest 100 entries; “Show earlier messages” reveals 100 more while preserving the scroll anchor. Exchanges refresh on open/focus and every 5 seconds while visible.
Measurements
Same 3,000-message fixture and measurement method as the bottom PR. These are single-run local development observations; cold route timing includes module loading.
Verification
Copy audit (§8): blank/Connecting timeline → skeleton plus quiet “Syncing…”; “Show earlier messages” names the action; refresh failure gives a reopen action. Sentence case, glossary, punctuation and short/long-name layouts checked. No new glossary terms or special voice exceptions.
Cold full history remains large; the DOM window reduces initial rendering work without changing the complete cached projection. Old homes continue to return full state.