Skip to content

fix(doctor): unrelated macOS processes block updater runtime cleanup - #185359

Closed
fuller-stack-dev wants to merge 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/darwin-census-unterminated-environment
Closed

fuller-stack-dev wants to merge 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/darwin-census-unterminated-environment

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: on macOS, openclaw doctor --fix and post-update cleanup never remove retained openclaw-update-runtime-XXXXXX directories. Hundreds of unrelated system processes are reported as holders with "Could not verify runtime custody for PID N: process command is unavailable".

User Impact

User impact: on macOS, unrelated processes like webprivacyd, mdworker_shared, ssh, or sleep no longer block runtime cleanup. A retained runtime is kept only while a Node/Bun/tsx runtime, an OpenClaw process, or a process whose argv, cwd, or executable points into the runtime might still hold it. On one affected Mac this left 3–4 retained runtimes (~10.5 GB) that Doctor could not reclaim.

Why This Change Was Made

To identify OpenClaw services, the Darwin census reads OPENCLAW_SERVICE_MARKER from every process. On current macOS, many same-user platform binaries have an argument image whose environment section is unterminated. proc-safe then fails the whole read with incomplete, even though argv reads fine without the environment, and the census records "command unavailable" (unknown custody), which blocks removal.

On Linux the marker can only identify Node/Bun/tsx runtimes. This change applies the same rule on Darwin. When only the environment is unbounded, the census re-reads exact argv and classifies the process normally. Runtime executables still fail closed, because their marker can change identity. The runtime predicate now lives in one place, isServiceMarkerRuntime, shared by both platforms.

Accepted edge case: a non-runtime process whose environment is unbounded and that carries OPENCLAW_SERVICE_MARKER=openclaw is classified by its argv and cwd alone. That matches Linux. Its marker-bearing runtime children still block.

Evidence

Reproduced on macOS 27.2 (arm64), real census, no mocks, before editing (base ce069f9f837; rechecked at f0e7a65c63c and rebased onto 4fa15de9e5d; neither range touches the census, process, or classification paths):

  • Asking proc-safe for the environment fails for e.g. webprivacyd, /bin/sleep, and mdworker_shared with incomplete: unterminated Darwin environment. Reading the same PIDs without the environment returns exact argv.
  • maintainRetainedUpdateRuntimes (the Doctor retirement path) with the live census on an isolated, planted, marker-valid runtime that nothing references:
base f0e7a65c63c this PR
"process command is unavailable" warnings 353 0
blocking PIDs 379 36

On this PR, the remaining 36 blockers on that host are OpenClaw processes (fleet node run services, gateway, supervisor relays, OpenClaw.app), Node test runs inside OpenClaw worktrees, and two third-party Node processes whose script could not be resolved. Those intentionally stay fail-closed, so the full "Removed abandoned updater runtime" outcome was not observed on a host with OpenClaw running.

Tests (red on base, green here):

  • openclaw-process-census.test.ts › "classifies other Darwin processes by exact argv when their environment is unbounded". Base retains the webprivacyd fixture with "process command is unavailable". The same case keeps a /bin/sleep whose cwd is inside the runtime, and a process whose executable image is inside the runtime, as holders.
  • openclaw-process-census.native.test.ts › "retains a runtime only for real processes working inside it". Uses real orphaned /bin/sleep processes on macOS. Base reports the unrelated sleep along with 335 other PIDs; this PR reports only the one working inside the runtime.
  • Negative control: the existing "incomplete Darwin environment" case now covers runtimes whose argv is readable. A Node peer and the Node launcher keep unknown custody. Removing the runtime gate fails both cases (mutation-checked). That case's old /bin/sleep row, which asserted the bug, was replaced by the test above.

Checks: focused pnpm test over the census, retained-runtime, process-custody, Darwin command, argv classification, and plugin source-capture suites: 149/150 passed. The one failure is the existing native handoff test "finds a real non-Node process holding retained handoff paths". It flakes on the unmodified base too (1 of 6 runs failed with "Host process census is incomplete"). This change does not touch the handoff path, which already reads argv without the environment. After rebasing, the census, Darwin command, and missing-command suites pass 79/79. pnpm tsgo:core is clean, oxlint and oxfmt are clean on the changed files, and git diff --check is clean.

🤖 Generated with Claude Code

…time cleanup

The Darwin process census read OPENCLAW_SERVICE_MARKER for every process.
Many same-user platform binaries (webprivacyd, mdworker_shared, ssh, sleep)
have an argument image whose environment is unterminated, so proc-safe
failed the whole read with `incomplete` and the census recorded unknown
custody. Doctor and post-update cleanup then retained every
openclaw-update-runtime directory.

The marker only identifies Node/Bun/tsx runtimes, as on Linux. When only
the environment is unbounded, re-read exact argv and classify the process
normally; runtime executables keep unknown custody.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Retry incomplete macOS environment inspection without environment data for non-runtime processes while preserving uncertain custody for Node, Bun, and tsx.

Example: On macOS 27, /bin/sleep 62 runs outside /tmp/openclaw-update-runtime-Held01 and its environment cannot be inspected.

  • Before: The process becomes an unknown holder and prevents runtime cleanup.
  • After: Exact argv and filesystem references determine custody, so this unrelated sleep no longer blocks cleanup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful native-boundary evidence supports the repair, but the added census-specific policy should be consolidated with the shared reader.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor-proof gate is waived for this maintainer-authored PR; supplied macOS arm64 evidence exercises the real census and maintenance owner, but remaining holders prevented actual deletion.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Unrelated macOS processes prevent Doctor and updater maintenance from reclaiming abandoned runtime directories.
Reason: The maintainer-authored direction addresses a source-confirmed maintenance failure without adding configuration or weakening the native parser contract.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR addresses a current cleanup failure, but the fallback should use the existing shared Darwin command reader.

Priority: P2
Reviewed head: 507b70976b4b76589aae17c2b4031dea23d7a5a6

Before merge

  • Put the fallback in the existing Darwin command reader (P2) - This adds a second command-reading policy specifically for the census, although the same incomplete environment observation affects other consumers of readDarwinProcessCommand. For example, a live orphaned /bin/sleep with readable argv and an unbounded environment still throws from captureProcess in src/process/orphaned-process.ts:73, while this wrapper successfully reads it. The PR gives no reason those consumers should retain different behavior. Move the runtime-preserving fallback into the existing Darwin adapter and remove this wrapper; fix(process): classify macOS 27 system commands without an environment section #185342 already demonstrates that shared repair. This satisfies the repository's shared-owner and smallest-complete-fix requirements without adding a parallel interpretation of the same observation.

Findings

  • [P2] Put the fallback in the existing Darwin command reader — src/infra/openclaw-process-census.ts:73-83

Tests

  • Missing end-to-end proof: Supplied evidence does not show a shipped Doctor command removing an abandoned runtime or an upgrade run; red-on-base and green-on-head census regressions are reported.
Agent review details

How this fits together

Doctor and updater cleanup consume the process census, which combines native command observations, working directories, package identity, and artifact references to decide whether disposable runtimes remain held.

flowchart TD
  A[Darwin process observations] --> B[Shared Darwin command reader]
  B --> C[Census fallback added here]
  C --> D[Artifact custody classification]
  D --> E[Doctor and updater cleanup]
  B --> F[Gateway lock inspection]
  B --> G[Orphan process cleanup]
Loading

Technical review

Best possible solution:

Consolidate the fallback in the shared Darwin command reader, retaining runtime uncertainty and the distinct custody regressions from this PR.

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

The dependency parser and current-main census establish the cleanup-blocking path, corroborated by native results in this PR and the published-package reproduction at #183957; this review ran no target code.

Is this the best way to solve the issue?

The runtime-preserving fallback is appropriate application policy, but placing it in the existing Darwin reader provides one implementation for affected consumers, as demonstrated by #185342.

Full review comments:

  • [P2] Put the fallback in the existing Darwin command reader — src/infra/openclaw-process-census.ts:73-83
    This adds a second command-reading policy specifically for the census, although the same incomplete environment observation affects other consumers of readDarwinProcessCommand. For example, a live orphaned /bin/sleep with readable argv and an unbounded environment still throws from captureProcess in src/process/orphaned-process.ts:73, while this wrapper successfully reads it. The PR gives no reason those consumers should retain different behavior. Move the runtime-preserving fallback into the existing Darwin adapter and remove this wrapper; fix(process): classify macOS 27 system commands without an environment section #185342 already demonstrates that shared repair. This satisfies the repository's shared-owner and smallest-complete-fix requirements without adding a parallel interpretation of the same observation.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9ef140709309.

Provenance checked

  • Incomplete Darwin environment custody changes intended behavior with a stated reason (4797b07: Continue the census after an incomplete observation while retaining unknown custody instead of assuming an absent marker.)
  • Linux runtime marker predicate keeps the original intent (79deea8: Distinguish unrelated runtime processes without losing OpenClaw service-marker identity.)
  • Marker-free update handoff inspection keeps the original intent (45314c9: Handoff matching uses argv and cwd and therefore skips environment inspection.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 79deea8 adds src/infra/gateway-process-argv.ts:247 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 79deea8c3e75; files: src/infra/gateway-process-argv.ts)

PR surface

Source +30, Tests +46. Total +76 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 36 6 +30
Tests 2 57 11 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 93 17 +76

Review metrics

Metric Value Why it matters
Production versus test changes Production +36/-6; tests +57/-11 The native regression covers a distinct OS boundary; production growth includes a caller-specific fallback that can instead reside in the existing reader.

Root-cause cluster

Relationship: same_root_cause
Canonical: #183957
Summary: The missing Darwin environment boundary produces incomplete command observations; both open repairs recover non-runtime argv while the earlier mitigation only prevented census-wide failure.

Members:

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

Labels

Label changes:

  • add P2: The demonstrated current problem retains disposable updater runtimes and consumes disk space; the supplied evidence does not establish that this remaining path prevents updates from completing.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The demonstrated current problem retains disposable updater runtimes and consumes disk space; the supplied evidence does not establish that this remaining path prevents updates from completing.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 October 26, 2026, 11:08 PM ET / October 27, 2026, 03:08 UTC.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Superseded by #185342 (merged as a9e413e), which applies the same fallback in the shared readDarwinProcessCommand reader: an incomplete environment read retries with argv only, and Node/Bun/tsx stay fail-closed. On current main the census and captureProcess both go through that reader, so this PR's census-only wrapper would duplicate the policy, which is what ClawSweeper flagged. Root cause tracked in #183957. Closing without merge.

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

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant