Skip to content

Render the sidebar and opened chats from the client cache first (851-4468) - #1487

Merged
dylanplayer merged 3 commits into
mainfrom
dylan/851-4468-read-client-cache
Nov 27, 2026
Merged

dylanplayer merged 3 commits into
mainfrom
dylan/851-4468-read-client-cache

Conversation

@dylanplayer

@dylanplayer dylanplayer commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Fixes 851-4468 (part 2 of 2). Stacked on #1478: review only the commits after it.

The Mac and iOS apps now render from the client cache first. The sidebar and workspace list load from the cache tables at launch, and opening a chat you've seen shows its cached transcript immediately, before and without any connection. The live connection then replaces it in place. There's no switch: it's always on, and alpha is the safety net.

What changed

  • Sidebar from the tables. NavigationCacheStore loads and saves through ClientCache (the cache_* tables from Write what the apps receive into a client cache (851-4468) #1478) instead of the per-machine JSON blobs in client_values.
    • On the first launch with this build, the old blobs are imported into the tables once and then removed (LegacyNavigationCacheImport).
    • Each machine's last written snapshot is kept in memory, so later deltas only write changed rows.
  • Chats from the cache. SessionController shows the cached transcript as soon as an existing chat is configured (showCachedTranscript), not only inside the connect path.
    • The connect path reuses that display only if it was built on the same client. A display built while the machine was unreachable (placeholder client) gets a fresh live model when the machine returns.
    • iOS also swaps in the real client for a controller created while unreachable (replaceUnreachableClient).
  • iOS no longer blocks on the machine. The workspace screen builds its panes and chat controller while the machine is unreachable, and only the connect step waits for availability. So a chat you've seen shows its transcript instead of "Connecting to ". Chats with nothing cached still show the existing connecting / can't-reach screen, unchanged.
  • The Mac opens into its cache. When the cache has content, the launch cover is skipped and the window opens straight into the cached sidebar and chats (LaunchGate, hasCachedContent). Connection state shows only through what main already has: the inline "Reconnecting…" line and the sidebar's Syncing indicator. With an empty cache the cover behaves as before.
  • Attachments you've opened show offline. CodevisorServerClient.fileData / filePreview read the cached bytes first and only fetch on a miss.
  • Old transcript file cache removed. TranscriptPageCache (30 files in Caches) is removed and its directory is cleaned up at launch.

No server or protocol changes, and no UI redesign: every screen is an existing one. The only visible difference is that cached content appears where a connecting screen or the Mac launch cover used to.

Disposable, wipe and refill

The rules from #1478 still hold, and now they matter at read time too. A cache from another schema version is dropped. A row that fails to decode at launch rebuilds the whole cache. In both cases the app refills from the machines, so the worst case is the sidebar loading from the network as it did before.

Tophat

Real Mac dev app and iOS simulator (bun run dev:ios), real Codex sign-in, no mocks. Screenshots are on the Linear ticket.

Offline (the before/after). Dev server and dev cloud stopped (the Mac's machine unreachable, nothing for the iPhone to reach), iPhone app cold-launched:

  • Before (the Write what the apps receive into a client cache (851-4468) #1478 build, same read path as main): the sidebar showed (old blob), but opening "List two colors", which the iPhone had opened earlier, stayed on "Connecting to Mac App (spearmint)" with no transcript, even after 40 s.
  • After: the sidebar showed all 341 workspaces from the tables in 5.4 s. Opening "Five fruits" showed the full transcript up to the latest turn, entirely from the cache.

Mac offline cold launch (the before/after). The dev app was quit, then started on its own with no server and no cloud: the CodevisorUsesStandaloneServer pref makes it wait for an external server, and nothing was listening. The real server was started later by hand from the same data.

main this PR
Launch "Codevisor Couldn't Start" cover (Try Again / Continue Anyway) Straight into the cached sidebar with Syncing…, last chat open
Chat seen before ("Long chat", "Five fruits") Only after Continue Anyway, from the old 30-file transcript cache, with the red "Waiting for this Mac's Codevisor server to start" banner Full transcript from the cache tables with "Reconnecting…"
Attachment opened before (codevisor-icon.png) "Preview unavailable" Thumbnail and lightbox show the image
Chat never opened on this Mac "Waiting for the server..." "Waiting for the server..." (unchanged)
  • Server back: the open chat dropped "Reconnecting…" and loaded its models, and Syncing cleared. A message sent from the Mac composer ("Name the fourth planet") streamed back the real reply ("Mars"). The never-opened chat loaded its real transcript in place.
  • Wiped cache: schema version set to 999 with the app quit, then a normal bun run dev launch. The launch dropped every cache table and the cached files, and kept the app's 4 preferences and 30 values. The sidebar refilled to 345 workspaces / 346 chats (Client cache matches sidebar of local). Reopening "Five fruits" and its image re-cached the transcript and the 28 KB original. This found a bug fixed in Write what the apps receive into a client cache (851-4468) #1478: a wipe used to leave the cached files on disk, outside the size budget.

Server frozen (dev server sent SIGSTOP; tunnel up, every request hangs):

  • iPhone: tapping a seen chat showed its full transcript within 2 s.
  • After SIGCONT, the same chat went live. A prompt sent to it streamed the real reply ("Lemon") into the open chat, and a message sent from the iPhone composer went through.
  • Mac: reopening "Long chat" with the server frozen showed it in 0.7 s. The Mac also keeps recent chats in memory, so the iPhone cold launch is the cache-only proof.

Large account. 300 workspaces plus a 30-turn real Codex chat, created through the dev server's own API:

  • Sidebar audits matched at 342 workspaces / 343 chats on both apps.
  • The long chat caches its newest page (24 items), with the page cursor recorded for older pages.
  • The iPhone cold-launched to the full sidebar in 5.4 s offline (about 7 s online under a machine load average of 40–70). Reading the cache was about 20 ms of that in a sample.
  • Not caused by this change: the Mac took minutes to catch up while 300 workspaces were created in a burst. A sample shows the main thread busy in SidebarWorkspaceSection.body / ProjectGroup.grouping (debug build), with no cache or SQLite frames on the main thread.

Wiped / mismatched / corrupt cache:

  • iPhone: schema version set to 999 with the app quit. Next launch dropped the cache tables (version back to 1, the 4 preference rows untouched). The tables refilled to 342 workspaces / 343 chats once the machine answered, and the audit matched.
  • Mac: one cache_chats payload overwritten with invalid JSON. Next launch logged navigation.load failed; rebuilding the cache, refilled to 342 / 343 with a matching audit, and kept the app's own preferences and values (4 / 30 rows).

Regression checks:

  • Sending from iOS and Mac online.
  • New chats on iOS.
  • Cross-device updates: a turn from the iPhone appears on the Mac.
  • The turn-end transcript audit matched (6, 10 items).
  • The "Failed" badges in the screenshots are the server's own state (sessions.sidebar_state = errored in the server DB, from stopping the runner mid-session), not client state.

Not covered in-app:

  • Scrolling up into older pages in the app (AX scrolling didn't move the transcript); page stitching is covered by ClientCacheTranscriptTests.

Tests

  • New: the Mac opens straight into cached content (LaunchGateTests). An attachment opened before still loads when its machine is unreachable (ClientCacheTests).
  • New: a chat shows its cached transcript before anything connects, and a display built while unreachable is replaced by the live chat on reconnect (SessionControllerTranscriptCacheTests). Old sidebar blobs import once (ClientCacheTests).
  • Updated to the tables: the launch snapshot, cached-launch and relaunch navigation tests, which used to rely on the blobs.
  • ClientCache, Launch, Navigation, SessionController and MachineController suites pass. In full parallel runs on this machine, a handful of timing tests (main-thread read checks in ClientPreferences, CloudCredentialCache, CloudMachineKey*, ClientLaunchSnapshot, plus SessionModel's optimistic-send) fail intermittently. A clean origin/main checkout fails the same set on the same machine, and main's CI Build is green, so they come from load, not this change.

🤖 Generated with Claude Code

@dylanplayer
dylanplayer changed the base branch from main to dylan/851-4468-client-database-cache-what-the-apps-have-seen November 26, 2026 02:09
@dylanplayer
dylanplayer force-pushed the dylan/851-4468-client-database-cache-what-the-apps-have-seen branch 2 times, most recently from c350948 to b9923bd Compare November 26, 2026 21:51
@dylanplayer
dylanplayer force-pushed the dylan/851-4468-read-client-cache branch from abab5ae to 9923857 Compare November 26, 2026 21:53
Base automatically changed from dylan/851-4468-client-database-cache-what-the-apps-have-seen to main November 27, 2026 04:34
dylanplayer and others added 3 commits November 26, 2026 20:34
The sidebar loads from the cache tables at launch (the old snapshot blobs
are imported once and removed), and an existing chat shows its cached
transcript as soon as it is opened, before and without a connection. The
live connection then replaces it. On iOS a chat whose machine is
unreachable now shows its cached transcript instead of the connecting
screen. The old per-chat transcript file cache is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The turn-end audit runs only after the page refresh succeeds, so a failed
fetch doesn't report a false mismatch. Tests that relaunch a navigation
store now share a client cache across the relaunch, since the sidebar no
longer persists through the old snapshot blobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When the client cache has content, the Mac's launch cover steps aside
right away instead of waiting for this Mac's server, so the app opens into
what it last knew; server state shows through the existing inline banner and
Syncing indicator. Attachments are served from the cache before the network,
so an image opened before still shows in the lightbox while its machine is
unreachable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dylanplayer
dylanplayer force-pushed the dylan/851-4468-read-client-cache branch from 9923857 to 0f74c4c Compare November 27, 2026 04:37
@dylanplayer
dylanplayer merged commit dbd3222 into main Nov 27, 2026
@dylanplayer
dylanplayer deleted the dylan/851-4468-read-client-cache branch November 27, 2026 04:37
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