Repository navigation
fix(gateway): prevent startup failures during temporary state contention - #166111
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 9:39 PM ET / October 7, 2026, 01:39 UTC (Revision 6). ClawSweeper reviewWhat this changesGateway startup gains bounded waiting for temporary shared-state contention, with cancellation and refusal regressions and documented startup behavior. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main and the latest release. Recorded production-boundary proof remains applicable, prior follow-up is resolved, and no blocking introduced defect was found. Priority: P1 Review scores
Verification
How this fits togetherGateway startup validates configuration using a private snapshot of shared SQLite state. Database ownership admission controls when that snapshot can be prepared and consumed by startup validation. flowchart TD
A[Gateway startup] --> B[Configuration preflight]
B --> C[Database ownership admission]
C --> D{Admission outcome}
D -->|Temporary contention within budget| C
D -->|Allowed| E[Private SQLite snapshot]
E --> F[Startup validation]
D -->|Maintenance or deadline| G[Reported startup failure]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -7, Tests +165, Docs +1. Total +159 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep bounded startup waiting in the existing snapshot admission owner, preserving immediate refusal elsewhere and single execution of prepared work. Do we have a high-confidence way to reproduce the issue? Yes: a foreign schema lease makes current main's cold startup snapshot admission throw before preparation. Source inspection and recorded two-process before/after proof establish the trigger; this read-only review executed no target code. Is this the best way to solve the issue? Yes: retrying typed temporary contention before snapshot preparation repairs the existing owner without replaying callbacks or relaxing maintenance admission. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f0c9bcfbe30f. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
…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]>
|
Merged via squash.
|
…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]>
What Problem This Solves
Gateway startup can exit before opening its listener when another OpenClaw process temporarily owns the shared-state schema. The reported lock lasted about nine seconds; a five-second SQLite busy budget is too short for that startup race.
User Impact
Startup waits up to five minutes for temporary schema custody, matching the existing startup migration lease budget and accommodating slow cold starts. Explicit offline maintenance still refuses access immediately. Exhausted contention retains the operational read-failure path (exit
1); configuration errors and required offline migrations retain their existing classification. No configuration, schema, stored-data, permission, or update-migration contract changes.Why This Change Was Made
The existing snapshot owner retries only
StateDatabaseAdmissionPendingErrorfor its selected database. Startup supplies the wait budget; other snapshot callers still default to immediate refusal. Every attempt checks cancellation and fresh ownership. Snapshot preparation, callbacks, and cleanup remain outside the retry loop, and admission is revalidated before the callback.Maintainer cleanup preserves synchronous error mapping and retained read settlement while removing a single-use forwarding function and duplicate positional arguments. It also simplifies error construction and empty registry diagnostics. The existing raw-SQLite test fixtures now await worker-backed database closure before opening a connection.
Permanent controlled-time tests cover recovery after nine simulated seconds, default immediate refusal, genuine maintenance, another database, the five-minute deadline, caller cancellation, and shutdown. A startup-entry regression exercises
readAdmittedConfigSnapshotwith a synthetic foreign schema-owner record and verifies one config callback and unchanged source bytes. No real retry sleeps were added.Evidence
Main refresh: merged current main into
3c983c19e6c03aa60e84dc4a811f14d49cfb7e50because CI run 37555942032 tested a stale merge ref predating shared paired-worker fixture fix98567acd6060; all five PR files are byte-identical tof02c10837760ee328c55bb7f70c0833cfe835b68, so the recorded review and isolated proof are reused without a new lease.Proven implementation head:
f02c10837760ee328c55bb7f70c0833cfe835b68. The defect was still present on fetched mainf97c85590ad9a68e36c231117aecc6c424fce6de; history inspection confirmed that cold snapshot admission still checked ownership once and rethrew before snapshot preparation.oxfmt --check,node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.jsonon the four changed TypeScript files, andgit diff --check.scoped-clean, no actionable P0–P2 findings. The committed tree matches the reviewed tree.cbx_f83db7d0f253(stopped; verifiedreleasedincrabbox list --provider aws), Node 24.21.0, pinned pnpm 12.5.1. Trusted-main bootstrap verified the full SHA and IMDS no-role boundary; no hydration or Tailscale was used. No contributor code executed on the maintainer host.Passing command:
Core typecheck passed in 15.23 s. All 48 tests across four files passed in 78.48 s command wall time, including worker preparation and both test projects.
On the same lease and unchanged Git HEAD, only the two production files were restored to merge-base
83908d3f49ee8a8049eb90a0fe649824994e79ff:The owner regression failed as expected in 27.72 s. The wrapper stopped after the failed unit shard, so the startup regression was then exercised separately, with the same production-only revert:
That control failed as expected in 30.52 s, through
readAdmittedConfigSnapshot. Sanitized excerpts:Test cost: separate exact-head
pnpm test <file> --maxWorkers=1measurements were 29.00 s wall / 0.149 test seconds / 14 passing cases for snapshot admission, and 54.47 s wall / 36.476 test seconds / 19 passing cases for config preflight. Admission wall time includes 21.085 s of compiled-worker preparation. The existing startup integration suite exceeds 30 s because it exercises real configuration parsing, isolated SQLite snapshot/worker lifecycles, source-byte preservation, and operational-versus-terminal failure classification. The added startup case protects the caller's budget selection and production ownership classification, which the cheaper mocked admission suite cannot prove. Retry budgets use controlled time, with no real retry sleeps. File-specific CI seconds are unavailable: exact-head CI run 37554683431 was skipped; this is not a claim of green CI.LOC against
origin/main...HEAD: production +47/−54 (net −7); tests +169/−4 (net +165); docs +1/−0. Exact numstat:ClawSweeper's outstanding P2 request to retain recovery, default-refusal, deadline, and cancellation coverage is addressed in the existing admission suite. No review finding was rejected. This phase stops after branch repair, proof, and this body update; no merge or sibling closure was performed.
This proof covers startup snapshot admission and retained-read lifecycle behavior. It does not establish a complete Windows Scheduled Task or Gateway + Node Host boot. The broader launcher status and service-supervision symptoms are outside this change.
Credit
Original fix by @NianJiuZst; maintainer cleanup and permanent regression coverage build on that startup-specific implementation. Controlled-time admission regressions adapted from @ericcaiwx-star's #166108, with both contributors credited in the maintainer commit. The startup-only five-minute budget is why this PR was selected as the base. The other PR remains open for coordinator disposition after landing.
Fixes #166088
Co-authored-by: Eric Cai [email protected]