Skip to content

fix(state): healthy Gateway starts log SQLite lock-wait warnings for retried lease work - #167754

Merged
steipete merged 3 commits into
mainfrom
codex/stab-state-lifecycle-noise
Oct 9, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/stab-state-lifecycle-noise

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: almost every Gateway start logs a SQLite "lock wait failed" warning for shared-state lease work that is already retried, so operators see lock-contention warnings on healthy starts:

[sqlite/transaction] SQLite transaction lock wait failed async=false busyTimeoutMs=0 database=<state>/state/openclaw.sqlite operation=plugins.lifecycle.lease code=ERR_SQLITE_ERROR elapsedMs=0 failureKind=lock-contention ...
[sqlite/transaction] SQLite transaction lock wait failed async=false busyTimeoutMs=0 ... operation=workspace.local-reconciliation ...

On a dev Gateway with lived-in state this appeared 13 times over 16 starts.

User Impact

Healthy starts no longer log lock-contention warnings for lease renewal/release attempts that the lease owner already retries or lets expire. Ordinary transaction contention and COMMIT failures still report as before; lease errors, authority checks, retry budgets, and persistence are unchanged.

Why This Change Was Made

Both lease callers acquire through workers with a 5 s busy timeout; their zero-timeout paths are renewal and release, whose BEGIN contention is handled by the existing lease retry and expiry logic. The generic BEGIN reporting in src/infra/sqlite-transaction.ts still logged those expected try-lock failures. The lease write owner (src/state/openclaw-state-lease-storage.ts) now marks its BEGIN contention as handled across the native, existing-schema, and worker writer paths, and duplicate worker wrappers were removed. Production +66/−58.

Shutdown WAL checkpoint TRUNCATE remained busy (also seen on many clean shutdowns) was investigated but is not changed here: the logs cannot attribute the blocker, and shutdown checkpoint ordering falls under the storage approval checkpoint.

Evidence

  • Live on a dev Gateway with two days of lived-in state: main logged the warning on ~13 of 16 starts; this branch, three consecutive starts/clean stops: 0 lock-wait warnings.
  • pnpm test src/state/openclaw-state-lease-diagnostics.test.ts --maxWorkers=1: 3 failed / 1 passed with the original production code (the unwanted warning assertions), 4 passed with the fix (20 s wall).
  • Ten targeted suites (lease diagnostics/contention/worker/async/maintenance, state-db async lifecycle and open, gateway server-close and shutdown, sqlite-transaction): 153 passed. Types, lint, format, import cycles (0), build pass.

Landing validation

  • Focused lease diagnostics and SQLite transaction suites: 32 passed across two shards, 28.82 s total; diagnostics shard 23.70 s (4 cases). Ordinary BEGIN contention and COMMIT contention remain visible; failed release leaves the lease unchanged, and a later successful release removes it.
  • Independent Codex autoreview found no actionable issues.
  • CI run 37911652063 failed checks-fast-baseline-ratchets on an inherited stale assertion allowance: src/config/sessions/session-accessor.sqlite-read.ts: 2 < 3. Main fixed that exact allowance in cff1f4f. Merged main for that named failing gate, producing a30bd35; the PR delta has the same stable patch ID. pnpm check:assertion-safety --base origin/main passes after the merge. No workflow rerun was requested.
  • CI run 37912360699 passed the baseline ratchet but failed check-test-types-core-1 on an inherited Windows lifecycle fixture (src/cli/update-cli.windows-lifecycle.test.ts:545, TS2554: listener called without its signal). The error also reproduced on the older main checkout. Main fixed it in 3223e13; merging that named gate fix produced a013a01. The focused node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.cli-update.json --noEmit check passes after the merge, and the lease fix retains the same patch ID.
  • ClawSweeper completed reviews of both f46077d and a30bd35 with no findings; current-head review and CI remain required before landing.

Inherited CI exception

CI run 37913649528, attempt 1, failed checks-node-changed-compact-large-15 (job 113764943537) in server-close.memory.test.ts, case “joins accepted Memory sync through Gateway close without reopening its executor between publications”: memory-core dreaming SQLite state store is not configured. The identical error reproduces on main b92562c without this PR (1 failed, 2 skipped; 44.46 s). The test, its fixture, and the reported failure-path sources are unchanged between that main snapshot, tested baseline 3223e13, and this PR. The runtime-store lookup fails before Memory workspace lock acquisition, independently of the lease BEGIN diagnostic change.

The failed CI checkout is d6eef5bac41b3ac78a863b40d9815b6e46ca1153, with ordered parents 3223e13 and a013a01. The aggregate gate names that single root failure; the successful fail-fast monitor cancelled five sibling jobs. Those cancellations remain incomplete coverage, not passing checks. Security-fast and the scoped lease proof passed. Landing uses the explicitly authorized native pre-existing-failure exception; no unrelated Memory fix or workflow rerun is included.

Let lease owners handle expected nonblocking BEGIN failures while preserving ordinary contention and commit diagnostics. Share native and worker lease write policy, including existing-schema writers, without changing retry or authority semantics.
@clawsweeper

clawsweeper Bot commented Oct 9, 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 Oct 9, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR stops misleading SQLite lock-wait warnings for nonblocking lease renewal and release attempts whose contention is already handled by the lease owner.

Example: An operator starts the Gateway while plugin lifecycle lease work encounters database contention.

  • Before: A handled attempt logs “SQLite transaction lock wait failed” with operation=plugins.lifecycle.lease and busyTimeoutMs=0.
  • After: The handled BEGIN contention produces no transaction warning, while ordinary contention and COMMIT failures retain their diagnostics.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, narrow diagnostic correction supported by reported real Gateway behavior and focused regressions, with no actionable defect identified.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The complete body reports three real dev-Gateway starts and clean stops with lived-in state producing zero lock-wait warnings, compared with approximately 13 warning-bearing main starts out of 16. This exercises lease diagnostics through Gateway startup; real-SQLite regression cases supplement the observation. Source confirms no stored-data contract or migration changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators see SQLite lock-failure warnings during healthy Gateway starts even though the lease owner already handles the contention.
Reason: The warning incorrectly suggests failed work, and the recorded area-owner decision accepts correcting it without changing lease semantics.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main retains the misleading diagnostics, the area owner accepted the narrow correction, and no actionable patch defect was found.

Priority: P3
Reviewed head: a013a0160ff122cc0d3197d0c7528022987bf8a3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared SQLite database stores temporary leases that coordinate Gateway work. Lease owners acquire, renew, and release them through database transactions with existing retry, expiry, and authority checks.

flowchart TD
  A[Gateway lifecycle work] --> B[Lease owner]
  B --> C[Shared lease writer]
  C --> D[SQLite transaction]
  D --> E{Failure phase}
  E -->|Nonblocking lease BEGIN| F[Return error without transaction warning]
  E -->|Ordinary BEGIN or COMMIT| G[Preserve transaction warning]
  F --> B
Loading

Technical review

Best possible solution:

Keep diagnostic policy in the shared lease writer while preserving the existing transaction, retry, expiry, and authority owners.

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

Yes: zero-timeout lease BEGIN contention reaches generic failure reporting before the lease owner handles it. Source supports the reported Gateway observations and base-failing regressions; this review did not execute them.

Is this the best way to solve the issue?

Yes: the shared lease-write boundary selects the narrow reporting policy, preserving error propagation, acquisition waits, COMMIT diagnostics, and authority checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned delta and review continuity: The complete introduced diff was inspected. Comparing the previous reviewed head with this head shows no changes to the reviewed lease, transaction, or documentation paths; the previous review recorded no findings. (a013a0160ff1)
  • Suppression preserves error propagation: The new condition suppresses only BEGIN lock reporting when requested; COMMIT reporting remains enabled and the original error is still thrown. (src/infra/sqlite-transaction.ts:310, a013a0160ff1)
  • Shared lease policy and timeout ownership: The lease writer requests suppression only for a zero busy timeout and forwards it through native and existing-schema writers. The managed transaction owner already applies and restores the timeout, supporting removal of the redundant outer wrappers. (src/state/openclaw-state-lease-storage.ts:73, a013a0160ff1)
  • Authority and stored state preserved: Worker renewal retains transaction and commit ownership checks; release retains admission and physical database identity checks at both stages. Acquisition retains its nonzero timeout. No SQL mutation, schema, stored format, permission, or authority grant changes. (src/state/openclaw-state-lease-worker.ts:230, a013a0160ff1)
  • Current main still needs the correction: Fetched main retains the old lease writer and generic BEGIN reporting. No changes between the pinned base and fetched main affect the production paths changed by this PR; the related merged PRs establish earlier owners rather than replacing this correction. (src/state/openclaw-state-lease-storage.ts:67, 9490c112abba)
  • Reported real Gateway behavior: The fully read PR body reports warning-bearing starts on approximately 13 of 16 main runs, followed by three branch starts and clean stops with zero lock-wait warnings using lived-in state. It also reports three intended failures with original production code and four passing diagnostic cases after the fix. These are contributor observations, not reviewer-executed tests. Captured source identity: 52a2f6050a685c708d7cfbf274121e84c0d81ba796148ae6c55d766f85acb1e8; REST supplied the complete matching body. (a013a0160ff1)

Likely related people:

  • Peter Steinberger: Raw commit 65bc5f6 adds src/state/openclaw-state-lease-worker.ts:105 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 65bc5f6ed94d; files: src/state/openclaw-state-lease-worker.ts)

PR surface

Source +8, Tests +131, Docs +4. Total +143 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 66 58 +8
Tests 1 131 0 +131
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 201 58 +143

Review metrics

Metric Value Why it matters
Production versus tests Production +66/−58, net +8; tests +131/−0 Small production growth is justified by shared diagnostic policy and removal of redundant wrappers; regression cases protect reporting and stored lease outcomes.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: The demonstrated impact is misleading warnings during otherwise healthy Gateway starts, without a workflow failure.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-09T09:34:54.656Z sha f46077d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T09:42:41.161Z sha a30bd35 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 6:03 AM ET / 10:03 UTC (Revision 3).

Merge cff1f4f to fix the named checks-fast-baseline-ratchets failure from CI run 37911652063. The failure was inherited from the main merge base: src/config/sessions/session-accessor.sqlite-read.ts had 2 assertions against an allowance of 3. The assertion safety ratchet now passes. The reviewed lease diagnostics delta is unchanged.
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper approve

Maintainer decision (coordinator for Peter, 2026-10-09): diagnostics-only fix - expected, already-retried lease try-lock contention is not reported as a lock-wait failure; no lease, schema, or durability semantics change.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 9, 2026
CI run 37912360699 failed check-test-types-core-1 on the inherited zero-argument SIGINT listener call in src/cli/update-cli.windows-lifecycle.test.ts. Main repaired that call in 3223e13. The same error reproduces on the older main tooling checkout; the focused CLI update typecheck passes after this merge. Lease diagnostics patch ID is unchanged.
@steipete
steipete merged commit d44b2f6 into main Oct 9, 2026
168 of 177 checks passed
@steipete
steipete deleted the codex/stab-state-lifecycle-noise branch October 9, 2026 10:10
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
Let lease owners handle expected nonblocking BEGIN failures while preserving ordinary contention and commit diagnostics. Share native and worker lease write policy, including existing-schema writers, without changing retry or authority semantics.
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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