Skip to content

perf(native-chat): defer inline writer checkpoints during slow off-thread flushes and raise active writer SQLite cache - #52026

Merged
AmethystLiang merged 2 commits into
mainfrom
perf/defer-inline-journal-writer-checkpoints
Nov 29, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
perf/defer-inline-journal-writer-checkpoints

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When the chat journal's background checkpoint thread took more than 5 seconds to flush a large WAL on a multi-GB database, Orca immediately turned inline checkpointing back on for the main SQLite writer connection—causing active chat writes to stall for 2–9 seconds inside COMMIT. This keeps the 5-second safeguard that lets saves through, while waiting 30 seconds before pulling the hot writer into inline checkpoints, and raises the single writer's active SQLite page cache from 2 MB to 16 MB (already reclaimed after 10 s idle via shrink_memory).

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21

What Changed

  • Added writerFallbackStalled() (WRITER_FALLBACK_STALL_MS = 30_000) to JournalCheckpointWorkerController in src/main/native-chat/agent-session-journal/database/journal-checkpoint-worker-thread.ts.
  • Updated JournalCheckpointOwner.syncWriterCheckpoints() in src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.ts to keep gated() opening WAL admission at stallMs (5 s), while only re-enabling writer-side wal_autocheckpoint = 1000 when off-thread checkpointing actually failed/stopped/unavailable or a live worker has been silent for 30 s.
  • Set PRAGMA cache_size = -16384 (16 MB) on the single writable connection in src/main/native-chat/agent-session-journal/journal-sql-worker-entry.ts (reclaimed after 10 s idle by the existing idleShrinkTimer calling PRAGMA shrink_memory).
  • Added performance contract src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.performance.test.ts.

Why

On a 27 GB agent-session-domain.db under heavy multi-agent load, legitimate off-thread PASSIVE + checkpoint_fullfsync = ON flushes routinely exceed 5 seconds. Re-enabling wal_autocheckpoint = 1000 on the hot writer at 5 seconds caused the writer's own steps/effects/send-admission commits to absorb synchronous multi-second checkpoints, while SQLite's default 2 MB page cache thrashed across ~90 indexes on every write batch.

Visual Proof

N/A — background SQLite journal writer tuning only; no UI changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Verified with oxfmt, oxlint (0 errors/warnings), pnpm tc:node, and pnpm test src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.test.ts src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.performance.test.ts on macOS.

Performance

Avoids 2–9 s synchronous inline checkpoints on the journal SQL writer thread during slow off-thread flushes, and reduces B-tree page-cache misses on the single writer connection. Peak extra memory is bounded to +14 MB on the single writer thread while actively writing, and returns to baseline after 10 s idle via existing PRAGMA shrink_memory. Reader workers stay capped at -2048 (2 MB).

Risk

Level: Low

Durability pragmas (synchronous = NORMAL, checkpoint_fullfsync = ON) and the 5-second WAL admission safety valve are unchanged. If a live checkpoint worker truly deadlocks, the writer still falls back to wal_autocheckpoint = 1000 after 30 s so WAL growth remains bounded; dead/failed workers still fall back immediately. Plain revert backs it out cleanly.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…read flushes and raise active writer SQLite cache
@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with the previous test-coverage gap addressed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test-coverage gap addressed.

Summary

The PR delays writer-side checkpoints during slow background flushes and raises the writable connection’s SQLite cache to 16 MiB.

  • A live checkpoint worker gets more time before the writer starts inline checkpoints.
  • The writable journal connection keeps a larger page cache during active writes.

Reviews (2) · Last reviewed commit: "test(native-chat): exceed bulk WAL ceili..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The checkpoint worker controller adds a configurable writer-fallback stall threshold. The owner uses the threshold and worker failure states to synchronize writer-side autocheckpointing. A performance test checks checkpoint settings at timed intervals and after a worker response. Writable database setup also sets SQLite’s cache size before creating indexes and schema.

Merge Risk: Low · up to 50de8

The change reduces commit stalls during slow checkpoints by delaying the inline checkpoint fallback, and gives the writer a larger page cache. The main residual risk is higher memory use while the writer is active and a longer window of WAL growth. No concrete defect was found, so this is mergeable with owner awareness.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description follows the template closely. It has ELI5, What Changed, Why, Visual Proof (N/A with reason), Testing with checkboxes, Performance with a sentence, Risk with level and rollback, and th… Add an issue number under Linked Issue (replace 'Fixes #' with a real issue reference, or explain why none exists if you are a maintainer). Describe how the 2–9 s stall and the page-cache effect were measured, or state the reasoning. Fill i…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title describes the main change: deferring inline writer checkpoints during slow off-thread flushes, plus raising the active writer SQLite cache. The diff matches both parts: a 30 s writer-fallbac…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title describes the main change: deferring inline writer checkpoints during slow off-thread flushes, plus raising the active writer SQLite cache. The diff matches both parts: a 30 s writer-fallback stall threshold in the checkpoint owner and worker controller, and cache_size set to -16384 in the journal SQL worker. The title is long at 118 characters, but it is specific and accurate.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed, Why, Visual Proof (N/A with reason), Testing with checkboxes, Performance with a sentence, Risk with level and rollback, and the checklist. The Linked Issue section is missing: it reads 'Fixes #' with no issue number, and the template says outside contributors must link an actual issue. The Review, Notes, and AI Disclosure sections are left as template text. The Performance section also gives a measured-looking claim (2–9 s stalls, 27 GB DB) without showing the measurement method.

Resolution

Add an issue number under Linked Issue (replace 'Fixes #' with a real issue reference, or explain why none exists if you are a maintainer). Describe how the 2–9 s stall and the page-cache effect were measured, or state the reasoning. Fill in or remove the unused AI Disclosure and Review sections, and confirm the cross-platform testing status, since only macOS testing is reported.

  • 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

Recent review info

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: 627e6daa-c6bf-41e1-97ae-2173261aeec4
Commits

Reviewing files that changed from the base of the PR and between 7a971b8 and 50de872.

Files selected for processing: 1

  • src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.performance.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@AmethystLiang
AmethystLiang merged commit 2e357d9 into main Nov 29, 2026
59 checks passed
@AmethystLiang
AmethystLiang deleted the perf/defer-inline-journal-writer-checkpoints branch November 29, 2026 01:05
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