Repository navigation
fix(infra): name the lock path in gateway lock errors (companion to #159614) - #190282
Conversation
A Gateway startup that cannot take state ownership failed with "failed to acquire gateway state ownership" and nothing for the operator to go and look at, even though one lock file was always responsible. Name it. acquireGatewayStateOwner() locks the process owner sidecar (state.<hash>.lock), so an unattributed or non-contention failure names that primary file rather than the gateway.state.lock projection, which is written lazily and may never exist. The historical lock scan still names the file it discovered, which is the more specific answer. Rebuilt onto current upstream/main: the lock-path module extraction this change previously carried is gone — upstream keeps resolveGatewayLockPaths in gateway-lock.ts — and upstream removed gateway-lock.roles.test.ts, so the sidecar-naming case now lives in gateway-lock.unactionable-timeout.test.ts. Co-authored-by: Copilot App <[email protected]>
… live contention Unverifiable (foreign PID namespace) and unreadable state/config lock payloads now report the lock file they refused, and a database failure keeps pointing at the database instead of the owner sidecar. Builds on openclaw#159614 by @carlosjarenom.
|
🦞👀 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. What this changesThis PR adds the blocking lock file path to Gateway ownership errors while preserving database-error attribution. Example: Gateway startup encounters an unverifiable historical lock at /tmp/h159614.fFAO/.openclaw/tmp/openclaw-1000/gateway.state.lock.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a useful, focused diagnostic fix that current main still lacks; no introduced correctness or security defect was found, and the exact-head CI gate passes. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway startup and maintenance enter the shared ownership coordinator, which checks the process-owner sidecar, historical locks, and database ownership before returning custody or an actionable error. flowchart TD
A[Gateway startup or maintenance] --> B[Ownership coordinator]
B --> C[Process owner sidecar]
C --> D[Historical lock inspection]
D --> E[Database ownership check]
E --> F[Ownership handle]
B --> G[Error with blocking path]
Technical reviewBest possible solution: Retain this focused change in the existing ownership coordinator, including historical inspection attribution and the database-error exception. Do we have a high-confidence way to reproduce the issue? Current-main source shows historical inspection failures reaching an unattributed startup error, and the contributor supplies matching before/after Gateway startup output; no target code was executed during this review. Is this the best way to solve the issue? The patch uses the existing coordinator, preserves refusal and retry semantics, and attributes errors where the blocking historical file is known. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5e6d9a2781d6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +29, Tests +216, Docs +2. Total +247 across 4 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 2, 2026, 11:41 PM ET / November 3, 2026, 04:41 UTC (Revision 3). |
|
@clawsweeper re-review Merged current main (a0669ec). The remaining red check, |
|
🦞👀 Re-review progress:
|
|
@obviyus when you have a moment, this is ClawSweeper 5/5/5 and ready for maintainer look; happy to adjust anything. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…penclaw#159614) (openclaw#190282) * fix(infra): name the lock file that blocked gateway state ownership A Gateway startup that cannot take state ownership failed with "failed to acquire gateway state ownership" and nothing for the operator to go and look at, even though one lock file was always responsible. Name it. acquireGatewayStateOwner() locks the process owner sidecar (state.<hash>.lock), so an unattributed or non-contention failure names that primary file rather than the gateway.state.lock projection, which is written lazily and may never exist. The historical lock scan still names the file it discovered, which is the more specific answer. Rebuilt onto current upstream/main: the lock-path module extraction this change previously carried is gone — upstream keeps resolveGatewayLockPaths in gateway-lock.ts — and upstream removed gateway-lock.roles.test.ts, so the sidecar-naming case now lives in gateway-lock.unactionable-timeout.test.ts. * fix(infra): name the historical lock file for every refusal, not only live contention Unverifiable (foreign PID namespace) and unreadable state/config lock payloads now report the lock file they refused, and a database failure keeps pointing at the database instead of the owner sidecar. Builds on openclaw#159614 by @carlosjarenom. * test(infra): drop removed staleMs option and merge gateway-lock imports --------- Co-authored-by: Carlos <[email protected]> Co-authored-by: jerome-queck <[email protected]>
Companion to #159614 by @carlosjarenom, which went stale waiting on proof. This branch keeps his commit (authorship intact), applies it to current
main, adds one follow-up commit, and supplies the missing real-run evidence. Related issue: #135133.What Problem This Solves
When Gateway startup cannot acquire state ownership, the error says
failed to acquire gateway state ownershipwithout naming the lock file that blocked it. The operator has to guess between the process owner sidecar (state.<hash>.lock), the historical state lock (gateway.state.lock) and the config lock (gateway.<hash>.lock). This is worst when the holder sits in another PID namespace, e.g. a containerized Gateway sharing~/.openclaw, because nothing on the host can verify or reclaim it.User Impact
The startup error now ends with
at <lock path>, naming the exact file that refused ownership, so the operator knows what to inspect (or hand toopenclaw gateway recover-lock). There is no behavior change to locking, reclaiming or timeouts; only the error text changes. When the failure is a database error rather than a lock, the message keeps pointing at the database, as onmain.Why
4418884(@carlosjarenom, from fix(infra): name the lock path in gateway lock timeout errors #159614): tracks the lock file that blocked each poll attempt, resets it every attempt so a stale path is never reported, and falls back to the owner sidecar. Conflicts with currentmain's acquire loop were resolved by keepingmain's structure and adding only his tracking.df683a6(follow-up): on currentmain, an unverifiable or unreadable historical lock payload throws before live contention, so his hook never fired for those cases (his own "recorded owner cannot be verified" tests failed after rebasing). The follow-up attributes any refusal from a historical lock check to that file, includes the lock path inGatewayLockNamespaceErrorwhen it is known, and skips the lock suffix for database failures (whichbackup-sqlite.test.tscovers). It adds a regression test for the foreign-PID-namespace state lock.gateway-lock.tsstays under the 700 code-line limit.Evidence
Real Gateway startup on Linux from the source CLI (
node --import ./scripts/tsx.mjs src/entry.ts), isolatedHOME, port 19462. Agateway.state.lockis left by a Gateway in another PID namespace (live PID, foreignprocessNamespace), then a second Gateway starts on the same state dir.Before (
origin/main2c0ab86):After (this branch, df683a6):
Tests (Linux, vitest infra config,
--maxWorkers=1):src/infra/gateway-lock*.test.ts: 7 files passed, 1 skipped (Windows-only), 102 tests passed.src/infra/gateway-lock.unactionable-timeout.test.ts: againstmain'sgateway-lock.ts/gateway-lock-payload.ts, 5/5 fail. Against fix(infra): name the lock path in gateway lock timeout errors #159614's commit alone on currentmain, 3/5 fail (the unverifiable-owner and foreign-namespace cases). On this branch, 5/5 pass.backup-sqlite,doctor-sqlite-maintenance-lock,run.supervised-lock,daemon/diagnostics,update-database-restore,sqlite-readonly-location,startup-plugin-source-captures,update-command-invalid-configall pass.run-loop.test.tshas timeouts locally that reproduce identically onmain, so they are unrelated.checks-node-changed-compact-large-36on fix(infra): name the lock path in gateway lock timeout errors #159614 failed insrc/agents/sandbox/sdk-state-owner.process.test.ts(filesystem snapshot.bunentry count 1645 vs 1639), which does not touch the lock code. Locally that test passes on bothmainand this branch (1/1 each), so it looks like a runner-environment snapshot flake, not this patch.If @carlosjarenom prefers to fold
df683a6into #159614, I'll close this one.CI attribution:
check-lint-core-5(and theci-gatethat follows it) fails onsrc/skills/workshop/experience-review.test.ts:167-168(typescript(no-unnecessary-type-arguments)). This PR does not touch that file; the same failure shows on other open PRs against current main (for example #190299). Head a0669ec merges current main; all checks for the files this PR changes pass.