Repository navigation
fix: stop session cleanup from amplifying a blocked WAL - #154302
Conversation
|
🦞👀 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: needs maintainer review before merge. Reviewed September 21, 2026, 7:26 AM ET / 11:26 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR preserves session archives during incomplete SQLite checkpoints, defers repeated cleanup until recovery, moves page reclamation through the existing worker, and adds passive reader diagnostics. Merge readiness✅ Ready for maintainer review Keep open: the fix remains necessary on current main and the latest release. No actionable introduced defect was found, and the revised lifecycle coverage supports the intended cleanup contract. Priority: P1 Review scores
Verification
How this fits togetherSession maintenance measures disk usage and removes eligible history and archives. SQLite checkpoint results now determine whether maintenance can reclaim space safely or should preserve data and wait. flowchart TD
A[Session activity or manual cleanup] --> B[Measure disk usage]
B --> C[SQLite maintenance worker]
C --> D{Checkpoint complete?}
D -->|No| E[Preserve archives and defer cleanup]
D -->|Yes| F[Reclaim pages and eligible history]
C --> G[Publish checkpoint observations]
G --> B
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +785, Tests +854, Docs +20, Other +1. Total +1660 across 55 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep checkpoint completion authoritative for pressure cleanup, preserve committed deletion semantics, and investigate the unidentified Windows reader separately. Do we have a high-confidence way to reproduce the issue? Yes: holding a SQLite reader while creating WAL-only pressure exposes the source-proven cleanup defect. Recorded boundary runs cover that scenario; this review did not execute code or reproduce the broader Windows startup failure. Is this the best way to solve the issue? Yes. Reusing the WAL and reclamation owners fixes completion handling without changing schemas, configured budgets, or committed deletion semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0e4f556d0527. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
06281c2 to
4e132dc
Compare
Preserve archives and defer disk-budget cleanup when checkpointing is incomplete. Share the checkpoint/vacuum owner, move archive page work through the retained worker, and relay checkpoint recovery to the scheduler. Record bounded connection and statement ownership diagnostics for persistent readers. Related: #143524. Thanks to @desksk and the earlier reporters for the reproduction evidence.
Include the WAL reclamation owner in the extracted wrapper runtime inventory. Count Reef peer reads at the existing keyed-store boundary so cached native diagnostic wrappers cannot defeat late prototype spies; retain the bounded-read and refresh assertions.
Remove native method interposition and restore explicit Kysely reader ownership. Keep bounded weak connection metadata without changing native settlement, retirement, or prototype fault injection. Repair maintenance fixtures at their intended admission boundaries and attach the existing raw-PRAGMA justification to its checked expression. Same-Testbox attribution: all 12 files fail at the previous head and pass on main; all 12 pass after the repair. Related: #143524.
a0d46ac to
42c3286
Compare
Join the parent's native settlement barrier before post-commit page work so that the parent's own writer lock cannot create a fresh busy checkpoint. Preserve authority checks, abrupt-exit confirmation, and committed results. Force the real vacuum/settlement interleaving in the existing WAL-budget regression. It fails five times before the owner fix and passes five times after it, with the original recovery and preservation assertions intact. Related: #154302, #154543
Join the parent's native settlement barrier before post-commit page work so that the parent's own writer lock cannot create a fresh busy checkpoint. Preserve authority checks, abrupt-exit confirmation, and committed results. Force the real vacuum/settlement interleaving in the existing WAL-budget regression. It fails five times before the owner fix and passes five times after it, with the original recovery and preservation assertions intact. Related: #154302, #154543
…155009) * fix(state): resume history cleanup after WAL recovery Join the parent's native settlement barrier before post-commit page work so that the parent's own writer lock cannot create a fresh busy checkpoint. Preserve authority checks, abrupt-exit confirmation, and committed results. Force the real vacuum/settlement interleaving in the existing WAL-budget regression. It fails five times before the owner fix and passes five times after it, with the original recovery and preservation assertions intact. Related: #154302, #154543 * test(state): rely on main WAL settlement repair
) * fix: stop session cleanup from amplifying a blocked WAL Preserve archives and defer disk-budget cleanup when checkpointing is incomplete. Share the checkpoint/vacuum owner, move archive page work through the retained worker, and relay checkpoint recovery to the scheduler. Record bounded connection and statement ownership diagnostics for persistent readers. Related: openclaw#143524. Thanks to @desksk and the earlier reporters for the reproduction evidence. * fix: restore PR wrapper imports and Reef read checks Include the WAL reclamation owner in the extracted wrapper runtime inventory. Count Reef peer reads at the existing keyed-store boundary so cached native diagnostic wrappers cannot defeat late prototype spies; retain the bounded-read and refresh assertions. * fix: keep SQLite reader diagnostics out of lifecycle custody Remove native method interposition and restore explicit Kysely reader ownership. Keep bounded weak connection metadata without changing native settlement, retirement, or prototype fault injection. Repair maintenance fixtures at their intended admission boundaries and attach the existing raw-PRAGMA justification to its checked expression. Same-Testbox attribution: all 12 files fail at the previous head and pass on main; all 12 pass after the repair. Related: openclaw#143524. * test: verify post-delete cleanup after checkpoint recovery
…penclaw#155009) * fix(state): resume history cleanup after WAL recovery Join the parent's native settlement barrier before post-commit page work so that the parent's own writer lock cannot create a fresh busy checkpoint. Preserve authority checks, abrupt-exit confirmation, and committed results. Force the real vacuum/settlement interleaving in the existing WAL-budget regression. It fails five times before the owner fix and passes five times after it, with the original recovery and preservation assertions intact. Related: openclaw#154302, openclaw#154543 * test(state): rely on main WAL settlement repair
Related: #143524
What Problem This Solves
Fixes session cleanup deleting archives and adding WAL writes when a reader prevents SQLite checkpointing from completing.
User Impact
Cleanup preserves archives and history while checkpointing is incomplete, records the actual outcome and physical bytes, and defers repeated budget work until a completed checkpoint is observed. Archive page maintenance uses the existing worker.
Bounded diagnostics report explicitly tracked readers, weak connection metadata and current open-transaction flags. They do not replace native methods or participate in worker settlement or retirement. Raw native statements outside explicit reader tracking remain unobserved; the original Windows holder remains unidentified. Startup blocking policy, schemas, dependencies and configuration options are unchanged.
Why This Change Was Made
Archive pruning discarded checkpoint failure and reported completion. Disk-budget pressure then kept scheduling cleanup against WAL bytes it could not reclaim. Periodic and post-deletion maintenance also vacuumed after incomplete checkpoints. One WAL owner now guards vacuum, and the budget scheduler consumes checkpoint outcomes and recovery observations, including retained-worker close. Older completion observations cannot clear a newer blocked outcome.
Reader diagnostics remain observers. Kysely owns explicit reader custody; native idle inspection owns retirement of untracked SQLite readers. Diagnostic metadata neither adds nor settles those lifecycle records.
Thanks @desksk for the driver analysis, and @L497c, @markun-japan, @ERMALTA and @TommyLei666 for the checkpoint and lifecycle evidence.
Evidence
The r2 attribution matrix ran all twelve failing files at original head
4e132dc9dbbf895d16166a060bc430f0ce0389c1and pinnedorigin/main62f5950ba4b1c377136ce3247212d9977eda66f3on the same Blacksmith Testbox, in the recorded failing-file order with hosted worker caps and isolation settings (--isolate=falsewhere applicable). The fix was then replayed against that same main. No main-side failure appeared in this matrix.src/gateway/server-methods/session-row-facts.test.tssrc/infra/sqlite-worker-shared-state-idle.test.tssrc/infra/sqlite-coordinator.idle.test.tssrc/infra/session-cost-usage-cache.worker.test.tssrc/transcripts/library.query-budget.test.tssrc/state/openclaw-agent-worker-store.test.tssrc/config/sessions/session-history-eviction.protected-cancellation.test.tssrc/plugin-state/plugin-state-store.doctor-repair.test.tssrc/config/sessions/session-history-budget-owner.test.tssrc/cron/service/ops.mutation-completion.test.tssrc/infra/sqlite-worker-shared-state.test.tssrc/state/user-profiles.avatar-admission.test.tsThe original head failed 23 assertions across all 12 files. The fixed candidate and both main control passes are green. Same-Testbox run, lease
tbx_01m315jyye5egwkdvtva1a6k1h. Fixed source tree:2c9563a348912fe2aa56a92681e11111a51ac23d. Each file retained its source test order; these are targeted file runs, not claims that every preceding file in each hosted shard was replayed. Every recorded failure reproduced without needing that broader replay.Attribution and canonical repairs:
assertSettled, turning an untracked cursor into premature retirement and anoutcome-unknownresult. Bound instance methods also defeated late prototype SQL counters and injected failures. The fix deletes native interposition, restores original Kysely custody and keeps only passive weak metadata. The original idle, coordinator, query-budget and SQL-calibration regressions are unchanged.check:architecturefailed because the existing raw-PRAGMA justification precededreturn Number(...)instead of its nestedprepare()call. Moving that same comment to the checked expression fixes the guard without a baseline or allowance change. Fullcheck:architecturepasses. The SDK API unavailable text was an echoed, unexecuted branch;plugin-sdk:api:diffexists on both revisions.Additional fixed-candidate proof: 55 tests passed across WAL checkpoint diagnostics, Kysely lifecycle handling and the real session-budget flow. Held readers cause one prune attempt across repeated passes, constant WAL bytes and preserved archives; releasing the reader and observing checkpoint completion restores cleanup and WAL truncation. Earlier harness output measured 2,191,872 bytes throughout four held-reader passes and 0 after release.
The earlier wrapper inventory omission is fixed by adding the sole missing eager dependency,
sqlite-wal-reclamation.ts; all six source-closure checks passed. The Reef read counter uses the public keyed-store lookup boundary while preserving its bounded-read and refresh assertions. The earlier four-file Testbox proof passed 191 tests with one existing macOS-only skip.Full
node scripts/check-changed.mjspassed on the clean Testbox with frozen dependencies, including core/extension typechecks, lint and remaining guards. The local attempt stopped because this worktree still has CUA driver 0.24.0 installed while the lockfile requires 0.28.2; no source change was made to conceal that environment mismatch. The remote command succeeded with exit 0; its portal-sync warning occurred after completion and did not change the recorded command outcome. Fresh P1 autoreview is scoped-clean, with no accepted/actionable P0/P1 finding.The r2 delta is production +40/-262 (net -222), tests/support +197/-268 (net -71), and docs +6/-5. No matrix test exceeded 30 seconds; each matrix-file command was under 46 seconds. The Testbox is stopped after proof.
The operator-facing warning is:
Inspect
checkpoint.activeReadersandcheckpoint.readerDiagnostics. Native statements are explicitly marked unobserved, and observations do not claim native lock ownership. No SQL text, bound values or transcript contents are recorded.R3: committed deletion versus deferred pressure cleanup
A committed lifecycle deletion remains committed. Unrelated archive/history cleanup is intentionally deferred when its checkpoint is incomplete, as the storage contract requires. The previous lifecycle test assumed that scheduling maintenance also guaranteed immediate removal of unrelated data; it discarded the actual sweep outcome and warning.
The six lifecycle cases now hold a real named read transaction and require
deferredReason: checkpoint-incomplete,completed: false, the reader's open-transaction diagnostic, and the existing warning. They verify the requested deletion is already committed, then release the reader, require a successful checkpoint through the WAL owner, and require the original archive/history removal and live-session preservation assertions. The cases moved to a sibling test file to remain below the line cap. No production code changed relative to42c3286b1fa10e4328bb2d68f040dfbcc54b2a90.The old assertions failed deterministically in all three committed cases with the named reader held; all three noncommitted cases passed. After the assertion repair, all six passed. An instrumented replay of the original hosted shard's available 84 files passed 1,556 tests: one file from the hosted merge was absent at branch head. Its checkpoints completed, so this replay does not identify the original transient hosted blocker. The deterministic reader evidence establishes the preservation and recovery contract without attributing that unidentified blocker.
R3 final proof on
ea1ab660aab1e20744dd2985090d35b01ca887b0(tree392a9d91c7b9262b095fe39d1f754c633efd7778): 166 tests passed across both eviction files and the twelve-file matrix, retaining the matrix's recorded order, worker caps and isolation settings. The split lifecycle file took 28.2 seconds with--maxWorkers=1; the existing eviction file took 41.2 seconds with two workers. No individual test exceeded 5.95 seconds and no file command exceeded 43.4 seconds. Blacksmith Testbox run, leasetbx_01m31swemzyn0eec2tk55g96zp.Scoped
node scripts/check-changed.mjs --base 42c3286b1fa10e4328bb2d68f040dfbcc54b2a90 -- src/config/sessions/session-history-eviction.test.ts src/config/sessions/session-history-eviction.lifecycle.test.tspassed, including core test typechecking, ratchets and lint with zero warnings/errors. Its first invocation lacked the comparison-base object in the Testbox carrier repository; fetching that exact commit allowed the check to run without source changes. P1 autoreview is scoped-clean. Production interdiff against the prior head is empty (0 LOC); tests are +270/-139 (net +131), including the six-case move. The Testbox is stopped. Auto-merge was verified disabled before the lease-protected push; this revision is awaiting r3 review.