Skip to content

perf(bots): persist mobile chats and exchange snapshots - #290

Merged
nixuuu merged 1 commit into
perf/bot-cache-2from
perf/bot-cache-3
Nov 6, 2026
Merged

nixuuu merged 1 commit into
perf/bot-cache-2from
perf/bot-cache-3

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Mobile bot chats and bot-to-bot exchange views now keep their latest projection and checkpoint across app restarts. Opening a view shows memory/disk content first, then applies only the gateway delta. Cached pending approval cards are display-only until a live subscription confirms them; the mutation boundary also checks live/pending state, including “Always allow”.

Chats and exchanges share a separate bot budget: 16 views / 32 MiB on disk, 8 MiB per entry, and 6 views / 16 MiB in memory. This is independent of the thread cache. Storage reuses the existing atomic expo-file-system adapter in the app-private Paths.cache directory, isolated by device and certificate pin. No native dependency or rebuild is needed. The OS may evict cache files; corruption or a missing entry falls back to the full load. Oversized views still work online but are not kept.

Unpair and detected revocation fence both caches before deleting disk state and credentials, preventing late writes from restoring content. Bot list reconciliation removes archived, deleted and moved bots and their exchanges. Only public bot projections are stored; connector credentials, provider configuration, model checkpoints and the device token stay out of the cache. Offline devices cannot detect revocation until reconnect.

The header uses the real bot name/avatar from cached state or the directory. Cold views reuse the existing generic Skeleton/ConversationSkeleton building blocks. Exchange links now open a read-only native history screen, refreshed incrementally every 5 seconds while active. Polish mobile, bot and UI API docs are updated.

Measurements and limitations

The web comparison for the complete stack is 3,819.9 → 187.2 ms to first content, and 7,050,627 → 393 B for an unchanged reopen of the 3,000-message fixture. Cold web route: 4,512.9 → 910.2 ms. See the bottom PR for the measurement method and limits.

Android before/after first-content timing, wire bytes and runtime appearance remain unverified. The emulator session opened, but the device tool could not open the dev-client deep link: COMMAND_FAILED: adb exited with code 1; its advised debug retry failed too. Device interaction stopped there, without taking another session or using SSH/ADB for UI control. No native rebuild was performed. The owned session and port forwards were cleaned up.

Verification

  • Real paired-device TLS/gateway tests plus durable disk cache tests: 7 passed together with thread cache coverage. They cover restart/LRU/byte limits/corruption, archive/move/removal, late writes during unpair, cached pending approvals blocked before live, successful live response and rejection after resolution, credential-free persisted payloads, and cache clearing after actual gateway revocation.
  • All stage gates passed: install, generated-contract check, typecheck, lint and formatting. Expo lint and Expo Doctor passed (20/20 checks); Android and iOS bundle exports and CNG prebuild passed. Generated native directories and exports are not committed.
  • Top-of-stack web build passed. Final full check:tmp: 1,534 passed, 158 skipped, 0 failed (10,535 assertions across 274 files); nothing left in the checked temp directory.
  • Browser verification on the previous layer covers light/dark, desktop/phone, cold skeleton and delayed live replacement without scroll movement.

Copy audit (§8): temporary Bot/Connecting values → real name/avatar and skeleton; cached state uses quiet “Syncing…”. New exchange labels reuse existing bot vocabulary. Errors give a retry/reopen action. No new glossary term. Native text wrapping, accessibility and light/dark runtime appearance remain unverified because of the device tool failure.

Remote bots pass their checkpoint through to the home; old gateways may ignore it and return full state. The existing bot mirror publisher remains unchanged.

@nixuuu
nixuuu added this pull request to stack #291 November 6, 2026 19:00
@nixuuu
nixuuu marked this pull request as ready for review November 6, 2026 19:11
@nixuuu
nixuuu merged commit cf9f6be into dev Nov 6, 2026
9 checks passed
@nixuuu
nixuuu deleted the perf/bot-cache-3 branch November 6, 2026 19:18
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.
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.

1 participant