Skip to content

fix(state): avoid gateway stalls during WAL coordination - #157484

Merged
steipete merged 4 commits into
mainfrom
codex/wal-maintenance-admission-20260924
Sep 24, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/wal-maintenance-admission-20260924

Conversation

@steipete

@steipete steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157121

What Problem This Solves

Fixes Gateway pauses during periodic shared-state database maintenance when another process holds the lifecycle coordinator.

User Impact

The Gateway can keep servicing events while maintenance waits for coordination. The existing 350 ms contention budget, short-wait recovery, blocked-health reporting, and retry cadence remain intact.

Why This Change Was Made

Periodic maintenance uses the existing asynchronous acquisition owner and rechecks the current database handle and physical file immediately before SQL. Retirement cancels and joins pending admission. Failed coordinator release remains owned until canonical cleanup succeeds, including when a symlink target changes. Explicit synchronous checkpoint and close behavior is preserved; no schema, migration, retention, permission, or environment-setting change is introduced.

Evidence

Linux/Node 24.19 proof reproduces a 371.3 ms callback stall on the original process main thread. Four causal negative controls cover blocking acquisition, yielding only once, lost holder attribution, and failed-release custody. The revised path keeps servicing independently acknowledged turns while preserving successful short-contention maintenance.

284 focused/sibling/wrapper/routing cases passed, with 54 affected cases rechecked after canonical main integration. Core types and all 25 test graphs passed; affected types and all reported lint failures were rechecked on the integrated head. Formatting, dependency, schema, legacy-store, script lint, import-cycle, webhook, and pairing guards passed. Managed review is clean through P2.

The coordinator tests now use buffered checkpoint events and child-process acknowledgments instead of pacing sleeps or polling. All three affected negative controls still fail for their intended reasons; 60 positive cases passed.

Single-worker cost on Linux/Node 24.19 in the CI-backed Testbox:

Test file Reported case time, summed Vitest duration Full command wall time
openclaw-state-db.coordinator.test.ts (19 cases) 3.266 s 6.20 s 29.004 s
state-database-coordinator-acquisition.test.ts (9 cases) 0.073 s 0.795 s 2.018 s

The coordinator command includes 19.975 s preparing the real SQLite worker runtime. Reported case totals exclude harness setup/teardown; the full command measurements include it. For ordinary PR CI at 1156d99, the complete workflow spanned 1318 seconds across 166 jobs (44591 summed job seconds, including setup and all selected checks).

The isolated full build and ordinary CI at 1156d99 passed. The enforced Security Review also passed before native landing as 7a052255f8d6876a3132b845ce37ffcf392ac546. Source proof does not establish that deployed event-loop stalls have been eliminated.

@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 scripts Repository scripts size: L labels Sep 24, 2026
@steipete
steipete marked this pull request as ready for review September 24, 2026 18:33
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 5:22 PM ET / 21:22 UTC (Revision 2).

ClawSweeper review

What this changes

The branch makes periodic shared-state SQLite maintenance wait asynchronously for lifecycle coordination, rechecks the database before SQL, and adds cancellation, cleanup, tests, and documentation.

Regression provenance

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

Merge readiness

✅ Ready for maintainer review

Current main still makes the periodic checkpoint wait synchronously for lifecycle coordination, so this PR remains useful. The earlier test-timing finding is addressed on the current head, and this review found no introduced blocking defect.

Priority: P2
Reviewed head: 1156d990a1d215840ecb4e14ecb1774e8ec488f7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair has focused production-path process coverage and no identified blocking defect; the reported measurements remain distinct from completed exact-head CI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed cache-owned admission is exercised through the real periodic timer and native SQLite coordinator: a child process holds the lock while acknowledgments show the process can service turns, and checkpoint events show completion after release. The PR reports Linux/Node 24.19 after-fix results; no stored-data format changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed cache-owned admission is exercised through the real periodic timer and native SQLite coordinator: a child process holds the lock while acknowledgments show the process can service turns, and checkpoint events show completion after release. The PR reports Linux/Node 24.19 after-fix results; no stored-data format changes.
Evidence reviewed 7 items Current main remains synchronous: The fetched main revision still passes a 350 ms timeout to synchronous lifecycle-coordinator acquisition for WAL maintenance.
Introduced periodic admission: The new cache-owned path awaits coordinator acquisition, then checks current admission, the open handle, and physical file identity immediately before the operation.
Cancellation and cleanup: Retirement cancels WAL admission; asynchronous resource close joins pending work and retains a failed coordinator release for retry.
Findings None None.
Security None None.

How this fits together

OpenClaw stores shared Gateway state in SQLite. A periodic timer maintains its write-ahead log, while lifecycle coordination controls when that maintenance can use the open database; checkpoint health feeds status and Doctor.

flowchart LR
  A[Gateway shared state] --> B[SQLite database]
  C[Periodic maintenance timer] --> D[Lifecycle coordination]
  D --> E[Check live database and file]
  E --> F[WAL checkpoint]
  F --> G[Status and Doctor health]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +151, Tests +364, Docs +4, Other +1. Total +520 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 165 14 +151
Tests 3 388 24 +364
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 11 559 39 +520

Review metrics

Metric Value Why it matters
Production and test delta production +165/−14 lines; tests +387/−24 lines The production growth has a stated lifecycle and cancellation purpose; the larger test change exercises real coordinator ownership.
Reported single-worker cost 29.004 s coordinator suite; 2.018 s acquisition suite The coordinator suite is near the repository's 30-second explanation threshold, including reported SQLite-worker preparation.

Technical review

Best possible solution:

Keep the existing lifecycle coordinator as the sole checkpoint gate and land the bounded periodic-wait repair after the normal exact-head gates complete.

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

Yes, the source-defined path is clear: hold the lifecycle coordinator in another process and trigger the periodic timer on current main, where acquisition waits synchronously for up to 350 ms. This review did not execute that path.

Is this the best way to solve the issue?

Yes. The patch uses the existing coordinator owner, preserves explicit synchronous maintenance, and checks current database ownership and file identity before periodic SQL.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A periodic contention stall affects Gateway responsiveness, but the reported wait is bounded and the affected path is limited.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed cache-owned admission is exercised through the real periodic timer and native SQLite coordinator: a child process holds the lock while acknowledgments show the process can service turns, and checkpoint events show completion after release. The PR reports Linux/Node 24.19 after-fix results; no stored-data format changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed cache-owned admission is exercised through the real periodic timer and native SQLite coordinator: a child process holds the lock while acknowledgments show the process can service turns, and checkpoint events show completion after release. The PR reports Linux/Node 24.19 after-fix results; no stored-data format changes.

Evidence

What I checked:

  • Current main remains synchronous: The fetched main revision still passes a 350 ms timeout to synchronous lifecycle-coordinator acquisition for WAL maintenance. (src/state/openclaw-state-db-open.ts:146, a219fa50a0a9)
  • Introduced periodic admission: The new cache-owned path awaits coordinator acquisition, then checks current admission, the open handle, and physical file identity immediately before the operation. (src/state/openclaw-state-db-cache.wal.ts:87, 1156d990a1d2)
  • Cancellation and cleanup: Retirement cancels WAL admission; asynchronous resource close joins pending work and retains a failed coordinator release for retry. (src/state/openclaw-state-db-cache.wal.ts:56, 1156d990a1d2)
  • Production-path regression coverage: The coordinator tests open a real SQLite database, use a child process to hold the lifecycle coordinator, acknowledge event-loop turns, and observe checkpoint completion, file replacement refusal, retirement, and failed-release cleanup. The PR body reports Linux/Node 24.19 measurements; this read-only review did not execute the tests. (src/state/openclaw-state-db.coordinator.test.ts:354, 1156d990a1d2)
  • Earlier review finding addressed: The current tests use checkpoint events and child-process acknowledgments for the transitions cited in the prior P3 finding. The PR body also reports single-worker wall times. A direct diff against the earlier reviewed head could not be completed because Git could not retrieve an older promisor object. (src/state/openclaw-state-db.coordinator.test.ts:106, 1156d990a1d2)
  • Related merged history: The earlier merged short-contention change established the 350 ms synchronous WAL-maintenance wait. This PR addresses the event-loop effect of that wait rather than replacing the earlier contention behavior. (src/state/openclaw-state-db-open.ts:146, 1b32a8b3c7fc)

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 (1 earlier review cycle)
  • reviewed 2026-09-24T18:51:51.585Z sha 4d3092c :: needs changes before merge. :: [P3] Use event signals in the new coordinator tests

@steipete
steipete merged commit 7a05225 into main Sep 24, 2026
221 of 223 checks passed
@steipete
steipete deleted the codex/wal-maintenance-admission-20260924 branch September 24, 2026 21:45
@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 25, 2026
…7484)

* fix(state): avoid gateway stalls during WAL coordination

* test(state): observe WAL checkpoints without polling
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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