Skip to content

fix(state): tolerate brief WAL coordinator contention - #157121

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-wal-maintenance-contention-20260919
Sep 24, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-wal-maintenance-contention-20260919

Conversation

@steipete

@steipete steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157064

What Problem This Solves

A brief lifecycle lock held by another CLI process makes shared-state WAL maintenance abandon its checkpoint, emit an anonymous error, and leave history eviction waiting for completion.

User Impact

Maintenance can finish through short coordinator holds. Persistent contention remains visible in status and Doctor, repeated logs are throttled, and Linux diagnostics identify the observed holder. A completed checkpoint clears the existing history-eviction gate. No configuration, schema, durability, retention, or update migration changes are required.

Why This Change Was Made

Allow 350 ms for maintenance acquisition and retry a refused periodic attempt once after one second. The checkpoint owner records contention as blocked; health warnings remain eligible after two refusals, while log callbacks occur every fifth refusal. Completion resets the count, and close cancels the retry. Writer admission and checkpoint thread placement stay with their existing owners.

Linux holder attribution reads kernel locks by device and inode and reports PID, process start time, command, and family. The snapshot is diagnostic only; SQLite still owns exclusion. Unsupported platforms and unavailable procfs observations report unknown, and coordinator files remain write-free.

Rebased onto main b9da50953aa88b0c9cb021e447b9542e555c4edb. Dropped the separate CI-routing commit, including .github/workflows/ci.yml, scripts/changed-lanes.mts, scripts/lib/tsgo-core-test-shards.mts, docs/ci.md, and test/scripts/ci-workflow-planning.test.ts; those files match main. No separate CI PR was created. The only tooling change is one entry in scripts/pr-lib/wrapper-components.txt: the standalone wrapper must package the new coordinator-owner module or its state-lease imports fail.

Evidence

All new validation ran on Blacksmith Testbox tbx_01m39skzsqt0mndkcvehssyz3f (runner). No local tests, typechecks, or builds ran.

  • The 12 selected files passed all 192 tests in seven Vitest groups: checkpoint/WAL, coordinator acquisition and delegation, shared-state coordination, history eviction and WAL budget recovery, status/Doctor, wrapper import closure, and the previously failing missing-subagent-task file. Testbox command wall time was 132.07 s, including cold compiler preparation.
  • The old checks-node-compact-small-8 failure was real: eager-import-closure.test.ts could not resolve state-database-coordinator-owner.js in the extracted wrapper. The manifest entry fixes the missing runtime module; all 15 existing wrapper-closure cases now pass.
  • The old checks-node-changed-compact-large-2 failure counted two warning records in subagent-completion-admission.task-missing.test.ts; its wake-count assertions passed. All five cases now pass unchanged on this candidate. The extra old warning's source is unproven, so this is not claimed as a repaired flake.
  • Full-main CI run 36001885009 at b39eca3dd5da has successful subagent-support and all 13 UI E2E jobs, including the suites containing the two prior UI failures. No UI source changes are included here.
  • Independent Codex autoreview of the complete reduced diff is clean through P2. git diff --check passes.

The first Testbox invocation stopped before testing because the synchronized checkout lacked dependencies. pnpm install --frozen-lockfile repaired that setup, and the focused command then passed. Existing regression proof from the original PR demonstrated failure before the fix for the 200 ms foreign hold and warning cadence; the single-worker checkpoint and shared-state coordinator files previously measured 1.35 s and 20.35 s cold wall respectively.

node scripts/check-changed.mjs --base b9da50953aa88b0c9cb021e447b9542e555c4edb passed in 37m28.96s command wall: core plus all 25 core-test type graphs, formatting, lint, all three export scans, and every selected guard. The remote execution directory and hashes of all ten candidate files were verified before this command. The final head is b3b4335f82d4b873870a90ebac366c78a48b41b0; hosted CI is tracked on that rewritten head. The Testbox lease was stopped after validation. Linux holder attribution is covered; no macOS/Windows holder-attribution or production deployment proof is claimed.

@clawsweeper

clawsweeper Bot commented Sep 24, 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 docs Improvements or additions to documentation size: M labels Sep 24, 2026
@steipete
steipete enabled auto-merge (squash) September 24, 2026 07:29
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 10:21 AM ET / 14:21 UTC (Revision 6).

ClawSweeper review

What this changes

The branch adds a short wait and retry for shared-state SQLite WAL checkpoints, Linux lock-holder diagnostics, tests, documentation, and wrapper packaging.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

The short-lock recovery remains useful because current main does not provide it. The earlier review’s blocker remains: a reader-blocked checkpoint followed by coordinator contention resets the warning streak, suppressing the documented Status and Doctor warning.

Priority: P2
Reviewed head: b3b4335f82d4b873870a90ebac366c78a48b41b0

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The real SQLite contention test supports the recovery claim, but the unresolved warning-streak defect blocks the current patch.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed shared-state checkpoint owner is exercised through the production database opening path with a separate process holding a real SQLite coordinator lock for 200 ms; the reported Testbox pass includes the assertion that the checkpoint completes in the same cycle. That proof does not cover the reader-then-coordinator warning defect. No stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed shared-state checkpoint owner is exercised through the production database opening path with a separate process holding a real SQLite coordinator lock for 200 ms; the reported Testbox pass includes the assertion that the checkpoint completes in the same cycle. That proof does not cover the reader-then-coordinator warning defect. No stored-data contract changes.
Evidence reviewed 9 items Introduced warning reset: Coordinator contention increments the previous count only when the previous health snapshot has blockingOwner. A reader-blocked snapshot has no such field, so the next refusal records count one.
Existing warning contract: The existing documentation says Status and Doctor warn after two consecutive blocked checkpoints; the branch's new text also describes warning after two refusals.
Warning consumer: The formatter returns no Status or Doctor warning when health.warning is false.
Findings 1 actionable finding [P2] Preserve the blocked streak across both contention types
Security None None.

How this fits together

OpenClaw periodically checkpoints the shared-state SQLite database behind a process coordinator. Its checkpoint observations feed Status and Doctor warnings and clear a history-eviction deferral after completion.

flowchart LR
A[Shared state database] --> B[Periodic WAL maintenance]
C[Other process lock] --> D[Coordinator admission]
B --> D
D --> E[Checkpoint result]
E --> F[Status and Doctor]
E --> G[History eviction gate]
Loading

Before merge

  • Preserve the blocked streak across both contention types (P2) - After a reader-blocked checkpoint, blockingOwner is absent even though consecutiveBlocked is one. A coordinator refusal therefore takes the zero branch here, records another count of one, and suppresses the documented two-observation Status and Doctor warning. The earlier review raised this sequence; add a mixed-order regression and count the preceding blocked observation.
  • Resolve merge risk (P1) - Mixed reader and coordinator contention can leave a blocked WAL checkpoint without the Status and Doctor warning promised after two consecutive blocked observations.
  • Complete next step (P2) - Preserve the blocked streak across reader and coordinator contention and add a regression for that order before merge.

Findings

  • [P2] Preserve the blocked streak across both contention types — src/infra/sqlite-wal-checkpoint.ts:155-156
Agent review details

Security

None.

PR surface

Source +89, Tests +101, Docs +10, Other +1. Total +201 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 99 10 +89
Tests 2 102 1 +101
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 10 212 11 +201

Review metrics

Metric Value Why it matters
Code and test growth production +89 net lines, tests +101 net lines The PR explains the production growth chiefly through the 52-line Linux holder diagnostic and adds focused checkpoint coverage.
Maintenance timing wait 0→350 ms; one retry after 1 s These are the new contention bounds operators would receive without a configuration change.

Merge-risk options

Maintainer options:

  1. Repair the warning streak (recommended)
    Carry the blocked count across reader and coordinator refusals and prove that order in a focused regression before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve one consecutive blocked-observation streak across reader-blocked checkpoints and coordinator contention; add a regression for reader then coordinator, while retaining the existing log cadence.

Technical review

Best possible solution:

Keep the bounded coordinator wait and retry, while counting every consecutive blocked checkpoint until completion and preserving the intended contention-log cadence.

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

Yes, from source: a reader-blocked checkpoint followed by coordinator contention records count one and no warning. This read-only review did not execute that mixed-order sequence.

Is this the best way to solve the issue?

No, not yet. The existing checkpoint owner is the right place for the wait and retry, but its health count must preserve the documented warning threshold across both blocker types.

Full review comments:

  • [P2] Preserve the blocked streak across both contention types — src/infra/sqlite-wal-checkpoint.ts:155-156
    After a reader-blocked checkpoint, blockingOwner is absent even though consecutiveBlocked is one. A coordinator refusal therefore takes the zero branch here, records another count of one, and suppresses the documented two-observation Status and Doctor warning. The earlier review raised this sequence; add a mixed-order regression and count the preceding blocked observation.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 85af71525401.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded shared-state maintenance improvement with a concrete warning regression, not an immediate core outage.
  • merge-risk: 🚨 other: The introduced health-count condition can suppress a documented operational warning under mixed contention.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The changed shared-state checkpoint owner is exercised through the production database opening path with a separate process holding a real SQLite coordinator lock for 200 ms; the reported Testbox pass includes the assertion that the checkpoint completes in the same cycle. That proof does not cover the reader-then-coordinator warning defect. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed shared-state checkpoint owner is exercised through the production database opening path with a separate process holding a real SQLite coordinator lock for 200 ms; the reported Testbox pass includes the assertion that the checkpoint completes in the same cycle. That proof does not cover the reader-then-coordinator warning defect. No stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/infra/sqlite-wal-checkpoint.test.ts src/state/openclaw-state-db.coordinator.test.ts.
  • [P1] node scripts/check-changed.mjs --base main.

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve the warning streak across a reader block followed by coordinator contention and add that regression.

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 (5 earlier review cycles)
  • reviewed 2026-09-24T07:34:39.064Z sha 8c7c437 :: blocked before merge. :: [P2] Preserve early WAL health warnings while throttling logs
  • reviewed 2026-09-24T07:57:17.362Z sha a22afc3 :: blocked before merge. :: [P2] Count reader and coordinator blocks in one warning streak
  • reviewed 2026-09-24T10:19:02.584Z sha e59f5fe :: blocked before merge. :: [P2] Preserve the warning streak across reader and coordinator blocks
  • reviewed 2026-09-24T10:43:04.874Z sha e59f5fe :: blocked before merge. :: [P2] Preserve the warning streak across reader and coordinator blocks
  • reviewed 2026-09-24T12:03:23.575Z sha 2574c55 :: blocked before merge. :: [P2] Preserve the blocked streak across reader and coordinator contention

@steipete
steipete disabled auto-merge September 24, 2026 07:43
@steipete
steipete enabled auto-merge (squash) September 24, 2026 07:50
@steipete
steipete disabled auto-merge September 24, 2026 08:52
@steipete
steipete enabled auto-merge (squash) September 24, 2026 10:07
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 24, 2026
Wait briefly for WAL maintenance admission, retry a blocked periodic pass once, and report repeated contention with Linux holder identity. Preserve native SQLite exclusion and publish completed checkpoints through the existing eviction gate.
Keep status and Doctor warning eligibility after two coordinator refusals while throttling maintenance logs to every fifth refusal.
Package the holder-attribution module with the standalone wrapper so state lease bootstrap and extracted runtime import closure stay complete.
@steipete
steipete force-pushed the steipete/perf-micro-wal-maintenance-contention-20260919 branch from 2574c55 to b3b4335 Compare September 24, 2026 14:12
@steipete
steipete disabled auto-merge September 24, 2026 14:16
@steipete
steipete enabled auto-merge (squash) September 24, 2026 14:16
@steipete
steipete merged commit 1b32a8b into main Sep 24, 2026
220 of 221 checks passed
@steipete
steipete deleted the steipete/perf-micro-wal-maintenance-contention-20260919 branch September 24, 2026 14:39
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '9ccfc7d1bea21e34da48edbd54afd2e1be57db40': (89 commits)
  fix(exec): avoid gateway stalls during background task writes (#157177)
  test(cli): isolate preaction title setter state
  fix(test): synchronize Git backoff cancellation readiness (#157315)
  fix: validate Codex model references in Docker (#157175)
  fix(state): tolerate brief WAL coordinator contention (#157121)
  fix: unblock conversations after recovery preparation fails (#157214)
  test(telegram): avoid wall-clock pacing in HTTP conformance (#157281)
  fix: keep independent database work responsive under load (#157230)
  refactor(sqlite): centralize WAL checkpoint execution (#157263)
  improve(android): show tool outcomes in collapsed work (#156950)
  fix: remove tracked release scratch blocking source capture (#157308)
  test(update): remove legacy probe stream ordering race
  fix: preserve steering across reconnects and show queued input (#157135)
  fix(ui): keep typing focus when the GitHub reader opens (#157202)
  fix(ios): keep screenshot logs outside capture evidence
  test(codex): await startup teardown in lifecycle fixtures
  chore(ui): refresh control ui locales (#157311)
  refactor(memory): deslop memory plugins (#156867)
  refactor(test): share CLI diagnostics fixture setup (#157201)
  fix(release): retry notarization submit/wait on transport failures and name the resume command (#157116)
  ...
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
Bound WAL maintenance waits with backoff, warn once per run of blocked cycles, and record the coordinator holder so contention names its process.
amittell added a commit to amittell/openclaw that referenced this pull request Oct 2, 2026
Peter Steinberger's upstream fix, merged to main 2026-09-24, after the
9.6 tag. Shared-state WAL maintenance now waits up to 350 ms for the
lifecycle coordinator instead of failing at once. A contended periodic
pass records "blocked" health rather than "error", retries once after
1 s, and calls onCheckpointError only on every fifth consecutive block;
health turns to a warning from the second. The contention error names
the coordinator's holder (pid, start time, command) when it can read
one; that reader uses /proc/locks, so off Linux the holder stays
"unknown" and the message is unchanged.

Applied with cherry-pick -x and one adaptation. Upstream's retry chains
on the periodic scheduler's promise, which arrived with openclaw#155631's
page-budget scheduler; that change is not carried. Here
createSqliteWalMaintenanceScheduler returns a promise that settles when
its attempt (or the one already admitted) has run, and resolves at once
on the unadmitted path, which still runs synchronously. Its one caller
is configureSqliteWalMaintenance.

Conflicts: sqlite-wal.ts, the interval callback calls
maintainPeriodically(); sqlite-wal-checkpoint.test.ts, upstream's new
test is inserted before the tag's (synchronous) next test, and no
existing test changed. The other files auto-merged; the new owner
module and the errors module equal upstream's blobs.

Tests on the branch: sqlite-wal-checkpoint 13/13 and
openclaw-state-db.coordinator 14/14, including both new upstream tests;
the Linux-only holder assertions do not run on macOS. With eight WAL
and coordinator neighbor files: 10 files, 115 passed, 8 skipped.

(cherry picked from commit 1b32a8b)
amittell added a commit to amittell/openclaw that referenced this pull request Oct 2, 2026
… the 9.6 carry

Records the three upstream ports (openclaw#156583, openclaw#157834, openclaw#157121), why
openclaw#155988 was not carried, the /tools/invoke loop-detection fix, the
review left-overs, and the validation run on this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant