Repository navigation
fix(gateway): recover-lock can clear the Linux legacy config lock that blocks Doctor maintenance - #201893
Closed
sukhdeepjohar wants to merge 1 commit into
Closed
fix(gateway): recover-lock can clear the Linux legacy config lock that blocks Doctor maintenance#201893sukhdeepjohar wants to merge 1 commit into
sukhdeepjohar wants to merge 1 commit into
Conversation
Contributor
|
🦞👀 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. |
Contributor
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
sukhdeepjohar
marked this pull request as ready for review
November 19, 2026 17:10
…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
force-pushed
the
fix-doctor-legacy-lock-recovery
branch
from
November 20, 2026 02:35
fcefa38 to
d1d7fcc
Compare
This was referenced Nov 23, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-lockdoes not inspect it. This PR makesrecover-lockinspect 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; andopenclaw 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-lockcommand is available. An install already rolled back to 2026.11.4 has norecover-lockcommand, 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 thatrecover-lockalready inspects, and #201912's refusal already namesrecover-lockthere; 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 sameTMPDIR), 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 whenrecover-lockskips 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-locknames 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-lockdoes 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.mjsof a built tree, Linux container, root): the reporter's lock record (noprocessNamespace, exited PID, mtime 30 Sep 2026) at/tmp/openclaw-0/gateway.<hash>.lock, thendoctor --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):Live run with this PR
Same container recipe, same record, the patched build of this head on that main:
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 owncheck:changedon the bench.Upgrade run from a real 2026.11.4 install (Linux container, user
node)npm i -g [email protected], state initialized byopenclaw 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 withscripts/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.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-locklists the record and prints the confirm command, the confirm removes the file, Doctor exits 0, and the config marker and state database are intact.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.
The candidate labeled
ead12fais the bench's own commit of this head's patch on top of maind5f3e4d7b75(the same content as this head, which passed the CI-stylecheck:changedrun 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 newit.eachin 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.