Skip to content

fix: serialize periodic database maintenance with session writes - #148941

Merged
steipete merged 9 commits into
mainfrom
codex/swarm-periodic-wal-admission-20260915
Sep 16, 2026
Merged

steipete merged 9 commits into
mainfrom
codex/swarm-periodic-wal-admission-20260915

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #130741

What Problem This Solves

Periodic SQLite maintenance could race a reserved session write. Failed deferred maintenance could also release admission while its native Worker still held a transaction lock.

User Impact

Checkpoint and incremental-vacuum work waits for the existing database writer owner. Retired connections do not receive delayed maintenance, and session writes retain FIFO ordering. A poisoned transaction keeps the writer reserved until the Worker actually exits.

Why This Change Was Made

Periodic maintenance coalesces behind the existing admission queue and rechecks the timer and exact connection after waiting. Retained Workers flush pending maintenance under current parent authority before and after their operation. The existing poisoned-transaction check reaches the cleanup owner if commit, rollback, and close all fail, so that owner cannot report settlement early. Checkpoint behavior and the 512-page vacuum bound remain unchanged.

Evidence

Exact-head CI passed on d2c44d378514bdcf47799e7b22f9f9a317544179: 125 jobs succeeded and 15 were skipped. The tested merge was 4108afdb8a83f3ec722d43005ff8a0de1142612a. Eight selected owner files account for 330 passing cases with no skipped or failed cases, including all six native pre/post-maintenance failure and cleanup cases, Doctor revalidation, prepared reads, transcript/provenance, read-only companions, and shared-state open behavior.

Earlier focused proof passed 79 tests and canonical changed checks on its recorded integration. The original post-maintenance regression reproduced premature settlement while an independent connection remained locked; the repaired case verifies writer exclusion, retained ownership, actual exit, and subsequent write recovery. The reviewed feature patch is unchanged.

Current-main composition preserves normalized admission-service registrations, canonical validation, cold-open preparation, reader cleanup, and native error ownership. Any preparation that changes the published head requires matching CI before merge. These results do not establish the overall 500 ms Swarm performance target.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 4:11 AM ET / 08:11 UTC (Revision 10).

ClawSweeper review

What this changes

Queues periodic SQLite maintenance behind session writes and retains Worker ownership until failed native transactions safely settle.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main still runs periodic maintenance outside the writer queue. No introduced correctness or security defect was found, and the previous review has no outstanding findings.

Priority: P2
Reviewed head: d2c44d378514bdcf47799e7b22f9f9a317544179

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful native-boundary regressions, successful pinned-head CI, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-authored PR. Supplemental evidence exercises the production reclamation Worker against native SQLite, including retained locks, native exit, and write recovery; inspected CI confirms a successful run for the reviewed head.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-authored PR. Supplemental evidence exercises the production reclamation Worker against native SQLite, including retained locks, native exit, and write recovery; inspected CI confirms a successful run for the reviewed head.
Evidence reviewed 10 items Verified introduced change and merge composition: The original head has recorded parents b7e42aa and 174bbf3. The test merge has exactly the pinned base followed by this head; its inspected database-owner changes match the introduced patch.
Existing writer owner reused: Published agent connections register periodic maintenance with the existing per-database writer queue. Execution checks the exact cached connection; timer invalidation prevents delayed work after close.
Deferred maintenance and native settlement: Worker maintenance checks current operation authority before execution and propagates poisoned open transactions to the existing cleanup owner. The production request owner waits for settlement or native exit before releasing admission.
Findings None None.
Security None None.

How this fits together

OpenClaw stores session data in per-agent SQLite databases. Session writes and periodic checkpoint/vacuum work share those databases, so maintenance must respect writer ownership and connection lifetime.

flowchart TD
  A[Periodic maintenance timer] --> B[Coalesce pending maintenance]
  C[Session writes] --> D[Existing database writer queue]
  B --> D
  D --> E[Check current connection and authority]
  E --> F[Checkpoint and bounded vacuum]
  F --> G[Transaction settlement or native Worker exit]
  G --> D
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +138, Tests +824. Total +962 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 159 21 +138
Tests 5 893 69 +824
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 1052 90 +962

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +138 lines; tests net +824 lines Production growth supplies the queue adapter and settlement checks; most growth exercises native failure and ownership boundaries.

Technical review

Best possible solution:

Keep periodic maintenance under the existing writer owner, preserving connection validity checks, bounded vacuum work, and native settlement before admission release.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main's periodic timer bypasses the session writer queue, and the added regressions exercise that contention boundary. No runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing writer queue and poisoned-transaction cleanup contract is a focused repair that preserves stored data and public behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b47ba1021fff.

Labels

Label justifications:

  • P2: This repairs a bounded database-maintenance race without evidence of a current widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-authored PR. Supplemental evidence exercises the production reclamation Worker against native SQLite, including retained locks, native exit, and write recovery; inspected CI confirms a successful run for the reviewed head.

Evidence

What I checked:

  • Verified introduced change and merge composition: The original head has recorded parents b7e42aa and 174bbf3. The test merge has exactly the pinned base followed by this head; its inspected database-owner changes match the introduced patch. (4108afdb8a83)
  • Existing writer owner reused: Published agent connections register periodic maintenance with the existing per-database writer queue. Execution checks the exact cached connection; timer invalidation prevents delayed work after close. (src/state/openclaw-agent-db.ts:434, d2c44d378514)
  • Deferred maintenance and native settlement: Worker maintenance checks current operation authority before execution and propagates poisoned open transactions to the existing cleanup owner. The production request owner waits for settlement or native exit before releasing admission. (src/infra/sqlite-wal-write-admission.ts:60, d2c44d378514)
  • Production-boundary regression coverage: The six pre/post-maintenance fault cases use the actual reclamation Worker and native SQLite connections. Assertions check independent writer exclusion, retained leases, delayed native exit, and subsequent write recovery. Companion cases cover coalescing, connection retirement/replacement, and revoked maintenance authority. These sources were inspected, not executed during this review. (src/config/sessions/session-accessor.sqlite-reclamation-maintenance.test.ts:248, d2c44d378514)
  • Pinned-head validation: GitHub confirms https://github.com/openclaw/openclaw/actions/runs/35051019335 completed successfully for the reviewed head. The captured PR body reports 330 selected passing cases, including the six native maintenance cleanup cases; that count is contributor-reported rather than independently rerun. (d2c44d378514)
  • Still necessary on current main: Fetched main still invokes checkpoint and incremental vacuum directly from the periodic timer; the maintenance-admission module is absent there. (src/infra/sqlite-wal.ts:703, b47ba1021fff)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T09:03:07.540Z sha a84f627 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T11:19:20.080Z sha bcbe89f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T16:48:57.904Z sha 1beae4f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T16:56:19.290Z sha 1beae4f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T19:58:45.574Z sha 70180fe :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T00:42:46.062Z sha b7e42aa :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T01:47:14.447Z sha 178bd142b61c6ae4c64c7f31359ddfe1aea830de :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T03:20:48.902Z sha d2c44d3 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 15, 2026 08:58
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
Preserve the reviewed component delta while including the canonical CI fixture and shard ownership repairs.
Require native exit before initialization failure rejection and retain queued
admission custody without granting an exited Worker.

Related: #130741
Merge main eee60cd while retaining published head
1beae4f as ancestry. Preserve the reviewed WAL
delta and its 512-page maintenance bound. Focused integration proof passed
140 tests; two Node 26.8 diagnostic cases remain explicitly skipped.
Propagate the existing poisoned-transaction error after deferred maintenance so reclamation retains its writer until native exit. Cover real periodic vacuum failures and successful rollback or close cleanup through the retained worker.
Preserve queued WAL maintenance and the native-settlement guard while incorporating current archive reads, maintenance preparation, and reader cleanup.
@steipete
steipete force-pushed the codex/swarm-periodic-wal-admission-20260915 branch from 178bd14 to d2c44d3 Compare September 16, 2026 03:14
@steipete steipete self-assigned this Sep 16, 2026
@steipete
steipete merged commit 18401b6 into main Sep 16, 2026
200 of 202 checks passed
@steipete
steipete deleted the codex/swarm-periodic-wal-admission-20260915 branch September 16, 2026 08:16
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…nclaw#148941)

* fix(sqlite): admit periodic agent maintenance through its writer

* test(sqlite): await queued vacuum after reclamation settlement

* test(sessions): cover Worker failure and admission settlement

Require native exit before initialization failure rejection and retain queued
admission custody without granting an exited Worker.

Related: openclaw#130741

* fix(sqlite): retain worker admission after failed maintenance

Propagate the existing poisoned-transaction error after deferred maintenance so reclamation retains its writer until native exit. Cover real periodic vacuum failures and successful rollback or close cleanup through the retained worker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant