Repository navigation
Conversation
Inline autocheckpoints ran on every committing connection, including the Gateway main thread, and while readers kept the log from resetting every commit above 4 MiB retried a PASSIVE checkpoint and synced the database file. Raise the inline threshold to the 64 MiB recycling limit as a stalled-owner valve, tick the WAL maintenance timer every 10 s with checkpoint-only passes off the writers, and keep the 30-minute bounded vacuum reclaim.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 29, 2026, 2:21 AM ET / 06:21 UTC (Revision 8). ClawSweeper reviewWhat this changesThe branch moves frequent SQLite WAL checkpoints from published writers to worker connection timers, raises the fallback inline threshold, and updates memory publication policy, tests, and storage documentation. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 4 items remain Keep this PR open. The latest revision resolves the previously reported duplicate checkpoint schedule, but published writers can now leave WAL backfill waiting while their maintenance worker is idle. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw writes agent and shared state to SQLite databases. WAL maintenance copies committed pages into those databases and reclaims free pages; its scheduling affects disk use and Gateway responsiveness. flowchart LR
A[Gateway writes] --> B[Published SQLite writer]
B --> C{Worker admitted?}
C -->|Yes| D[Worker checkpoint tick]
C -->|No| E[Thirty-minute pass]
D --> F[WAL backfill]
E --> F
E --> G[Bounded vacuum]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +65, Tests +174, Docs 0. Total +239 across 14 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep an off-main checkpoint owner active whenever a published writer has inline checkpoints disabled, including idle-worker periods, while preserving replacement checks and the thirty-minute vacuum cadence. Do we have a high-confidence way to reproduce the issue? Yes, as a source-level path: let a published writer commit while its worker has no admitted operation, then observe that neither inline nor ten-second checkpointing runs. This read-only review did not execute that scenario. Is this the best way to solve the issue? No. Moving checkpoint I/O off the Gateway thread fits the existing owner model, but the proposed scheduling does not cover idle-worker periods. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2aed86671065. LabelsLabel changes: No label changes. Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
…rker-transactions-20260919
Writers whose WAL maintenance is delegated to a worker disable SQLite's automatic checkpoint when they register the owner and restore the 64 MiB valve on cancel. The maintenance timer counts fires: the first fire and every reclaim interval run the split-brain inspection and the bounded vacuum pass, all other ticks are checkpoint-only, so test forks that replace store files no longer trip the fatal containment every 10 s.
Keep the 30-minute periodic timer as the only owner of the split-brain inspection and the bounded vacuum pass, and arm a separate 10-second checkpoint-only tick beside it, so test forks that replace store files never meet the fatal containment on a tick. Worker-maintained writers remember the inline threshold they had and restore it when their owner is cancelled instead of exporting a shared constant.
…on policy The memory publication snapshots pragmas from the canonical agent connection and requires a borrowed worker connection to match them. wal_autocheckpoint now legitimately differs between a main-thread handle that delegates checkpoints to its maintenance worker and a worker connection that keeps the inline threshold, so the checkpoint cadence stays with each connection's WAL owner instead of the publication policy.
A main-thread tick delegated every pass through the maintenance worker and raced store replacement; worker-thread connections to the same store now tick inline while a main-thread handle keeps only its periodic pass.
…rker-transactions-20260919
A delegated main-thread writer's tick round-tripped through its maintenance worker and raced store replacement; the scheduler now returns for a zero-budget pass when a worker owner is registered, and worker connections to the same WAL tick inline. Drops the thread-based default, which vitest's thread pool made unreliable.
…ong-write-lock-holds-worker-transactions-20260919
openclaw#160818) * perf(sqlite): checkpoint WAL from maintenance ticks instead of commits Inline autocheckpoints ran on every committing connection, including the Gateway main thread, and while readers kept the log from resetting every commit above 4 MiB retried a PASSIVE checkpoint and synced the database file. Raise the inline threshold to the 64 MiB recycling limit as a stalled-owner valve, tick the WAL maintenance timer every 10 s with checkpoint-only passes off the writers, and keep the 30-minute bounded vacuum reclaim. * perf(sqlite): keep worker-maintained writers off inline checkpoints Writers whose WAL maintenance is delegated to a worker disable SQLite's automatic checkpoint when they register the owner and restore the 64 MiB valve on cancel. The maintenance timer counts fires: the first fire and every reclaim interval run the split-brain inspection and the bounded vacuum pass, all other ticks are checkpoint-only, so test forks that replace store files no longer trip the fatal containment every 10 s. * perf(sqlite): run the checkpoint tick beside the periodic pass Keep the 30-minute periodic timer as the only owner of the split-brain inspection and the bounded vacuum pass, and arm a separate 10-second checkpoint-only tick beside it, so test forks that replace store files never meet the fatal containment on a tick. Worker-maintained writers remember the inline threshold they had and restore it when their owner is cancelled instead of exporting a shared constant. * perf(memory): keep checkpoint cadence out of the publication connection policy The memory publication snapshots pragmas from the canonical agent connection and requires a borrowed worker connection to match them. wal_autocheckpoint now legitimately differs between a main-thread handle that delegates checkpoints to its maintenance worker and a worker connection that keeps the inline threshold, so the checkpoint cadence stays with each connection's WAL owner instead of the publication policy. * test(sqlite): count both maintenance timers in the pragma acquisition test * perf(sqlite): tick checkpoints from worker connections only A main-thread tick delegated every pass through the maintenance worker and raced store replacement; worker-thread connections to the same store now tick inline while a main-thread handle keeps only its periodic pass. * perf(sqlite): skip checkpoint-only ticks on worker-maintained writers A delegated main-thread writer's tick round-tripped through its maintenance worker and raced store replacement; the scheduler now returns for a zero-budget pass when a worker owner is registered, and worker connections to the same WAL tick inline. Drops the thread-based default, which vitest's thread pool made unreliable.
What Problem This Solves
Every WAL-mode store connection, including the Gateway main thread, ran with SQLite's default inline autocheckpoint (
wal_autocheckpoint = 1000pages). Once readers keep the log from resetting, every commit above ~4 MiB of WAL retries a PASSIVE checkpoint insideCOMMITand syncs the main database file on the committing thread. On team.openclaw.ai (32.5 GB agent store on btrfs, 3.3 M extents) that made commit steps take 1.5–13.5 s on the main thread and up to 41 s on workers, which showed up as 11–12 schat.metadata/models.listresponses, liveness heartbeats 13 s overdue anddatabase is lockedfailures for cron maintenance.Evidence
Journal since boot 20:48Z (57 min): 28
slow SQLite transaction step … step=commitlines, 15 of themisMainThread=true; connections already runsynchronous = NORMAL, so the only sync a commit pays is the autocheckpoint;session history disk budget deferred until a completed WAL checkpoint is observed×15 confirms checkpoints never complete under readers, so every commit re-attempts one.Change
registerSqliteWalWorkerMaintenance) setwal_autocheckpoint = 0when they register the owner, so they never checkpoint inline; the threshold they had is restored if the owner is cancelled while the handle stays open.journal_size_limit) instead of 1,000. It only bounds a writer nobody else checkpoints.SqliteWalPeriodicRequest.maxPages = 0) and never the split-brain probe. A writer whose maintenance is delegated to a worker skips those ticks inside the scheduler (no worker round trip, which raced store replacement in tests); the worker connections to the same WAL tick inline on their own thread, so checkpoint I/O stays off the Gateway event loop.onCheckpointErrorevery 10 s; the reclaim pass keeps today's warnings.createSqliteWalMaintenanceSchedulertakes the page budget per run;reclaimSqliteWalFreePagestreats a zero budget as checkpoint-only.wal_autocheckpointin the publication connection policy it snapshots from the canonical connection and asserts on borrowed worker connections: the value now legitimately differs between a delegating main-thread handle and a worker connection, and checkpoint cadence belongs to each connection's WAL owner.No config, schema or durability change:
synchronous, journal mode,journal_size_limit, close/TRUNCATE behavior and the 30-minute reclaim cadence are unchanged. Update behavior: none beyond the new build; existing stores need no migration.Revision notes: revision 1 ran the split-brain probe on every tick, which SIGKILLed CI test forks that replace store files; revision 2 addressed the ClawSweeper findings (positive threshold still checkpointing inline above 64 MiB under a pinned reader; wall-clock cadence); revisions 3–4 still ran the probe on the first 10 s fire and exported a constant that tripped the plugin-SDK runtime-API guardrail; revision 5 keeps the periodic timer exactly as before and arms the tick beside it; revision 6 drops the pragma from the memory publication policy after CI showed the borrowed-connection assertion tripping on it; revisions 7–9 fix the per-owner timer counts and stop delegated writers from round-tripping ticks through their worker (a Testbox repro showed
SQLite transaction admission was refusedinsrc/auto-reply/reply/session.test.ts; after the fix that file passes 222/222 twice).Proof (validation)
src/infra/sqlite-wal.checkpoint-tick.test.ts: threshold pragma; a worker-maintained writer disables inline checkpoints and restores the valve on cancel; tick cadence with a real store (first fire checkpoints and reclaims, in-interval ticks checkpoint only, next interval reclaims).sqlite-wal.replacement.test-support.ts,sqlite-wal.agent-admission.test.ts,openclaw-state-db.wal.test.ts) and the shared-state pragma test (worker-maintained writer readswal_autocheckpoint = 0).tbx_01m3nswtg57zz8sewesdys2m0q/tbx_01m3nwg0ffycy0emy5get5khjm):src/auto-reply/reply/session.test.ts222/222 twice; focused sqlite-wal*, checkpoint-tick, agent-admission, reclamation, state-db.wal, state-db-open, state-db, memory-core publication, gateway memory-search and the plugin-SDK runtime-API guardrail: 359 passed;doctor-maintenance.settlementNOCOW test 30/30 after merging main;node scripts/check-changed.mjs --base origin/main: all lanes ok in 27 min; Codex autoreview (local mode vs origin/main, P0): scoped-clean on revision 9.docs/reference/database-schemas/integrity-and-recovery.mdmaintenance paragraph.Follow-ups (separate): NOCOW (
chattr +C) for stores on btrfs (lane in flight), and the worker admission wait that holds the write lock across main-thread round trips.