Skip to content

Make SQLite the source of truth for native chats - #39256

Merged
brennanb2025 merged 517 commits into
mainfrom
brennanb2025/native-chat-sqlite-host
Nov 14, 2026
Merged

brennanb2025 merged 517 commits into
mainfrom
brennanb2025/native-chat-sqlite-host

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #39221, which is folded into this PR so the whole change is reviewed and merged as one. Addresses native chat history growing to 20 GiB (STA-13374, tracked in #37802).

Problem and change

Native chats rebuild their whole history from an append-only journal and retain it in memory. Large histories become slow to open, and the journal keeps growing. This PR makes agent-session-domain.db the source of truth: one background writer commits changes, and reader workers serve history pages, outlines and individual records. Database work stays off the Electron main thread.

Existing chats convert while Orca is idle, or in the existing loading state when first opened. Sending, streaming, reopening and forking use the converted history. There is no new notice or control. The send/reconnect fix also prevents a message from remaining on “Sending…” after the agent has accepted it.

After every chat is proven converted, Orca waits seven days of time the app is open and a later launch before deleting the original journal and its empty companion files. If the original file changed or cannot safely be removed, it is kept. Background maintenance yields while chats are active.

Disclosures

  • One-way conversion: an older build can read the original history until that journal is removed. Writes made by an older build are not imported again into an already converted chat.
  • After the original journal is removed: Older builds start a separate empty history and may permanently delete attachments still referenced by current history.
  • Send/publication costs: preventing chats sticking on “Sending…” adds about +0.35 ms with one subscriber and +1 ms with 16 in the streaming-contention database-acknowledgement benchmark. The accepted burst/publication costs and measurement limits are below.
  • Startup for profiles with saved chats still has a small measured cost against the comparison base. These measurements ran on a busy host. The headless-server paired medians were +34 ms to RPC listening and +43 ms to watcher readiness on warm restart; +93/+109 ms under CPU contention; and +22/+63 ms on first start after upgrade. The contention watcher estimate has a 95% interval of +13 to +241 ms. This is an accepted startup tradeoff; the measurements do not establish parity, p95 latency, desktop first paint or every profile size.
  • Static baselines: config/main-blocking-sqlite-baseline.txt and config/main-sync-fs-baseline.txt are raised for worker-only code. These entries do not permit database or filesystem blocking on the Electron main thread.
  • Claude CLI title reuse removed: chat naming uses Orca’s generated names. Reusing the Claude CLI’s live title (Use Claude CLI titles for default native chat naming #40069) is removed.
  • Queue placement bounds: later queue rows may receive different numeric positions after reopening; visible order is preserved.
  • Measurement limits: writer BEGIN-to-COMMIT time is not measured separately. Send and startup results cover their stated workloads and hosts, rather than a claim that every operation is faster.

Performance measurements

The send repair was measured in Node with one synthetic chat. These are database acknowledgements and frame publication, with p50 values below; provider response time and Electron delivery time are outside the measurement.

Workload Subscribers Before After
Streaming: database acknowledgement 1 0.669 ms 1.017 ms
Streaming: database acknowledgement 16 1.000 ms 2.029 ms
Streaming: four-commit burst 1 3.788 ms 4.614 ms
Streaming: four-commit burst 16 5.493 ms 8.236 ms
Uncontended publication 16 1.884 ms 3.279 ms

Uncontended publication was 1.74× before (95% interval 1.61–1.83). Streaming acknowledgement p95 with one subscriber was 1.20× before (95% interval 1.08–2.84; tail estimates are less precise). These measured costs were accepted for the correctness repair.

The startup comparison used 20 saved chats × 30 turns, 16 paired rounds on a busy host. Values are branch-minus-base paired medians with 95% bootstrap intervals, measured from the headless server’s first startup phase mark (excluding process and bundle load). Watcher readiness is the first filesystem-watcher subscription reporting ready.

Saved-chat condition RPC listening Watcher ready
Warm restart +34 ms [−13, +62] +43 ms [+12, +111]
CPU contention (8 busy processes on 10 cores) +93 ms [+46, +146] +109 ms [+13, +241]
First start after upgrade (includes one-time import) +22 ms [+5, +48] +63 ms [+12, +83]

Validation

The final independent Claude/Codex reviews are complete. Head CI passed (82 successful checks, 19 skipped), with node/web typechecks, compatibility tests and static checks. Real Windows x64 Claude/Codex runs passed upgrade, history preservation, streaming, Stop followed by a new reply, send/reconnect, restart, and journal removal followed by another restart. Seven days of open time were simulated by seeded credit. The review status comment records screenshots, baseline behavior and limits, including the invalid TODO-strip scenario and one driver identity-check freshness gap. A targeted real Pi run also passed upgrade, restart, history/tool-row preservation and two new replies after each step, using the machine’s existing OpenAI sign-in and GPT-5.6 Sol. Main has moved since preparation and GitHub currently reports a merge conflict; the reviewed head is preserved for review.

Files Added Deleted Net
Test 349 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28322 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5817 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22505
Prod 923 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55351 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18521 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36830

One entry (native-chat-4a-comparison.ts) seeds the 55k-history/310-chat
profile once through the seed arm, clones it per arm at a fixed path,
launches each built checkout in the background with an isolated home,
and drives the same stub provider events through the host RPC surface
both builds serve. Envelopes come from each arm's own source bundle.
Rows cover send/queue, 1/8/16 MiB streams with a competing send,
maintenance windows, open/reopen, history/detail, outline/fork,
rewind, record operations, R3 retained-history admission and, reported
separately, first-launch conversion (optional 20 GiB source). Output is
one JSON and one markdown table keyed by both head SHAs.
… smoke filler chats for the unopened-chat row
One entry (native-chat-4a-comparison.ts) seeds the 55k-history/310-chat
profile once through the seed arm, clones it per arm at a fixed path,
launches each built checkout in the background with an isolated home,
and drives the same stub provider events through the host RPC surface
both builds serve. Envelopes come from each arm's own source bundle.
Rows cover send/queue, 1/8/16 MiB streams with a competing send,
maintenance windows, open/reopen, history/detail, outline/fork,
rewind, record operations, R3 retained-history admission and, reported
separately, first-launch conversion (optional 20 GiB source). Output is
one JSON and one markdown table keyed by both head SHAs.
… smoke filler chats for the unopened-chat row
nwparker added a commit that referenced this pull request Nov 16, 2026
…orkers

Since #39256 (first shipped in v1.4.260) a release's test journal opener
spawns its SQL writer and reader from a bundle its worker-bundle fixture
builds in a module-scope beforeAll. The harness imports release modules
mid-test, so that hook never runs and the opener passes bare file names
to new Worker (ERR_WORKER_PATH). Such releases also read a chat back
asynchronously rather than through journal.snapshot().

Bundle the release's own SQL worker entries and stand them in for its
fixture, and read each release's chat through its own reads.
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