Skip to content

fix: Doctor skips capture cleanup when unrelated Node services run - #157102

Merged
steipete merged 1 commit into
mainfrom
upd/doctor-process-census-node-dist-index
Sep 24, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/doctor-process-census-node-dist-index

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Fixes #156896.

What Problem This Solves

Doctor can leave legacy plugin captures on disk indefinitely when an unrelated Node service runs node dist/index.js.

User Impact

Doctor can reclaim eligible captures when the process belongs to a verified unrelated package. Actual OpenClaw owners still prevent reclamation. Unclassifiable live PIDs, including missing or unreadable package metadata, preserve captures with an explicit PID and reason instead of being reported as OpenClaw. These remain maintenance warnings; updates continue best effort.

Why This Change Was Made

The shared process classifier accepted any argument ending in generic names such as dist/index.js. It now identifies the runtime script, resolves relative paths using the observed process working directory, and checks the resolved installation's package identity. Doctor also reads the existing OpenClaw service marker; maintenance leases and SQLite capture custody remain authoritative and unchanged.

The same classifier serves update/restart discovery, Gateway verification, and legacy lock recovery. On Windows, process control can fall back to verifying a relative entrypoint through the existing current Gateway lease, binding the listener PID, native creation identity, port, and selected service environment; it rechecks ownership before signaling. Unknown lock owners remain unknown. Windows stale cleanup warns and leaves unclassified listeners running; it never uses a live owner lease as evidence that its owner is stale. Linux uses procfs cwd; Darwin uses exact native argv and NUL-delimited cwd inspection. The separate port-error hint no longer treats generic script names as OpenClaw.

Thanks @xilopaint for the unmodified-package namespace reproduction and detailed diagnosis.

Evidence

The Linux importer run on Blacksmith Testbox tbx_01m38sv9n2ftkxbc0gagn7xtzq (run) covered all 123 selected files in their original order: 4,454 passed, 35 existing skips, no failures (1,043.16 s total across 14 groups, including shared compiler preparation). The additional status-all diagnosis suite passed all 30 tests on Linux and locally. pnpm check:changed and pnpm build passed on Blacksmith Testbox tbx_01m38zmqvydsn0jy1cjcx3rrx5 (run); command exit 0. The earlier lease expired during an earlier check attempt; only the completed replacement is claimed here.

The public openclaw.mjs doctor --fix --non-interactive --yes --no-workspace-suggestions entrypoint passed all five Linux PID/mount/network-namespace cells with isolated state and ports:

Candidate Doctor cell Result Doctor time
Control Capture removed 4.416 s
Unrelated node dist/index.js still running Capture removed 4.304 s
Real resolved OpenClaw package child Capture preserved; exact owner PID reported 4.305 s
Live PID with deleted script Capture preserved; explicit unclassified PID/reason warning 4.464 s
Actual public Gateway child Capture preserved; exact owner PID reported 4.590 s

On the same Testbox, unmodified published 2026.9.6 installed through pnpm reproduced the defect: control removed the capture (4.134 s); unrelated node dist/index.js preserved it and was incorrectly named as OpenClaw (3.738 s). No container or ownership guard was bypassed.

The unmodified published 2026.9.6 updater → candidate cell passed on Blacksmith Testbox tbx_01m3909bmvsfx5j0ph0wqbcs2x (run). Public command: node <published-root>/openclaw.mjs update --tag <candidate.tgz> --yes --json --no-restart, using the isolated install prefix, cached dependencies, and disconnected network namespace. Update reported status: ok, exit 0, in 86.720 s; all 10,877 installed dist files matched the candidate artifact. The capture remained while the real updater parent was live. Afterward the installed candidate's public Doctor removed it in 3.898 s, with the unrelated Node child still alive.

The source package's version metadata is 2026.9.5, so the existing first-hop fixture helper stamped only the isolated artifact's supported version metadata as 2026.9.99-first-hop.0; repository metadata and runtime code were unchanged. Original candidate SHA-256: fafc5974fe5916fd7249ca48caa2221392d6d2164b4ac08f11abd50558b213b2; fixture SHA-256: 2861184e34a4042b15f73b49a0dabd42c4da172b06f2ce522285faf3c805e056. The first attempt stopped before installation because user-namespace UID remapping made root-owned ancestors appear unowned. The corrected harness preserved the runner UID/GID and root ownership; no product guard was weakened. A source-freeze retry after staging was also confined to harness preparation.

Fresh Codex autoreview --mode branch --base origin/main on commit 9458eeaec012d6b20d83fedec146c7f6a42f3aa8: scoped-clean, no actionable P0–P2 findings. The committed tree is identical to the tree used for importer, gate, build, and native proof: 667be109dfe45ee44ff613b842bef5259b7a0b2d.

The original census unit regression reproduced the false positive: an unrelated Node PID appeared as an OpenClaw owner. The two Windows Startup fallback failures encoded the same invalid assumption with nonexistent generic paths. Their fixtures now create real dist/index.js files beneath roots whose package.json declares name: "openclaw"; persisted-command mismatch, no-termination, and running/PID assertions are unchanged. All 87 Startup fallback tests pass; the Linux file accumulated 503.29 ms of test work.

Production is +439/−239 lines (net +200). Tests/support are +939/−328; documentation is +10/−1. The shared classification owner contains runtime option arity, canonical CLI command selection, resolved package identity, native cwd inspection, and explicit ownership/uncertainty facts. Remaining call-site changes are:

Call site Why it remains
Doctor census Supplies observed PID/marker and the maintained worker registry; preserves unknown-PID warnings. Its duplicate classifier is deleted.
Legacy lock recovery Consumes the same tri-state result so unreadable identity remains unknown instead of reclaiming a live lock.
Restart/discovery Supplies target PID for relative-path resolution and uses the shared native argv reader. lsof command names never bypass ownership verification; its obsolete name parser is removed. Windows stale cleanup warns and leaves unknown listeners running.
Windows ownership Supplies the current PID-incarnation lease, port, and selected service environment to the shared classifier; refreshes them before signaling. A recorded owner is never a stale target.
Darwin argv Reuses exact native argv across census, lock, and discovery, retaining only the service marker from environment bytes. Duplicate whitespace parsing is deleted.
Port diagnostics Uses the shared ownership result for Gateway listener classification, preserving SSH/socat formatting. Removes the separate text-based error hint; keeps inspected listener details and neutral port-resolution guidance.

Windows host-wide capture cleanup remains report-only. No new public options, dependencies, schemas, or baseline suppressions. macOS and Windows native live proof are not available from the Linux Testbox; their adapters have unit coverage.

The importer harness returned its timing-only exit 3 after all assertions passed; the maintainer overruled this timing gate and assigned the fixture-performance work separately. Existing slow but passing suites remain in importer coverage with their assertions and test tier unchanged: update-cli.test.ts 279.702 s, doctor-health.test.ts 161.095 s, and update-command-original-service.test.ts 121.576 s of accumulated test time. These repeated state/process fixture costs are tracked separately from this classifier change.

Changed test-file cost

Measured on Linux with pnpm test <file> --maxWorkers=1. Wall time includes shared transform/setup; test time is the accumulated measured test work. Hosted PR CI timings are pending.

File Wall seconds Test milliseconds Passed
restart.test.ts 17 79.24 16
ports-format.test.ts 1 82.92 47
schtasks.startup-fallback.test.ts 19 503.29 87
diagnostic-process-siblings.env.test.ts 16 308.81 10
gateway-processes.test.ts 1 62.44 16
restart-stale-pids.cwd.test.ts 2 56.46 7
lifecycle.test.ts 15 74.11 56
gateway-process-argv.test.ts 1 58.94 27
openclaw-process-census.test.ts 14 67.11 31
gateway-lock.test.ts 15 588.71 49
restart-stale-pids.test.ts 2 133.64 72
ports.test.ts 1 173.89 65
darwin-process-command.test.ts 2 5.23 21
doctor-plugin-source-captures.test.ts 14 75.53 16

Verify runtime entrypoints against resolved package ownership and share explicit OpenClaw, unrelated, and unclassified outcomes across process consumers. Preserve captures and locks when ownership cannot be established.

Fixes #156896. Thanks @xilopaint for the namespace reproduction.
@clawsweeper

clawsweeper Bot commented Sep 24, 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 labels Sep 24, 2026
@steipete
steipete marked this pull request as ready for review September 24, 2026 06:50
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 24, 2026, 2:56 AM ET / 06:56 UTC.

ClawSweeper review

What this changes

The branch makes Doctor and Gateway process discovery classify generic Node entrypoints by resolved package identity, with updated platform adapters, tests, and troubleshooting guidance.

Merge readiness

⛔ Blocked before merge - 5 items remain

This PR addresses the reported Doctor false positive, and current main still contains it. The proposed classifier has a separate ownership gap on Linux: Doctor can read a live process’s package identity from the wrong mount namespace, then reclaim a capture that process still needs.

Priority: P1
Reviewed head: 9458eeaec012d6b20d83fedec146c7f6a42f3aa8

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has substantial real Doctor and update proof, but the unresolved cross-namespace deletion boundary limits merge confidence.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the PR reports public Linux Doctor before/after and published-updater runs, including a real Gateway owner in the isolated setup. It does not show that a live owner with a colliding path in another mount namespace prevents the final capture deletion. No stored-data schema contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the PR reports public Linux Doctor before/after and published-updater runs, including a real Gateway owner in the isolated setup. It does not show that a live owner with a colliding path in another mount namespace prevents the final capture deletion. No stored-data schema contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Current main still has the reported false positive: The current classifier accepts any argument ending in a generic entrypoint such as dist/index.js, without checking its package.
Introduced process identity decision: The patch combines a PID's reported working directory with its script, then resolves that path and reads package.json in Doctor's filesystem view.
Deletion depends on the census: Doctor allows capture pruning when the census returns no OpenClaw PIDs; the pruning owner rechecks that condition immediately before removal.
Findings 1 actionable finding [P1] Resolve process package identity in its mount namespace
Security Needs attention Host path can misidentify a live capture owner: The classifier can consume a target PID's cwd string but read the script and manifest from Doctor's mount namespace; a same-path unrelated host package can authorize removal while the actual OpenClaw process remains live.

How this fits together

Doctor inspects legacy plugin captures before removing them during maintenance. A host process census supplies owner identities; its result also informs Gateway discovery and restart decisions.

flowchart TD
  A[Doctor maintenance] --> B[Legacy captures]
  A --> C[Host process census]
  C --> D[Process command and filesystem identity]
  D --> E{OpenClaw owner or uncertain?}
  E -->|Yes| F[Preserve captures]
  E -->|No| G[Reclaim eligible captures]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the PR reports public Linux Doctor before/after and published-updater runs, including a real Gateway owner in the isolated setup. It does not show that a live owner with a colliding path in another mount namespace prevents the final capture deletion. No stored-data schema contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve process package identity in its mount namespace (P1) - On a host running Doctor, a live OpenClaw process in another mount namespace can report /app as its cwd while the host's /app contains an unrelated package. Resolving dist/index.js against the host path returns other; the census then permits removal of a capture shared with that live owner. Read the script and manifest through the target PID's filesystem view, or keep the PID unclassified.
  • Resolve security concern: Host path can misidentify a live capture owner - The classifier can consume a target PID's cwd string but read the script and manifest from Doctor's mount namespace; a same-path unrelated host package can authorize removal while the actual OpenClaw process remains live.
  • Resolve merge risk (P1) - A host-run Doctor can mistake a live OpenClaw process in another mount namespace for an unrelated package when the host has a different package at the same path, then remove a shared legacy capture.
  • Complete next step (P2) - Repair target-PID filesystem identity and prove that a live OpenClaw owner in another mount namespace prevents capture deletion before merge.

Findings

  • [P1] Resolve process package identity in its mount namespace — src/infra/gateway-process-argv.ts:179-183
  • [medium] Host path can misidentify a live capture owner — src/infra/gateway-process-argv.ts:183
Agent review details

Security

Needs attention: Cross-namespace package lookup can weaken the process-ownership guard for legacy capture deletion.

PR surface

Source +200, Tests +611, Docs +9. Total +820 across 31 files.

View PR surface stats
Area Files Added Removed Net
Source 15 439 239 +200
Tests 15 939 328 +611
Docs 1 10 1 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 31 1388 568 +820

Review metrics

Metric Value Why it matters
Production and test LOC production +200 net; tests/support +611 net The PR body attributes production growth to the shared classifier and affected platform callers, with separate test coverage for those paths.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #156896
Summary: This PR is the candidate fix for the still-open Doctor capture-cleanup report.

Members:

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

Merge-risk options

Maintainer options:

  1. Verify identity in the target filesystem view (recommended)
    Resolve the entrypoint and manifest through the target PID's procfs view and demonstrate that a live OpenClaw owner prevents final capture removal.
  2. Preserve uncertain cross-mount owners
    Return an unclassified result for process identities whose package cannot be verified in their own mount view, leaving their captures intact.

Technical review

Best possible solution:

Resolve a Linux PID's script and package manifest through that PID's filesystem view, preserve an explicit unknown result when identity cannot be established, and prove the final Doctor deletion decision with colliding paths across mount namespaces.

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

Yes for the reported defect: the reporter supplied a public Doctor reproduction on published 2026.9.6, and current main retains the same classifier. The cross-mount safety case identified in this review has source evidence but no observed final-effect run.

Is this the best way to solve the issue?

No as submitted: a shared classifier is the appropriate owner, but its Linux package check must use the target process's mount view before it can authorize capture removal.

Full review comments:

  • [P1] Resolve process package identity in its mount namespace — src/infra/gateway-process-argv.ts:179-183
    On a host running Doctor, a live OpenClaw process in another mount namespace can report /app as its cwd while the host's /app contains an unrelated package. Resolving dist/index.js against the host path returns other; the census then permits removal of a capture shared with that live owner. Read the script and manifest through the target PID's filesystem view, or keep the PID unclassified.
    Confidence: 0.84

Overall correctness: patch is incorrect
Overall confidence: 0.84

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a3210acd3db8.

Labels

Label changes:

  • add P1: The shipped Doctor defect can indefinitely block large capture cleanup, while the proposed ownership decision also needs a safety repair before merge.
  • add merge-risk: 🚨 security-boundary: The patch changes which external process identities authorize deletion of shared capture files.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the PR reports public Linux Doctor before/after and published-updater runs, including a real Gateway owner in the isolated setup. It does not show that a live owner with a colliding path in another mount namespace prevents the final capture deletion. No stored-data schema contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The shipped Doctor defect can indefinitely block large capture cleanup, while the proposed ownership decision also needs a safety repair before merge.
  • merge-risk: 🚨 security-boundary: The patch changes which external process identities authorize deletion of shared capture files.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the PR reports public Linux Doctor before/after and published-updater runs, including a real Gateway owner in the isolated setup. It does not show that a live owner with a colliding path in another mount namespace prevents the final capture deletion. No stored-data schema contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Host path can misidentify a live capture owner — src/infra/gateway-process-argv.ts:183
    The classifier can consume a target PID's cwd string but read the script and manifest from Doctor's mount namespace; a same-path unrelated host package can authorize removal while the actual OpenClaw process remains live.
    Confidence: 0.84

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ee5f7c6 adds src/infra/openclaw-process-census.ts:37 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ee5f7c61c5b7; files: src/infra/openclaw-process-census.ts)
  • Dallin Romney: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prove through public Doctor that an allowed unrelated process permits cleanup and a live OpenClaw process in another mount namespace with a colliding path prevents final file removal.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete enabled auto-merge (squash) September 24, 2026 06:59
@steipete
steipete merged commit 79deea8 into main Sep 24, 2026
269 of 274 checks passed
@steipete
steipete deleted the upd/doctor-process-census-node-dist-index branch September 24, 2026 07:10
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…#157102)

Verify runtime entrypoints against resolved package ownership and share explicit OpenClaw, unrelated, and unclassified outcomes across process consumers. Preserve captures and locks when ownership cannot be established.

Fixes openclaw#156896. Thanks @xilopaint for the namespace reproduction.
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 merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Doctor legacy capture cleanup misidentifies unrelated Node.js services as OpenClaw processes

1 participant