Skip to content

Write what the apps receive into a client cache (851-4468) - #1478

Merged
dylanplayer merged 5 commits into
mainfrom
dylan/851-4468-client-database-cache-what-the-apps-have-seen
Nov 27, 2026
Merged

dylanplayer merged 5 commits into
mainfrom
dylan/851-4468-client-database-cache-what-the-apps-have-seen

Conversation

@dylanplayer

Copy link
Copy Markdown
Member

Fixes 851-4468 (part 1 of 2)

The Mac and iOS apps now write what they receive from the machines into real tables in client.sqlite. Nothing reads them yet, so nothing visible changes. PR 2 adds the read path, behind a setting.

What's stored

New cache_* tables in client.sqlite, under Persistence/ClientCache/:

Table Filled from Notes
cache_machines, cache_projects, cache_workspaces, cache_chats, cache_panes, cache_checkouts every navigation snapshot and delta (NavigationCacheStore) Diffed against the last write, so a delta only touches changed rows. Each row has key columns plus the server record as JSON, so reading back is lossless.
cache_transcripts, cache_transcript_items the open response, every transcript page the app fetches, and a head-page refresh when a turn ends Pages stitch into one contiguous window per chat. A refresh that doesn't overlap replaces older items instead of leaving a gap. Items the server rewrote or dropped are removed.
cache_attachments (+ files under Caches/ClientCacheFiles) attachment refs in transcript items, plus the bytes of any attachment or preview the app downloads
cache_queued_sends the send queue on every change Removed once delivered

Only the app changes: no server or protocol changes. The client gained transcriptPageReturningData (same endpoint, keeps the raw JSON) and a page receiver on ServerSessionTransport.

Disposable by design

  • The cache has its own schema version (client_cache.schema_version in client_metadata), separate from the numbered client.sqlite migrations. It is not migration 2: a numbered migration would make an older build refuse to open client.sqlite. On a version mismatch the app drops every cache_* table and recreates them. Preferences and client_values are untouched (tested).
  • If a cache write fails, the app logs it, rebuilds the cache, and rewrites the sidebars it holds.
  • The cache uses its own SQLite connection and a background serial queue, so it never blocks the main thread or the preferences connection.

Bounded size

  • Transcripts not opened in 30 days are dropped. Total transcript size is capped at 64 MB, dropping the least recently opened first. Each chat keeps at most 400 items, and older pages stop being cached past that.
  • Files not used in 30 days are deleted. Total files are capped at 200 MB, deleting least recently used first. Files over 25 MB are not cached.
  • Queued sends older than 7 days are dropped. Transcripts of chats a machine no longer lists are dropped.
  • Trim runs at launch and every 50 writes.

Verifying the data matches what the app shows

Development builds audit every write and log the result under the client-cache category:

  • Sidebar: after each write, the snapshot is read back from the tables and compared record by record with the snapshot the sidebar renders from.
  • Transcript: after each turn-end refresh, the cached page is run through the same mapper the app uses. Its item ids are compared with the items on screen.
# Mac
/usr/bin/log stream --predicate 'subsystem == "com.851labs.codevisor" AND category == "client-cache"'
# iOS simulator
xcrun simctl spawn <udid> log stream --predicate 'subsystem == "com.851labs.codevisor" AND category == "client-cache"'

A mismatch logs a fault: Client cache differs from …. The tables can also be read directly with sqlite3 <app support>/client.sqlite.

Tophat

Real Mac dev app and iOS simulator (bun run dev:ios), real Codex sign-in (GPT-6 models), no mocks.

  • Mac: started a chat ("Five fruits"), relaunched, reopened it, and sent a follow-up. The audit logged Client cache matches chat 36fb… on local: 4 shown items, 4 cached and matches sidebar of local: 1 workspaces, 1 chats. In cache_transcript_items, the four rows match the screen: prompt, fruit list, prompt, vegetable list.
  • iOS: opened the same chat, then started a new chat in that workspace and sent it ("List two colors"). The audit logged matches chat 150c… : 2 shown items, 2 cached and matches sidebar … 1 workspaces, 2 chats. Both transcripts are in the simulator's tables. cache_queued_sends was empty after delivery, as expected. There were 0 differs lines on either platform.
  • Found and fixed during tophat: new chats run on draft controllers, which never got the cache, so the first chat wasn't recorded. They now get it.
  • No visible change: the sidebar and transcripts look the same as before on both platforms.
  • Not exercised in the app: opened-attachment files and queued sends while unreachable. Both are covered by unit tests (ClientCacheTests). PR 2's offline tophat will exercise queued sends.

Tests

ClientCacheTests and ClientCacheTranscriptTests cover:

  • the sidebar written through a real NavigationStore (snapshot, then delta) reading back equal to delta.applying(to:)
  • forgetting a machine
  • a schema mismatch wiping only the cache
  • pages stitching, gaps, dropped items, and stale pages
  • the per-chat item limit
  • transcript aging
  • the file budget

The neighbouring Session, Navigation, ClientDatabase, ClientStorage and Transcript suites pass.

🤖 Generated with Claude Code

@dylanplayer
dylanplayer force-pushed the dylan/851-4468-client-database-cache-what-the-apps-have-seen branch from f3e7713 to e00dc01 Compare November 26, 2026 02:07
@dylanplayer
dylanplayer force-pushed the dylan/851-4468-client-database-cache-what-the-apps-have-seen branch from e00dc01 to c350948 Compare November 26, 2026 21:29
dylanplayer and others added 5 commits November 26, 2026 13:51
The sidebar snapshot per machine, transcripts of opened chats, attachment
metadata and opened files, and queued sends are written through to new
cache_* tables in client.sqlite. Nothing reads them yet. The cache has its
own schema version and is wiped and rebuilt on mismatch or a failed write,
and old transcripts and files age out. Development builds audit every write
against what the app holds and log the result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Draft controllers, which carry every new chat through its first send, now
get the client cache like existing chats do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every attachment the apps fetch goes through CodevisorServerClient, so the
client writes the bytes into the client cache there, keyed by machine and
file id. The lightbox, thumbnails and workspace media all fetch through it;
recording only in the session controller missed the lightbox and inspector.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dylanplayer
dylanplayer force-pushed the dylan/851-4468-client-database-cache-what-the-apps-have-seen branch from c350948 to b9923bd Compare November 26, 2026 21:51
@dylanplayer
dylanplayer merged commit ac31daf into main Nov 27, 2026
@dylanplayer
dylanplayer deleted the dylan/851-4468-client-database-cache-what-the-apps-have-seen branch November 27, 2026 04:34
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