Repository navigation
perf(native-chat): defer inline writer checkpoints during slow off-thread flushes and raise active writer SQLite cache - #52026
Conversation
…read flushes and raise active writer SQLite cache
[Medium impact] The PR appears safe to merge, with the previous test-coverage gap addressed. SummaryThe PR delays writer-side checkpoints during slow background flushes and raises the writable connection’s SQLite cache to 16 MiB.
Reviews (2) · Last reviewed commit: "test(native-chat): exceed bulk WAL ceili..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
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 viashrink_memory).What Changed
writerFallbackStalled()(WRITER_FALLBACK_STALL_MS = 30_000) toJournalCheckpointWorkerControllerinsrc/main/native-chat/agent-session-journal/database/journal-checkpoint-worker-thread.ts.JournalCheckpointOwner.syncWriterCheckpoints()insrc/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.tsto keepgated()opening WAL admission atstallMs(5 s), while only re-enabling writer-sidewal_autocheckpoint = 1000when off-thread checkpointing actually failed/stopped/unavailable or a live worker has been silent for30 s.PRAGMA cache_size = -16384(16 MB) on the single writable connection insrc/main/native-chat/agent-session-journal/journal-sql-worker-entry.ts(reclaimed after 10 s idle by the existingidleShrinkTimercallingPRAGMA shrink_memory).src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.performance.test.ts.Why
On a 27 GB
agent-session-domain.dbunder heavy multi-agent load, legitimate off-threadPASSIVE+checkpoint_fullfsync = ONflushes routinely exceed 5 seconds. Re-enablingwal_autocheckpoint = 1000on the hot writer at 5 seconds caused the writer's ownsteps/effects/send-admissioncommits 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
Verified with
oxfmt,oxlint(0 errors/warnings),pnpm tc:node, andpnpm 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.tson 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 towal_autocheckpoint = 1000after 30 s so WAL growth remains bounded; dead/failed workers still fall back immediately. Plain revert backs it out cleanly.Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)