Skip to content

fix(gateway): recover-lock can clear the Linux legacy config lock that blocks Doctor maintenance - #201893

Closed
sukhdeepjohar wants to merge 1 commit into
openclaw:mainfrom
sukhdeepjohar:fix-doctor-legacy-lock-recovery
Closed

sukhdeepjohar wants to merge 1 commit into
openclaw:mainfrom
sukhdeepjohar:fix-doctor-legacy-lock-recovery

Conversation

@sukhdeepjohar

@sukhdeepjohar sukhdeepjohar commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Related: #201472

Linux companion to #201912. #201912 lets macOS (like Windows since #182031) admit a stopped namespace-less legacy owner by itself and keeps Linux refusing on purpose, because a Gateway in another PID namespace can share the lock directory; its refusal on Linux tells the operator to remove the system-temp file by hand, because recover-lock does not inspect it. This PR makes recover-lock inspect that file on Linux, so the documented explicit recovery covers it. Rebased onto #201912 and narrowed to Linux; macOS and Windows behavior is #201912's and unchanged here.

This fixes the recovery route on a build that contains it. The issue's other ask, a route for an install already rolled back to 2026.11.4 (whose CLI has no recover-lock), stays open under the same issue for the maintainers.

What Problem This Solves

Fixes: on Linux, openclaw doctor --fix (and so every update, which runs Doctor) refuses maintenance when an older Gateway left a per-config lock file in a separate system temporary directory ($TMPDIR/openclaw-<uid>/gateway.<hash>.lock) with no process namespace, even though its process exited long ago; and openclaw gateway recover-lock, the documented way to clear a lock whose owner cannot be verified, never inspected that directory, so it reported "No Gateway lock or owner lease is present." Since #201912 the refusal for that file says to remove it by hand after checking the process has stopped on the host and in every container sharing the directory.

Scope: this fixes recovery wherever the fixed recover-lock command is available. An install already rolled back to 2026.11.4 has no recover-lock command, so how such an install obtains the fixed command (for example the updater running recovery from the candidate) remains unresolved and is left to the maintainers under #201472. When the service's temporary directory sits inside the state directory, the historical lock path is the same as the state-local config lock that recover-lock already inspects, and #201912's refusal already names recover-lock there; this change does nothing for that layout.

User Impact

User impact: on Linux, an operator blocked by "Legacy Gateway lock ... still has a live or unverified owner" can run openclaw gateway recover-lock (as the Gateway service account, with the same TMPDIR), see that record listed, and clear it with the printed --confirm <fingerprint> command; Doctor and the update then complete. For that file, the Doctor refusal now names that command before #201912's manual delete, which stays as the fallback when recover-lock skips the file or is not installed; the instruction to check the host and every container sharing the directory first applies to both. Nothing is reclaimed automatically: a record without a namespace is still "unverified", and the confirmation is the operator's statement that its process has stopped. A verified live holder is still refused.

If the file cannot be inspected safely (not owned by the operator, writable by others, under a parent directory another user could replace, not a regular single-link file, or larger than 16 KiB), recover-lock names the file and the reason instead of reporting an empty inspection, a confirmation that had to skip it says so, and a confirmation with nothing eligible says that nothing was recovered.

macOS and Windows are unchanged: they admit a stopped namespace-less record once its heartbeat is older than 90 seconds (#182031, #201912), so recover-lock does not inspect a separate system-temp copy there and #201912's Doctor message stays as it is. Other platforms (FreeBSD and the like) are also left out; the inspection runs only on Linux.

Why This Change Was Made

Doctor's maintenance admission checks the historical per-config lock under the system temporary directory, but lock recovery only observed the three state-local lock paths. Inspection now also observes that file on Linux, deduplicated when it is the same file as the state-local config lock; confirmation takes it first, so a failure to take custody of it leaves the state-local records untouched; and the Linux Doctor refusal for that file names the recovery command, as it already does for the state-local file. The ownership policy from #178076 is unchanged.

Because the file lives in a shared directory and confirmation deletes it, the checks are sized against what a wrong deletion could reach: the file and its directory must be owned by the current user and writable by nobody else (so the bytes shown are the operator's own record); the configured path's own components are checked first, and a symbolic link in it that another user controls is refused (it could redirect the lookup to a directory that passes every later check); the path is then resolved to its canonical form and every parent must be owned by the current user or root, and a parent writable by others must carry the sticky bit (otherwise another local user could rename a parent and redirect the confirmed path between inspection and confirmation); a symbolic link or directory that another account substitutes in the configured path is owned by that account, and the checks run again at confirmation, so it fails the owner test or the parent walk; that account cannot create components owned by the current user or root; the file is opened without following symlinks and without blocking (a FIFO cannot hang the command), must be a regular single-link file, and is read only up to the existing 16 KiB sidecar bound. Confirmation then re-verifies identity (device, inode, timestamps, size) and bytes before removal, as for the other lock files. POSIX ACL entries are not inspected; this is a known limit.

Evidence

Full-product check through the shipped CLI (openclaw.mjs of a built tree, Linux container, root): the reporter's lock record (no processNamespace, exited PID, mtime 30 Sep 2026) at /tmp/openclaw-0/gateway.<hash>.lock, then doctor --fix --non-interactive, gateway recover-lock, --json, --confirm, Doctor again.

Full-product repro on main

main d9e2d8a89dd (includes #201912), 19 Nov 2026 (the next main, d5f3e4d7b75, changes no file this PR touches):

== 1 doctor --fix --non-interactive (with the legacy lock)
doctor rc=1
  Doctor could not enter maintenance. Legacy Gateway lock /tmp/openclaw-0/gateway.3518e90d.lock still has a live or unverified owner (PID 28). If that process has stopped on this host and in every container sharing this directory, remove that file as the Gateway service account. Stop the Gateway service and other OpenClaw processes using this state, then run openclaw doctor --fix from an independent shell.
== 2 gateway recover-lock (inspect)
recover-lock rc=0
  No Gateway lock or owner lease is present.
== 3 gateway recover-lock --json
  { "present": false, "holders": [], ... }
== 4 skipped: inspection listed no record to confirm
RESULT lock_after_recovery=present
== 5 doctor --fix --non-interactive again
doctor rc=1

Live run with this PR

Same container recipe, same record, the patched build of this head on that main:

== 1 doctor --fix --non-interactive (with the legacy lock)
doctor rc=1
  Doctor could not enter maintenance. Legacy Gateway lock /tmp/openclaw-0/gateway.3518e90d.lock still has a live or unverified owner (PID 28). If that process has stopped on this host and in every container sharing this directory, run `openclaw gateway recover-lock` as the Gateway service account with the same TMPDIR to inspect and explicitly recover it, or remove that file as the Gateway service account. Stop the Gateway service and other OpenClaw processes using this state, then run openclaw doctor --fix from an independent shell.
== 2 gateway recover-lock (inspect)
recover-lock rc=0
  /tmp/openclaw-0/gateway.3518e90d.lock: holder 28 at unknown host, last renewed 4327232 s ago. Stop the holder before retrying; if it has already stopped, run `openclaw gateway recover-lock` to inspect and explicitly recover the unchanged owner.
  Stop the recorded holder through its service manager or container first. If you have confirmed it stopped, recover exactly these unchanged records with:
  openclaw gateway recover-lock --confirm <fingerprint>
== 3 gateway recover-lock --json
  { "present": true, "holders": ["/tmp/openclaw-0/gateway.3518e90d.lock: holder 28 ..."], ... }
RESULT recover_lists_legacy=yes
== 4 gateway recover-lock --confirm <fingerprint>
rc=0
  Gateway lock recovery completed. Start the Gateway again.
RESULT lock_after_recovery=removed
== 5 doctor --fix --non-interactive again
doctor rc=0

Doctor still refuses before recovery (the owner stays unverifiable); the difference is that recovery now reaches the file and Doctor passes once it is gone.

Focused tests (src/infra/gateway-lock-legacy.test.ts, src/infra/gateway-lock-recovery.test.ts): the new cases fail on unpatched main (the "red" lane copies them there) and pass with the change under the node runtime. The direct consumers of the two changed modules (gateway-lock-recovery.postgres.test.ts, doctor-health.legacy-update.test.ts, doctor-maintenance.interruption.process.test.ts, update-command-service-drain.test.ts) pass. Typecheck, lint and format run through CI's own check:changed on the bench.

Upgrade run from a real 2026.11.4 install (Linux container, user node)

npm i -g [email protected], state initialized by openclaw doctor --fix --non-interactive, a config marker set (gateway.port 18799), then the lock record above planted at /tmp/openclaw-1000/gateway.5b681173.lock (exited PID 273). The 2026.11.4 Doctor admits it (control). The candidate is this branch packed with scripts/package-openclaw-for-docker.mjs.

Phase A, the real updater with the lock present (openclaw update --yes --tag <candidate.tgz>): the candidate's Doctor refuses with the new message and the update rolls back to 2026.11.4, as on 2026.11.5 today; the install is back on 2026.11.4 and the config marker is intact. This is the unresolved part: a rolled-back install cannot run recovery by itself.

✗ openclaw doctor (2.6s)
  Failing check doctor (doctor-failed): Doctor could not enter maintenance. Legacy Gateway lock [redacted-path]
  ... Legacy Gateway lock /tmp/openclaw-1000/gateway.5b681173.lock still has a live or unverified owner (PID 273). If that process has stopped on this host and in every container sharing this directory, run `openclaw gateway recover-lock` as the Gateway service account ... or remove that file as the Gateway service account.
⚠️ OpenClaw update failed: doctor-failed.
RESULT A version_after=OpenClaw 2026.11.4 (d843d6a) lock_present=yes
marker gateway.port = 18799

Phase B, the manual route (installing the candidate by hand, not through the updater): npm i -g <candidate.tgz>, then Doctor refuses with the hint, recover-lock lists the record and prints the confirm command, the confirm removes the file, Doctor exits 0, and the config marker and state database are intact.

installed: OpenClaw 2026.11.5 (ead12fa)
doctor (lock present) rc=1
recover-lock: /tmp/openclaw-1000/gateway.5b681173.lock: holder 273 at unknown host, last renewed 4329492 s ago. ...
  openclaw gateway recover-lock --confirm <fingerprint>
confirm rc=0  Gateway lock recovery completed. Start the Gateway again.
RESULT B lock_after=removed
RESULT B doctor_after rc=0
marker gateway.port = 18799

Phase C, the real updater from the untouched 2026.11.4 state (restored from a copy taken before the lock was planted) once the file is gone: the update completes and the config marker is intact.

installed: OpenClaw 2026.11.4 (d843d6a)
state restored to the 2026.11.4 copy; lock present: no
update rc=0
✅ OpenClaw updated to 2026.11.5 (from 2026.11.4); 23 warnings need attention.
RESULT C version_after=OpenClaw 2026.11.5 (ead12fa)
marker gateway.port = 18799

The candidate labeled ead12fa is the bench's own commit of this head's patch on top of main d5f3e4d7b75 (the same content as this head, which passed the CI-style check:changed run there; the full-product runs above use the same tree). A first attempt at phase C reinstalled 2026.11.4 on a state that phase B's candidate Doctor had already migrated, which 2026.11.4 refuses to open ("uses newer schema version 40; this build supports 22"); that was the test's mistake, so phase C restores the pre-B state.

Proof artifice: the lock record was written by a script (the reporter's own recipe) with an already-exited child process as the recorded owner; no Gateway was running in any run; the candidate was packed from this branch rather than published to npm.

Proof gap: the bun test runtime is not installed in the bench containers, so the bun run of the focused tests is left to PR CI. This improves the guidance shown by the new build only; Doctor's message in an install already rolled back to 2026.11.4 is unchanged.

Data model: no stored data or record format changes. The lock record is read as before; the only new stored effect is the removal of the inspected file after confirmation, which the recovery test suite covers for both the state-local and the historical layout.

Test lines are net +54 against main: the recovery layouts (system temp dir, state tmp dir, non-regular path, world-writable parent) are four rows of one new it.each in the existing recovery suite, and #201912's platform table additionally expects the recovery command on Linux; no existing test covers the historical path in recovery.

@clawsweeper

clawsweeper Bot commented Nov 19, 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 cli CLI command changes size: M labels Nov 19, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head fcefa387bf0c2dae2334206a0463805c4df00b7a, but the PR head is now d1d7fcc3e58d0738f615b242e11556c55b162096. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-19T14:57:42.870Z sha fcefa38 :: needs maintainer review before merge. :: none

…t blocks Doctor maintenance

On Linux, Doctor refuses maintenance while a historical per-config Gateway lock
in the system temporary directory records an owner it cannot verify (no
processNamespace), but `openclaw gateway recover-lock` only inspected the
state-local lock paths, so it reported nothing present and the documented
explicit recovery never reached that file. Updates then rolled back with
doctor-failed on every attempt.

On Linux, inspection now also observes the legacy lock when its directory and
file are owned by the current user and writable by nobody else (deduplicated
when a service TMPDIR inside the state directory makes it the same file;
otherwise the skipped file and reason are reported), confirmation removes it
first under the same unchanged-record checks, and the Doctor refusal names the
recovery command for that file. macOS and Windows admit a stopped
namespace-less owner by themselves (openclaw#182031, openclaw#201912) and are unchanged.
Namespace ownership policy is unchanged: the owner is never reclaimed
automatically.

Related: openclaw#201472 (an install already rolled back to a release without
recover-lock still needs a maintainer-chosen route)
@sukhdeepjohar
sukhdeepjohar force-pushed the fix-doctor-legacy-lock-recovery branch from fcefa38 to d1d7fcc Compare November 20, 2026 02:35
@sukhdeepjohar sukhdeepjohar changed the title fix(gateway): recover-lock can clear the legacy config lock that blocks Doctor maintenance fix(gateway): recover-lock can clear the Linux legacy config lock that blocks Doctor maintenance Nov 20, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 21, 2026
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

Closing this one. #205709 since removed the recover-lock command this PR extends, and the Linux refusal it addressed has not been reported by a user outside our own test runs. Leaving #201472 with the Doctor owner; happy to pick it up again if a user hits it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant