Skip to content

fix: let macOS updates finish when an old Gateway left a dead lock file - #201912

Merged
steipete merged 1 commit into
mainfrom
codex/issue-201472
Nov 19, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/issue-201472

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #201472
Related: #201893

What Problem This Solves

On macOS, an OpenClaw Gateway that crashed before 2026.10.1 could leave its lock file behind. Every later update then failed. Doctor refused to start maintenance with Legacy Gateway lock … still has a live or unverified owner (PID …), and the update rolled back, even though that PID had exited weeks earlier. One reporter's Mac rolled back the automatic 2026.11.4 → 2026.11.5 update with doctor-failed in 19 of 20 attempts over 23 hours. Each attempt restarted the Gateway. A 2026.11.5 Gateway started by hand also refuses the same file.

User Impact

User impact: on macOS, updates and Gateway startup recover on their own from a dead lock file left by a Gateway older than 2026.10.1. A lock whose process is still running, or whose death can't be proven, is still refused. Linux behavior is unchanged: such a record still needs explicit recovery. The refusal now names the recovery step for the exact file it found.

Why This Change Was Made

Gateways add a processNamespace (host, boot, PID namespace) to lock records starting in 2026.10.1 (#164236). Since #178076, a record without one is unverifiable, so a PID probe can't prove its owner stopped. On Linux that's necessary: a Gateway in a container with its own PID namespace can share the lock directory, and its PID means nothing to the host. #182031 added a narrow exception for Windows legacy records, whose PIDs are host-global. The record counts as dead only when its heartbeat (file mtime) is more than 90 seconds old and native PID inspection or a changed process start identity proves the owner stopped.

macOS PIDs are host-global too. macOS has no PID namespaces, and containers run inside a VM. The same rule is sound there, so classifyGatewayLockProcessNamespace now applies it on darwin as well as win32. Both callers go through this one classifier: Doctor's legacy maintenance gate and Gateway startup's historical-lock check. On the macOS LaunchAgent layout, the service TMPDIR is $OPENCLAW_STATE_DIR/tmp, so the "legacy" path and the state-local config lock are the same file.

The Doctor legacy refusal used to say only "stop the Gateway service and rerun Doctor", which can't help with a file a dead process left. It now names the step that works for that file. For the state-local file it points to openclaw gateway recover-lock. For the system temporary directory it says to remove the file after confirming the process has stopped, because recover-lock inspects only state-local locks.

Accepted edge case, the same one #182031 accepted for Windows: another kernel, such as a Linux VM guest or a second machine, writes a pre-2026.10.1 record into shared storage and its Gateway is still running. A dead PID on this host can't see that.

Rejected alternatives:

Production LOC: +17 / −4 across gateway-lock-payload.ts and gateway-lock-legacy.ts, plus the docs line in docs/gateway/gateway-lock.md.

Evidence

Real macOS, real PIDs, scratch state only. This uses #201472's source-level script, extended to the LaunchAgent TMPDIR=$OPENCLAW_STATE_DIR/tmp layout and the Gateway-start inspection. The live control uses the script's own running process with its real start identity.

Layout Check Base (main 44267df6c5e) This PR
system temp Doctor maintenance, dead PID refused admitted
state tmp (LaunchAgent) Doctor maintenance, dead PID refused admitted
state tmp (LaunchAgent) Gateway start inspection, dead PID refused admitted
both live PID control refused refused

Linux, Crabbox AWS, published 2026.11.5. The reporter's reproduce.sh refuses in both layouts. In the state-tmp layout, openclaw gateway recover-lock lists the record and its --confirm command removes it. In the system-temp layout, recover-lock reports nothing, and removing the file by hand after ps -p <PID> fails works. Doctor exits 0 after either step. This PR leaves Linux classification unchanged.

Tests. gateway-lock-legacy.test.ts now runs the exited, reused, live, unverifiable and recently-exited owners on win32, darwin and linux. On base the macOS exited and reused cases fail. linux stays refused for every owner and asserts the new recovery hint. The missing-namespace owner-lock test in gateway-lock.namespace.test.ts pins Linux, because macOS now reclaims a provably exited owner there.

Local results:

  • Touched suites: 53/53.
  • Consumers (update service drain and unavailable, Doctor maintenance interruption, legacy-update health, lock recovery, state-owner heartbeat, gateway-lock, stale lock file): 178/178.
  • oxlint core shard and oxfmt clean.

A Gateway lock written before 2026.10.1 has no processNamespace. On macOS
such a record was always unverifiable, so an orphaned config lock left by a
crashed older Gateway made Doctor refuse maintenance forever: the update from
2026.11.4 rolled back with doctor-failed in 19 of 20 attempts, and a started
2026.11.5 Gateway refused the same file.

macOS PIDs are host-global like Windows PIDs, so namespace-less macOS file
locks now use the existing Windows rule: an expired heartbeat plus native PID
death or a changed process start identity proves the owner stopped. Live and
unprovable owners stay refused. Linux keeps refusing because a container in
another PID namespace can share the lock directory. The legacy refusal now
names the recovery step for the file it found.

Refs #201472
@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 size: S labels Nov 19, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Extend automatic dead-owner classification to legacy macOS Gateway locks and add recovery guidance to Doctor refusals.

Example: A macOS lock records exited PID 71333, lacks processNamespace, and has an expired heartbeat.

  • Before: Doctor refuses maintenance, causing the update to roll back.
  • After: The classifier recognizes the stopped owner and lets maintenance proceed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-consistent, with useful native-process experiments, but the required shipped-entry-point and upgrade proof remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An obsolete dead Gateway lock can make every automatic macOS update roll back and prevent Gateway startup.
Reason: The observed update failure warrants this narrow repair, and maintainer authorship supplies direction for the documented macOS exception; the broader linked issue correctly remains Related.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR narrowly addresses a current macOS update blocker through the existing lock classifier, and no introduced correctness defect was found.

Priority: P0
Reviewed head: 40e783ae2e604d5b093ced67b361b2edfc6c40fd

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted patched macOS CLI evidence for Doctor and Gateway startup in both temporary-directory layouts, a live-owner refusal, and a latest-stable-to-candidate update preserving settings and state; redact IPs, API keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Doctor maintenance and Gateway startup read persisted lock records through the shared ownership classifier, which returns same, dead, or unknown before callers acquire their own state custody.

flowchart TD
  A[Doctor maintenance] --> C[Legacy lock reader]
  B[Gateway startup] --> D[Shared lock classifier]
  C --> D
  E[Lock record and heartbeat] --> D
  F[Native process identity] --> D
  D --> G[Admit dead owner or preserve refusal]
Loading

Technical review

Best possible solution:

Use the existing classifier for automatic macOS dead-lock recovery and retain separate confirmed recovery for unverifiable Linux owners.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the refusal path, and the linked report supplies released-package controls and macOS observations; this read-only review executed no target code.

Is this the best way to solve the issue?

The change is the smallest complete macOS repair: it reuses the established classifier, heartbeat threshold, and native identity checks while preserving Linux's distinct namespace boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 576b22128f23.

Provenance checked

  • Legacy file-lock classification and documentation changes intended behavior with a stated reason (f55f561: Recover supported Windows legacy locks using an expired heartbeat and native proof of process death without treating a missing namespace as local authority.)
  • Unverifiable-owner protection changes intended behavior with a stated reason (edea119: Preserve paused and foreign-namespace owners because heartbeat expiry and unavailable process observations do not prove death.)
  • Doctor legacy maintenance refusal keeps the original intent (aac5c4d: Prevent offline maintenance beneath a retained legacy Gateway while supporting candidate-side update restoration.)
  • Legacy maintenance regression coverage keeps the original intent (c824dc9: Pass the historical lock path into ownership inspection and protect exited, reused, live, unknown, and fresh-owner outcomes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +13, Tests +15, Docs 0. Total +28 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 16 3 +13
Tests 2 53 38 +15
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 71 43 +28

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P0: The UX override applies: affected community installations repeatedly fail automatic updates, and the available recovery requires terminal commands or manual lock removal.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P0: The UX override applies: affected community installations repeatedly fail automatic updates, and the available recovery requires terminal commands or manual lock removal.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed November 19, 2026, 10:52 AM ET / 15:52 UTC.

@steipete
steipete marked this pull request as ready for review November 19, 2026 16:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:09:19.084660Z 40e783a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete merged commit 697b156 into main Nov 19, 2026
281 of 285 checks passed
@steipete
steipete deleted the codex/issue-201472 branch November 19, 2026 16:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

sukhdeepjohar added a commit to sukhdeepjohar/openclaw that referenced this pull request Nov 20, 2026
…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)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…ce (openclaw#201912)

A Gateway lock written before 2026.10.1 has no processNamespace. On macOS
such a record was always unverifiable, so an orphaned config lock left by a
crashed older Gateway made Doctor refuse maintenance forever: the update from
2026.11.4 rolled back with doctor-failed in 19 of 20 attempts, and a started
2026.11.5 Gateway refused the same file.

macOS PIDs are host-global like Windows PIDs, so namespace-less macOS file
locks now use the existing Windows rule: an expired heartbeat plus native PID
death or a changed process start identity proves the owner stopped. Live and
unprovable owners stay refused. Linux keeps refusing because a container in
another PID namespace can share the lock directory. The legacy refusal now
names the recovery step for the file it found.

Refs openclaw#201472

Co-authored-by: Peter Steinberger <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
…ce (#201912)

A Gateway lock written before 2026.10.1 has no processNamespace. On macOS
such a record was always unverifiable, so an orphaned config lock left by a
crashed older Gateway made Doctor refuse maintenance forever: the update from
2026.11.4 rolled back with doctor-failed in 19 of 20 attempts, and a started
2026.11.5 Gateway refused the same file.

macOS PIDs are host-global like Windows PIDs, so namespace-less macOS file
locks now use the existing Windows rule: an expired heartbeat plus native PID
death or a changed process start identity proves the owner stopped. Live and
unprovable owners stay refused. Linux keeps refusing because a container in
another PID namespace can share the lock directory. The legacy refusal now
names the recovery step for the file it found.

Refs #201472

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit 697b156)

Companion audit: Existing expired legacy lock recovery now also uses native Darwin PID identity; live/unknown owners stay protected and Linux namespaces unchanged. Full diff reviewed; no pinned later path fixes.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit dc423441ea3dc2ee4381be0eee3635fc742cc41e)
(cherry picked from commit 67b154a3049570f901f60992ccfe7f29ebb1a355)
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 P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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.

1 participant