Skip to content

fix: Gateway startup stops during temporary state maintenance - #166108

Closed
ericcaiwx-star wants to merge 2 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-166088-state-read-admission
Closed

ericcaiwx-star wants to merge 2 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-166088-state-read-admission

Conversation

@ericcaiwx-star

@ericcaiwx-star ericcaiwx-star commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #166088.

This PR repairs the temporary schema-owner contention part of that report. The broader Windows launcher, Scheduled Task, and Node Host symptoms remain outside this patch.

What Problem This Solves

Gateway startup discovery can abort immediately while another OpenClaw process briefly holds the shared-state schema lease. The cold snapshot owner receives StateDatabaseAdmissionPendingError before it prepares a private snapshot, but previously treated that temporary condition as terminal maintenance.

Why This Change Was Made

withOpenClawStateDatabaseReadSnapshot now waits only when all of these remain true:

  • the refusal is the existing typed StateDatabaseAdmissionPendingError;
  • it names the same resolved database;
  • the existing five-second SQLite admission budget has not expired; and
  • the caller has not cancelled.

The retry remains before admission capture and snapshot preparation, so it does not replay the callback or prepared work. Genuine offline maintenance, another database's custody, cancellation, and exhausted contention still refuse. This changes no schema, stored data, config, dependency, or permission contract.

User Impact

Startup discovery can recover when temporary foreign schema custody releases. A cancelled caller never enters the callback, persistent contention remains bounded, and ordinary maintenance is not admitted.

Evidence

Current implementation head: 518a645ae50e0c3a002aa3e75b8facc9b115b3ae, rebased cleanly onto 889611b388c4a219468f881e192e45ede2c6d3e1 after the independent fixture repair #166370 merged. git range-diff reports both patch commits unchanged by the rebase.

Real production-boundary proof

Windows / Node 26.7.0 proof used a fresh synthetic database, a separate process holding the production acquireStateDatabaseSchemaLease, and the production snapshot reader. It did not fabricate owner records, inject errno values, use operator state, or mock the changed production functions.

  • Named baseline 78e8de276bd2d31ed0996338100543c27adb4235: immediate admission refusal, exit 1, recorded by ocpr prove.
  • Prior exact implementation head d0a218e7d7ec42349aa4e96ff06d7dd5608c791a: recovery after release, exit 0, re-executed on Windows and recorded by ocpr prove. The observed boundary duration was 4,566 ms, including snapshot work and cleanup; it is not a claim that admission waited that long.
  • Additional prior-head controls: one callback after release; zero callbacks for cancellation, genuine maintenance, and exhausted contention.

The rebase did not change either patch commit or the two changed-file blobs. The Windows traces above are retained as prior-head production-boundary evidence; they are not relabeled as execution at the new SHA.

Prior-head Windows control outcomes, exit 0 (synthetic paths redacted):

{"platform":"win32","mode":"release","elapsedMs":1882,"callbackCount":1,"observed":{"admitted":true}}
{"platform":"win32","mode":"cancelled","elapsedMs":139,"callbackCount":0,"observed":{"admitted":false,"cause":"aborted","pending":false,"aborted":true}}
{"platform":"win32","mode":"maintenance","elapsedMs":128,"callbackCount":0,"observed":{"admitted":false,"pending":false,"aborted":false}}
{"platform":"win32","mode":"exhausted","elapsedMs":5084,"callbackCount":0,"observed":{"admitted":false,"pending":true,"aborted":false}}

These traces prove the snapshot-owner boundary, not a complete CLI, service, or Scheduled Task boot.

Current exact-head tests and checks

On exact head 518a645ae50e0c3a002aa3e75b8facc9b115b3ae:

  • node scripts/run-vitest.mjs src/state/openclaw-state-db-readonly.snapshot-admission.test.ts --maxWorkers=1: 12/12 passed.
  • node scripts/run-vitest.mjs run test/e2e/qa-lab/runtime/native-worker-slot.e2e.test.ts --maxWorkers=1: 1/1 passed after test(e2e): declare worker prompt-context capability #166370; Vitest reported 40.33 s test time and 80.10 s total test duration.
  • node scripts/check-changed.mjs --base upstream/main -- src/state/openclaw-state-db-readonly.ts src/state/openclaw-state-db-readonly.snapshot-admission.test.ts: exit 0. All selected guards passed, including formatting, lint, core and core-test type graphs, SQLite worker ratchet, dead exports, schema guards, and import cycles.

The measured 12-case owner regression cost on the prior patch-identical head remains: 10.50 s command wall time, 7.45 s Vitest duration, and about 0.06 s summed individual test time. The budget and cancellation cases use fake timers, not real five-second sleeps.

Current Status

#166370 was the independently owned two-line E2E fixture repair for the previous checks-node-changed admission failure. It merged as 98567acd6060d21c2199ef9dd8380779a07e1efe; this branch now includes that merge through current main. The exact rebased head passes the formerly blocked native-worker E2E locally without bundling any fixture change into this PR.

Hosted CI for 518a645ae50e0c3a002aa3e75b8facc9b115b3ae is the remaining fresh-head gate. No merge, CI bypass, inherited-green claim, or unrelated repair is requested or performed.

@clawsweeper

clawsweeper Bot commented Oct 6, 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.

@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 9:52 PM ET / October 7, 2026, 01:52 UTC (Revision 10).

ClawSweeper review

What this changes

The PR makes cold shared-state snapshots wait cancellably for up to five seconds during temporary schema ownership and adds focused admission regressions.

Merge readiness

✅ Ready for maintainer review

The patch is useful, narrowly scoped, and supported by real snapshot-boundary proof. Current main still lacks this retry. The overlapping startup PR remains unmerged and preserves different behavior for non-startup callers, so it does not yet establish complete supersession.

Priority: P1
Reviewed head: 518a645ae50e0c3a002aa3e75b8facc9b115b3ae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation and meaningful regressions are supported by real before/after boundary observations.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Windows traces exercise the production schema lease and snapshot reader with a separate holder, showing recovery after release and refusal for cancellation, maintenance, and exhausted contention. GitHub blob identities verify unchanged changed-file bytes at the rebased head. This proves snapshot admission, not full service boot; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Windows traces exercise the production schema lease and snapshot reader with a separate holder, showing recovery after release and refusal for cancellation, maintenance, and exhausted contention. GitHub blob identities verify unchanged changed-file bytes at the rebased head. This proves snapshot admission, not full service boot; no stored-data contract changes require migration proof.
Evidence reviewed 10 items Pinned introduced patch: The introduced delta retries only the existing typed pending-admission error for the selected database, before admission capture and snapshot preparation. Callback execution and retained-read cleanup remain outside the retry loop.
Current main still refuses immediately: Fetched main performs a single fresh ownership check before capturing admission and preparing the snapshot; a pending ownership error is immediately wrapped and rethrown.
Latest release lacks this snapshot retry: The supplied latest-release commit also checks snapshot ownership once and rethrows before preparation. This PR's retry is not established as shipped in v2026.9.8.
Findings None None.
Security None None.

How this fits together

Shared-state snapshots provide consistent private database copies for startup discovery, Doctor, backups, and update preparation. Ownership admission runs before copying data and is checked again before the caller reads it.

flowchart TD
 A[Startup and management reads] --> B[Snapshot admission]
 C[Current database ownership] --> B
 B --> D[Bounded cancellable wait]
 D --> B
 B --> E[Private database snapshot]
 E --> F[Revalidate admission]
 F --> G[Read callback and cleanup]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +24, Tests +89. Total +113 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 4 +24
Tests 1 90 1 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 118 5 +113

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166088
Summary: This PR repairs bounded temporary snapshot contention from the reported startup failure; another open candidate covers longer startup waits.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Use one snapshot admission owner with cancellable waits sized for the caller, including startup contention that lasts longer than five seconds.

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

Yes, source establishes that cold snapshot admission immediately propagates temporary foreign schema ownership on current main. The contributor also supplies real Windows before/after boundary traces; this review did not execute target code.

Is this the best way to solve the issue?

Yes for contention that releases within five seconds: retries stay with the existing owner and preserve refusal and cleanup contracts. The reported nine-second startup race needs the longer startup-specific budget proposed in the related candidate.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Temporary shared-state ownership can abort Gateway startup before its listener opens, disabling channel workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Windows traces exercise the production schema lease and snapshot reader with a separate holder, showing recovery after release and refusal for cancellation, maintenance, and exhausted contention. GitHub blob identities verify unchanged changed-file bytes at the rebased head. This proves snapshot admission, not full service boot; no stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Windows traces exercise the production schema lease and snapshot reader with a separate holder, showing recovery after release and refusal for cancellation, maintenance, and exhausted contention. GitHub blob identities verify unchanged changed-file bytes at the rebased head. This proves snapshot admission, not full service boot; no stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced patch: The introduced delta retries only the existing typed pending-admission error for the selected database, before admission capture and snapshot preparation. Callback execution and retained-read cleanup remain outside the retry loop. (src/state/openclaw-state-db-readonly.ts:125, 518a645ae50e)
  • Current main still refuses immediately: Fetched main performs a single fresh ownership check before capturing admission and preparing the snapshot; a pending ownership error is immediately wrapped and rethrown. (src/state/openclaw-state-db-readonly.ts:119, 19cd32da3326)
  • Latest release lacks this snapshot retry: The supplied latest-release commit also checks snapshot ownership once and rethrows before preparation. This PR's retry is not established as shipped in v2026.9.8. (src/state/openclaw-state-db-readonly.ts:131, fc23bc864e45)
  • Real production-boundary observations: The captured PR body records Windows/Node 26.7.0 execution using a synthetic database, a separate process holding the production schema lease, and the production snapshot reader. Baseline refused; the implementation recovered after release with one callback. Cancellation, genuine maintenance, and exhausted contention produced zero callbacks. These observations cover snapshot admission rather than complete Scheduled Task boot. (d0a218e7d7ec)
  • Prior proof source continuity: GitHub's prior-head production blob is 0272d4ca0e72a63ad9ee4c86f310bd169505a25f, matching the pinned checkout. The test blob likewise matches at 3e0b1a241229c9519cdb75efcd276feac0fdcd8c. This verifies unchanged changed-file bytes without relabeling prior Windows execution as current-head execution. (src/state/openclaw-state-db-readonly.ts, d0a218e7d7ec)
  • Regression value and validation: The added controlled-time cases protect recovery without callback replay, maintenance refusal, database isolation, deadline exhaustion, and cancellation before preparation. The captured body reports 12 passing current-head cases and passing changed-file checks; these are supplemental to the Windows boundary observations. Tests were inspected, not executed during this read-only review. (src/state/openclaw-state-db-readonly.snapshot-admission.test.ts:103, 518a645ae50e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • victor-gurbani: 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-10-06T13:14:18.177Z sha 7dd033f0d4e360cbf2f27aec01e64503320ceace :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T13:47:03.261Z sha 7dd033f0d4e360cbf2f27aec01e64503320ceace :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T13:54:06.786Z sha 7dd033f0d4e360cbf2f27aec01e64503320ceace :: needs changes before merge. :: none
  • reviewed 2026-10-06T14:04:42.505Z sha 7dd033f0d4e360cbf2f27aec01e64503320ceace :: blocked before merge. :: none
  • reviewed 2026-10-06T14:27:45.557Z sha 7dd033f0d4e360cbf2f27aec01e64503320ceace :: blocked before merge. :: none
  • reviewed 2026-10-07T00:07:25.928Z sha d0a218e7d7ec42349aa4e96ff06d7dd5608c791a :: needs changes before merge. :: none
  • reviewed 2026-10-07T00:26:01.562Z sha d0a218e7d7ec42349aa4e96ff06d7dd5608c791a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T01:09:48.449Z sha d0a218e7d7ec42349aa4e96ff06d7dd5608c791a :: needs maintainer review before merge. :: none

@ericcaiwx-star
ericcaiwx-star marked this pull request as ready for review October 6, 2026 13:06
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. and removed P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR's Evidence section for the remaining CI-provenance next step on unchanged head 7dd033f0d4e360cbf2f27aec01e64503320ceace.

The completed main UI job at immutable 8787ee08687efccb868e8273218942d1b597fb32 independently fails the same five chat-mobile-bubble-margin cases at the same assertion locations as this PR's failed UI job. The failing file, margin fixtures, activity component, mock harness, suite helper, and UI config are unchanged from the PR's tested main parent. Both actual job links and the complete three-red-entry attribution are in the body; this is not a green replay or a claim that the entire main trees are identical.

The PR changes only snapshot admission and its owner tests, not that mocked browser flow. The required CI gate remains red. The native inherited-failure landing exception remains a maintainer-owned disposition; no merge or bypass was performed. Please re-evaluate the contributor-side provenance against the updated evidence.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

The latest exact-head ClawSweeper review accepts the inherited UI-failure provenance and reports no patch or proof findings. The matching completed main job and all three red-check explanations are now in the PR's Evidence section; the required CI gate is still red.

Could a maintainer resolve the review's explicit owner decision: use the repository's native inherited-failure landing workflow for this reviewed snapshot repair, or wait for the main UI repair? The native workflow must independently verify landing authority, exact-head CI evidence, security, and review gates. I have not merged, bypassed checks, rerun CI for green, or bundled an unrelated UI fix.

@ericcaiwx-star
ericcaiwx-star force-pushed the codex/fix-166088-state-read-admission branch from 7dd033f to d0a218e Compare October 6, 2026 23:55
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 6, 2026
steipete added a commit to NianJiuZst/openclaw that referenced this pull request Oct 7, 2026
…atch

Keep startup's five-minute schema admission budget and preserve immediate
refusal for other snapshot callers. Check caller cancellation after awaited
admission, before preparing snapshot bytes. Preserve recovery, refusal,
exhaustion, and cancellation coverage, including the startup entry point.

Adapt the controlled-time admission regressions from Eric Cai's openclaw#166108.
Remove a single-use read forwarding layer without changing retained work
settlement, error mapping, or current/live read scopes. Await worker-backed
database closure before existing raw SQLite fixture access.

Fixes openclaw#166088

Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: Eric Cai <[email protected]>
@ericcaiwx-star
ericcaiwx-star force-pushed the codex/fix-166088-state-read-admission branch from d0a218e to 518a645 Compare October 7, 2026 01:45
@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Rebased cleanly onto current main after #166370 merged. Exact head 518a645ae50e0c3a002aa3e75b8facc9b115b3ae passes the 12-case state-owner regression, the formerly blocked native-worker E2E 1/1, and the full changed-file gate. The PR body now distinguishes prior-head Windows production-boundary proof from new exact-head macOS verification; no old proof was relabeled. Hosted CI is running on the new head.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

steipete added a commit that referenced this pull request Oct 7, 2026
…ion (#166111)

* fix(gateway): retry temporary startup state contention

* fix(state): retain startup contention coverage and simplify read dispatch

Keep startup's five-minute schema admission budget and preserve immediate
refusal for other snapshot callers. Check caller cancellation after awaited
admission, before preparing snapshot bytes. Preserve recovery, refusal,
exhaustion, and cancellation coverage, including the startup entry point.

Adapt the controlled-time admission regressions from Eric Cai's #166108.
Remove a single-use read forwarding layer without changing retained work
settlement, error mapping, or current/live read scopes. Await worker-backed
database closure before existing raw SQLite fixture access.

Fixes #166088

Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: Eric Cai <[email protected]>

---------

Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Eric Cai <[email protected]>
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thank you @ericcaiwx-star. Your fix and regression coverage were folded into #166111, merged as af716af with you credited as co-author. That version waits up to the existing five-minute startup migration budget (the reported contention lasted about nine seconds, longer than the five-second window here) and keeps explicit offline maintenance blocking. Closing this one as superseded by #166111.

@steipete steipete closed this Oct 7, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…ion (openclaw#166111)

* fix(gateway): retry temporary startup state contention

* fix(state): retain startup contention coverage and simplify read dispatch

Keep startup's five-minute schema admission budget and preserve immediate
refusal for other snapshot callers. Check caller cancellation after awaited
admission, before preparing snapshot bytes. Preserve recovery, refusal,
exhaustion, and cancellation coverage, including the startup entry point.

Adapt the controlled-time admission regressions from Eric Cai's openclaw#166108.
Remove a single-use read forwarding layer without changing retained work
settlement, error mapping, or current/live read scopes. Await worker-backed
database closure before existing raw SQLite fixture access.

Fixes openclaw#166088

Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: Eric Cai <[email protected]>

---------

Co-authored-by: NianJiuZst <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Eric Cai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants