Skip to content

refactor(sqlite): share one row cache across the SQLite-backed caches - #40028

Merged
nwparker merged 1 commit into
mainfrom
nwparker/sqlite-row-cache-consolidation
Nov 9, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/sqlite-row-cache-consolidation

Conversation

@nwparker

@nwparker nwparker commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

#39995, #39993 and #39997 each moved a JSON restart cache to SQLite, and each grew its own legacy-file import, startup read, changed-row writer and retry logic. This replaces those with one shared module, src/main/sqlite/row-cache/:

  • KeyedJsonRowCache handles the startup read, which goes over a read-only connection.
  • It writes only changed rows, reading the baseline and data_version in one transaction.
  • The import receipt is committed in the same transaction as the imported rows.
  • Corruption triggers one rebuild with fail-fast removal.
  • legacy-json-source.ts: absent / unreadable / read, with the receipt as a sha256 of the file bytes.
  • row-cache-failure.ts: busy / corrupt / other classification and backoff.

Each store keeps only its own policy:

  • Agent status: saves ownership changes immediately, and disables persistence for the session if startup can't read the cache.
  • GitHub cache: profile fences and barriers, and the 3-minute interval.
  • Dismissals: queues events while history is unread.
  • Model catalog: coalesces writes over 500 ms.

The diff is +859 / −1,265 lines.

Edge cases now handled the same way in every store

  • A corrupt or rejected legacy file keeps the stored rows. Dismissals and the catalog used to wipe them.
  • A legacy file that exists but can't be read makes the store unavailable for the session, rather than being treated as absent and later overwriting newer rows.
  • Receipts no longer include mtime, so a copied or restored leftover file is still recognised. Receipts written by perf(persistence): store notification dismissals and the model catalog as SQLite rows #39997 are still recognised.
  • If rows or the legacy file can't be read, nothing is saved that session and no file that wasn't loaded is deleted. The GitHub cache used to delete its sidecar unread in this case.
  • File and directory hardening is uniform, and the GitHub startup read no longer throws from inside its catch.

Compatibility

  • The agent-status cache moves to schema 202 and the GitHub cache to schema 2, so each rebuilds empty once. Both are restart caches and refill on their own.
  • Dismissals and the catalog keep their data.

Testing

  • Checks: typecheck, pnpm lint (43 steps) and the sync-fs ratchet pass. The baseline shrinks from 11 entries to 3.
  • Vitest: across sqlite, agent-hooks, persistence, push, agent-session, native-chat and ai-vault, 3,497 tests pass.
  • Shared behaviour tests replace the per-store copies of the migration and corruption tests. They cover:
  • Review: two rounds of independent Codex (gpt-6.1-sol) review. It found four regressions against the per-store versions, all fixed. The final round rates merge risk low.
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178 $\color{#cf222e}{\Huge{\mathbf{−}}}$​124 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​54
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​681 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1141 $\color{#cf222e}{\Huge{\mathbf{−}}}$​460

The last-status, GitHub cache, notification dismissal and model catalog stores each grew their
own legacy-file import, read-only startup read, changed-row writer and retry backoff. They now
share src/main/sqlite/row-cache/ (KeyedJsonRowCache with load/write, the legacy JSON source,
one failure classifier and backoff); each store keeps only its cadence and fencing policy.

Edge cases now behave the same in every store:
- a corrupt or rejected older-build file keeps the stored rows (it no longer wipes them);
- an older-build file that exists but cannot be read is never treated as absent;
- the import receipt is the file's content hash, without its mtime, so a copied leftover is
  still recognised as imported;
- while the rows or that file cannot be read, the store saves nothing that session and never
  deletes a file it did not load (dismissals keep retrying, as before);
- files are user-only and hardened everywhere.

The last-status and GitHub caches move to the shared row layout, so each rebuilds empty once.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 472dc4ec-12c4-4377-b6c1-384f95b1eb4d
Commits

Reviewing files that changed from the base of the PR and between 47b4238 and b325e5f.

Files selected for processing: 27

  • config/main-sync-fs-baseline.txt
  • src/main/agent-hooks/server/last-status-legacy-file.ts
  • src/main/agent-hooks/server/last-status-saved-rows.ts
  • src/main/agent-hooks/server/last-status-store.ts
  • src/main/agent-hooks/server/server-persistence.ts
  • src/main/agent-hooks/server/testing/persistence/last-status.test-fixtures.ts
  • src/main/native-chat/agent-model-catalog/agent-model-catalog-persistence.ts
  • src/main/persistence/loading-store/github-cache-database.test.ts
  • src/main/persistence/loading-store/github-cache-database.ts
  • src/main/persistence/loading-store/github-cache-persistence.ts
  • src/main/persistence/loading-store/github-cache-sidecar.ts
  • src/main/persistence/loading-store/github-cache-startup-read.ts
  • src/main/persistence/loading-store/loaded-state-parsing.ts
  • src/main/persistence/loading-store/profile-preferences.ts
  • src/main/persistence/loading-store/store-runtime-state.ts
  • src/main/persistence/loading-store/write-flush-barriers.ts
  • src/main/runtime/push/notifications/mobile-notification-dismissal-entries.ts
  • src/main/runtime/push/notifications/mobile-notification-dismissal-read-failure.test.ts
  • src/main/runtime/push/notifications/mobile-notification-dismissal-store.test.ts
  • src/main/runtime/push/notifications/mobile-notification-dismissal-store.ts
  • src/main/sqlite/keyed-json-row-cache.test.ts
  • src/main/sqlite/keyed-json-row-cache.ts
  • src/main/sqlite/legacy-json-source.ts
  • src/main/sqlite/row-cache/keyed-json-row-cache.test.ts
  • src/main/sqlite/row-cache/keyed-json-row-cache.ts
  • src/main/sqlite/row-cache/legacy-json-source.ts
  • src/main/sqlite/row-cache/row-cache-failure.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nwparker
nwparker merged commit d101312 into main Nov 9, 2026
59 of 60 checks passed
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