Skip to content

fix(infra): name the lock path in gateway lock errors (companion to #159614) - #190282

Merged
obviyus merged 5 commits into
openclaw:mainfrom
jerome-queck:fix/gateway-lock-path-companion
Nov 8, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
jerome-queck:fix/gateway-lock-path-companion

Conversation

@jerome-queck

@jerome-queck jerome-queck commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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 ownership without 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 to openclaw 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 on main.

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 current main's acquire loop were resolved by keeping main's structure and adding only his tracking.
  • df683a6 (follow-up): on current main, 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 in GatewayLockNamespaceError when it is known, and skips the lock suffix for database failures (which backup-sqlite.test.ts covers). It adds a regression test for the foreign-PID-namespace state lock. gateway-lock.ts stays under the 700 code-line limit.

Evidence

Real Gateway startup on Linux from the source CLI (node --import ./scripts/tsx.mjs src/entry.ts), isolated HOME, port 19462. A gateway.state.lock is left by a Gateway in another PID namespace (live PID, foreign processNamespace), then a second Gateway starts on the same state dir.

Before (origin/main 2c0ab86):

# source tree 2c0ab86fa41 (origin/main); isolated HOME=/tmp/h159614.8Shj
$ cat /tmp/h159614.8Shj/.openclaw/tmp/openclaw-1000/gateway.state.lock
{"pid":3662774,"createdAt":"2026-11-01T11:11:58.000Z","configPath":"/tmp/h159614.8Shj/.openclaw/openclaw.json","stateDir":"/tmp/h159614.8Shj/.openclaw","role":"gateway","processNamespace":{"platform":"linux","host":"gateway-container","pidNsInode":"4026532999"}}
$ openclaw gateway run --allow-unconfigured --port 19462
Run "openclaw doctor --fix" against the same state/config, then restart the gateway.
2026-11-01T19:12:18.525+08:00 [gateway] loading configuration…
2026-11-01T19:12:18.534+08:00 [gateway] resolving authentication…
2026-11-01T19:12:18.536+08:00 [gateway] starting...
2026-11-01T19:12:19.256+08:00 Gateway failed to start: failed to acquire gateway state ownership | Gateway lock inspection is unavailable | Gateway lock payload could not be verified
If the gateway is supervised, stop it with: openclaw gateway stop
# exit=1

After (this branch, df683a6):

# source tree df683a6449e (branch); isolated HOME=/tmp/h159614.fFAO
$ cat /tmp/h159614.fFAO/.openclaw/tmp/openclaw-1000/gateway.state.lock
{"pid":3688236,"createdAt":"2026-11-01T11:27:22.000Z","configPath":"/tmp/h159614.fFAO/.openclaw/openclaw.json","stateDir":"/tmp/h159614.fFAO/.openclaw","role":"gateway","processNamespace":{"platform":"linux","host":"gateway-container","pidNsInode":"4026532999"}}
$ openclaw gateway run --allow-unconfigured --port 19462
Run "openclaw doctor --fix" against the same state/config, then restart the gateway.
2026-11-01T19:27:41.965+08:00 [gateway] loading configuration…
2026-11-01T19:27:41.975+08:00 [gateway] resolving authentication…
2026-11-01T19:27:41.977+08:00 [gateway] starting...
2026-11-01T19:27:42.700+08:00 Gateway failed to start: failed to acquire gateway state ownership at /tmp/h159614.fFAO/.openclaw/tmp/openclaw-1000/gateway.state.lock | Gateway lock inspection is unavailable | Gateway lock payload could not be verified
If the gateway is supervised, stop it with: openclaw gateway stop
# exit=1

Tests (Linux, vitest infra config, --maxWorkers=1):

  • src/infra/gateway-lock*.test.ts: 7 files passed, 1 skipped (Windows-only), 102 tests passed.
  • Red/green for src/infra/gateway-lock.unactionable-timeout.test.ts: against main's gateway-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 current main, 3/5 fail (the unverifiable-owner and foreign-namespace cases). On this branch, 5/5 pass.
  • Callers that assert on these messages: backup-sqlite, doctor-sqlite-maintenance-lock, run.supervised-lock, daemon/diagnostics, update-database-restore, sqlite-readonly-location, startup-plugin-source-captures, update-command-invalid-config all pass. run-loop.test.ts has timeouts locally that reproduce identically on main, so they are unrelated.
  • checks-node-changed-compact-large-36 on fix(infra): name the lock path in gateway lock timeout errors #159614 failed in src/agents/sandbox/sdk-state-owner.process.test.ts (filesystem snapshot .bun entry count 1645 vs 1639), which does not touch the lock code. Locally that test passes on both main and this branch (1/1 each), so it looks like a runner-environment snapshot flake, not this patch.

If @carlosjarenom prefers to fold df683a6 into #159614, I'll close this one.

CI attribution: check-lint-core-5 (and the ci-gate that follows it) fails on src/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.

carlosjarenom and others added 2 commits November 1, 2026 19:01
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.
@clawsweeper

clawsweeper Bot commented Nov 1, 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 gateway Gateway runtime size: M labels Nov 1, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 1, 2026
@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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The startup failure reports failed to acquire gateway state ownership without identifying that file.
  • After: The startup failure includes at /tmp/h159614.fFAO/.openclaw/tmp/openclaw-1000/gateway.state.lock.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused diagnostic repair with supplied startup proof, distinct filesystem regression cases, successful exact-head gates, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied Linux source-CLI Gateway run uses isolated state and a foreign-namespace historical lock, showing the startup refusal gain the exact blocking path; the relevant production code remains unchanged through the reviewed head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An operator cannot identify which ownership lock refused Gateway startup from the failure message.
Reason: Exact file attribution improves an existing recovery workflow without changing locking policy, configuration, or persisted state.

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
Reviewed head: 595a4487d11bf5b17f7b48bb1e8e80fa0834b6ec

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Shared ownership acquisition and historical compatibility checks keeps the original intent (8b16e53: Consolidate ownership while preserving exclusion with supported historical lock readers.)
  • Unverifiable-owner refusal keeps the original intent (edea119: Missing process observations and heartbeat age cannot prove an owner stopped.)
  • Database failure attribution keeps the original intent (2a8b77f: Permit read-only owned state and distinguish unwritable database storage from lock contention.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction adds per-attempt attribution, catches historical inspection refusals at their file boundary, and preserves the database-failure exception. (src/infra/gateway-lock.ts:388, 595a4487d11b)
  • Current main still needs the diagnostic: Current main retains the acquisition message without a blocking-path suffix and historical inspection errors without file attribution. (src/infra/gateway-lock.ts:558, 5e6d9a2781d6)
  • Supplied startup proof: The PR body supplies Linux source-CLI Gateway startup output before and after the fix using isolated state and a foreign-namespace historical lock; the corrected output names that file. The changed production files are unchanged since the earlier reviewed head. (src/infra/gateway-lock.ts:584, 595a4487d11b)
  • Exact-head checks: All paginated check runs have successful, skipped, or neutral conclusions; dependency review, security-sensitive review, and openclaw/ci-gate statuses are successful. The previously reported check-lint-core-5 now succeeds. (595a4487d11b)
  • Companion contribution and remaining overlap: fix(infra): name the lock path in gateway lock timeout errors #159614 remains open and explicitly lacks shipped-entry-point proof. This PR credits and preserves Carlos Jareño's contribution, adds historical-refusal handling, and supplies startup evidence; the earlier PR is not a proven replacement.
  • Ownership history and original intent: Feature history traces singleton enforcement through shared-state ownership and namespace-safe refusal. The shared-owner refactor introduced the generic diagnostic; subsequent namespace and read-only-storage fixes explain the refusal and database-attribution contracts this PR preserves. (src/infra/gateway-lock.ts:393, 8b16e5328ecd)

PR surface

Source +29, Tests +216, Docs +2. Total +247 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 51 22 +29
Tests 1 216 0 +216
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 270 23 +247

Root-cause cluster

Relationship: canonical
Canonical: #190282
Summary: This PR carries the earlier diagnostic contribution forward with additional refusal coverage and startup proof.

Members:

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Missing lock-file attribution hinders operator diagnosis and recovery, with a limited diagnostic scope.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-01T11:57:43.797Z sha 2b936e5 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-01T12:24:19.792Z sha a0669ec :: needs maintainer review before merge. :: none

Reviewed November 2, 2026, 11:41 PM ET / November 3, 2026, 04:41 UTC (Revision 3).

@jerome-queck

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Merged current main (a0669ec). The remaining red check, check-lint-core-5, is in src/skills/workshop/experience-review.test.ts, which this PR does not touch. The attribution is in the Evidence section.

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 1, 2026
@jerome-queck

Copy link
Copy Markdown
Contributor Author

@obviyus when you have a moment, this is ClawSweeper 5/5/5 and ready for maintainer look; happy to adjust anything.

@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 3, 2026
@jerome-queck

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 3, 2026
@obviyus
obviyus merged commit e097b68 into openclaw:main Nov 8, 2026
153 checks passed
@obviyus

obviyus commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 9, 2026
…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]>
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

3 participants