Skip to content

fix(doctor): reclaim legacy pnpm runtimes and TMP/TEMP service scratch - #160164

Merged
steipete merged 18 commits into
mainfrom
fix/r97-forward-16
Sep 28, 2026
Merged

steipete merged 18 commits into
mainfrom
fix/r97-forward-16

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After an update, the newer Doctor could leave abandoned updater runtimes behind in two situations: legacy pnpm runtime projections whose recorded package root no longer matches the currently installed pnpm version, and scratch directories selected through the managed service's TMP or TEMP (not just TMPDIR), including Windows casing and drive-relative paths.

Forward-ports two of the three retained-runtime review corrections from abandoned release-branch commit c9de04a, adapted to current main. Thanks to Vincent Koc for the original work.

Summary

  • Doctor recognizes legacy pnpm projections through a symlink-safe scan of sibling openclaw@* versions in the same projected store, bounded to 4,096 immediate entries (fails closed with guidance beyond that); existing maintenance, process, identity and custody checks are unchanged.
  • Doctor's service scratch discovery reads TMPDIR, TMP and TEMP from the environment and the managed service definition (case-insensitive environment keys on Windows); a relative service path is resolved only against an absolute working directory on the same drive, otherwise Doctor warns that it could not inspect it.
  • Tests pin that failed mutation/recovery barriers and pending nonzero exits stay nonzero (main's existing barrier behavior).
  • Dropped from the original forward-port: the retained-runtime exit watchdog. In production its only retained resource is the SQLite broker, so forcing exit on a broker stall can interrupt accepted state writes (ClawSweeper P1). A safe version needs broker retirement split into mandatory settlement and disposable termination; tracked in Update: bound the retained-runtime exit only after SQLite broker settlement #160690.

Evidence

  • Red before production edits: src/flows/doctor-retained-runtime.test.ts failed for the missing service-root reports/warnings, Windows path resolution and old pnpm projections; green after (the bounded-inventory case uses a synthetic directory iterator instead of creating 4,097 directories).
  • Final reduced branch: 101 tests across the six touched/related files pass; pnpm tsgo:core and matching core test typechecks, targeted oxlint, oxfmt, madge (0 cycles), git diff --check pass. Autoreview (branch mode, P1): scoped-clean.
  • Test cost (single worker, local): src/flows/doctor-retained-runtime.test.ts 27 tests, about 45 s including transform (the bounded-inventory case 59 ms).

Remaining gaps (accepted by the maintainer)

  • Native Windows: managed-service TMP/TEMP casing and drive-relative handling are covered by the real path/environment owners under simulated win32 semantics only; no native Windows service run. The release Full Release Validation's Windows packaged-upgrade lanes are the regression check.
  • Published 2026.9.6 updater x candidate: covered by the post-merge Package Acceptance published-upgrade-survivor run on main (P5 fix(doctor): prevent plugin load errors after read-only inspection #160446 has landed), per maintainer decision; the release FRV runs the same cell on the re-cut branch.

Release note: Doctor now cleans up abandoned updater runtimes after a pnpm version change and in managed-service scratch selected via TMP/TEMP (Windows paths covered by simulated-platform tests).

…ions

Forward-port retained runtime review corrections from c9de04a. Preserve the recorded watchdog outcome and retained files when workers cannot close, recognize legacy pnpm projections within the same store, and inspect service TMP/TEMP roots without guessing relative paths.

Co-authored-by: Vincent Koc <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 28, 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 cli CLI command changes commands Command implementations size: M labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 4:25 PM ET / 20:25 UTC (Revision 16).

ClawSweeper review

What this changes

Doctor discovers abandoned updater runtimes from older pnpm package versions and managed-service TMP/TEMP locations, with recovery documentation and regression tests.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: current main still misses the reported recovery paths. The latest head removed the unsafe exit watchdog identified in the prior review, leaving a distinct, useful Doctor fix.

Priority: P2
Reviewed head: e27b29ada757cdc5e6657f1c21ae186f24fd98d6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused recovery patch has meaningful boundary regressions, with platform and published-driver observations scheduled for later validation.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: The supplied repository state classifies this as member-authored, so the external-contributor proof gate does not apply. Doctor flow tests exercise synthetic retained runtimes through the cleanup owner with mocked service and census inputs; native Windows and published-updater observations are deferred in the PR body. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state classifies this as member-authored, so the external-contributor proof gate does not apply. Doctor flow tests exercise synthetic retained runtimes through the cleanup owner with mocked service and census inputs; native Windows and published-updater observations are deferred in the PR body. No stored-data contract changes.
Evidence reviewed 10 items Current main misses legacy pnpm projections: The main-branch cleanup recognizes a marker only at the current package root; it does not search sibling pnpm versions.
Current main misses managed-service TMP/TEMP: The main-branch service reader inspects only TMPDIR.
Introduced recovery lookup: The branch scans sibling openclaw versions within the same projected pnpm store, rejects symlinked paths, and bounds the inventory.
Findings None None.
Security None None.

How this fits together

The updater can retain a copy of its running code while replacing an installation. Doctor uses package roots and temporary-directory locations to find those copies, then checks their identity, maintenance ownership, and process liveness before reporting or removing them.

flowchart LR
  A[Installed package roots] --> C[Doctor scan]
  B[Service temporary paths] --> C
  C --> D[Runtime marker check]
  D --> E[Identity and custody checks]
  E --> F[Maintenance and process checks]
  F --> G[Retain or remove runtime]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +61, Tests +165, Docs +5. Total +231 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 78 17 +61
Tests 2 171 6 +165
Docs 1 7 2 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 256 25 +231

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/infra/temp-artifact-cleanup.ts, unknown-data-model-change: src/commands/doctor/shared/temporary-directories.ts, unknown-data-model-change: src/infra/temp-artifact-cleanup.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep Doctor’s bounded recovery and final deletion safeguards, and address safe updater exit after SQLite settlement in #160690.

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

Yes, from source: current main reads only service TMPDIR and matches the current package root, leaving the reported TMP/TEMP and older pnpm cases outside Doctor’s scan. This read-only review did not run the flow.

Is this the best way to solve the issue?

Yes. The branch extends Doctor’s existing cleanup owner and retains its maintenance, identity, and process checks; the unsafe exit watchdog has been removed.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: Abandoned updater runtimes after an update are a bounded recovery defect; the stalled-exit concern is separately tracked.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state classifies this as member-authored, so the external-contributor proof gate does not apply. Doctor flow tests exercise synthetic retained runtimes through the cleanup owner with mocked service and census inputs; native Windows and published-updater observations are deferred in the PR body. No stored-data contract changes.
  • remove P1: Current review triage priority is P2, so this older priority label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Abandoned updater runtimes after an update are a bounded recovery defect; the stalled-exit concern is separately tracked.
  • merge-risk: 🚨 compatibility: The cleanup reaches runtimes from existing pnpm installations and managed-service scratch paths; the member-authored PR records scoped deferral of published-updater and native Windows validation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state classifies this as member-authored, so the external-contributor proof gate does not apply. Doctor flow tests exercise synthetic retained runtimes through the cleanup owner with mocked service and census inputs; native Windows and published-updater observations are deferred in the PR body. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-28T14:31:17.385Z sha ce84fd9 :: blocked before merge. :: [P2] Preserve a pending nonzero exit across the watchdog | [P2] Join removal already in progress before reporting retention
  • reviewed 2026-09-28T15:46:53.686Z sha e40d454 :: blocked before merge. :: [P2] Preserve the pending nonzero exit when the watchdog fires | [P2] Finish an in-flight runtime removal before exiting
  • reviewed 2026-09-28T16:14:14.697Z sha 03e5939 :: blocked before merge. :: [P2] Preserve the pending nonzero exit when the watchdog fires | [P2] Finish an in-flight runtime removal before exiting
  • reviewed 2026-09-28T16:36:02.974Z sha 26b3a53 :: blocked before merge. :: [P2] Preserve a pending nonzero exit over watchdog success | [P2] Finish removal already in progress before forcing exit
  • reviewed 2026-09-28T16:58:17.136Z sha 26b3a53 :: blocked before merge. :: [P2] Preserve a pending nonzero exit over watchdog success | [P2] Finish removal already in progress before forcing exit
  • reviewed 2026-09-28T17:08:23.283Z sha 45a9c90 :: blocked before merge. :: [P2] Preserve a pending nonzero exit over watchdog success | [P2] Finish removal already in progress before forcing exit
  • reviewed 2026-09-28T18:34:05.907Z sha c533a2f :: blocked before merge. :: [P1] Keep SQLite writes joined when the watchdog fires
  • reviewed 2026-09-28T18:57:01.076Z sha a281b9d :: blocked before merge. :: [P1] Keep SQLite writes joined when the watchdog fires

@steipete

Copy link
Copy Markdown
Contributor Author

Blocked by the CI Node-matrix cap, not by a test failure: preflight refuses with "Canonical pull_request Node matrix has 155 jobs, exceeding limit 130". A local run of the changed-node planner (createChangedNodeTestShards) shows each of src/infra/temp-artifact-cleanup.ts (132 rows), src/infra/runtime-worker-generation.ts (132) and src/cli/signal-exit-barrier.ts (131) exceeds the cap on its own, so splitting this PR cannot get under it. Landing it needs a CI-owner decision (raise/bypass the cap for this PR, or a full-suite dispatch) or a narrower redesign that avoids touching those widely imported owners. Leaving it open so the forward-port from release/2026.9.7 c9de04a is not lost.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Sep 28, 2026
Narrow the first directory entry and declare the generator's undefined return so the synthetic opendir iterator matches Dir's AsyncIterator contract under the core test typecheck.
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
…atchdog

A rejected mutation or recovery drain must turn a recorded successful command result into exit 1. Preserve recorded nonzero results and the original result for disposable retained-worker cleanup stalls. Document the distinction and extend the existing real-child exit cases.

PR #160164 follow-up. Before the fix, three new failure cases exited 0 instead of 1; after the fix, all 11 retained-runtime exit cases pass. The regression file took 13.50s wall with --maxWorkers=1. After merging main, the five requested test files pass 79/79 in 99.18s. Core, other, infra, and config-cli typechecks, targeted oxlint, formatting, diff checks, and independent review pass.

The published-driver test file passes 11/11 twice on the original branch and once on main. The reported case takes 7.33s and 6.82s on the branch versus 7.88s on main; its stable finalizer exits naturally without invoking the output watchdog. No PR-specific exit regression reproduced, so no CI-related production or test change was made.
@steipete

Copy link
Copy Markdown
Contributor Author

CI note for run 36427625220 (head 7ca4341): the only failure was src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts > doctor command > runs legacy ... (Test timed out in 30000ms), outside this PR's diff and seen once on main today. Rerunning the failed jobs once under the maintainer flake policy; a recurrence anywhere is treated as a main regression and fixed on main.

@steipete

Copy link
Copy Markdown
Contributor Author

CI note for run 36445210408 (head e40d454): the only failure was test/scripts/run-vitest-bounded.test.ts > bounded Vitest process ownership > prepares the direct E2E reader generation once (expected ['runtime','ai','ai'] to deeply equal ['runtime','ai']), outside this PR's diff and seen once on main today (logged). Rerunning the failed jobs once under the maintainer flake policy; a recurrence anywhere is treated as a main regression and fixed on main.

…f the watchdog

Preserve a pending nonzero exit when the output watchdog records success. Once retained-runtime directory removal starts, keep it joined through success or error; worker and preparation stalls before removal retain the bounded watchdog behavior. Document the installed-updater behavior.

Real-child regressions failed before the fix for pending exit precedence, interrupted removal, and removal error settlement. Validation: 80 tests across retained-runtime exit/runtime, signal-exit-barrier, and one-shot-exit passed with maxWorkers=2 in 72.86s. The 14-case exit file passed with maxWorkers=1 in 15.73s wall. Core, infra-test, and config-cli-test typechecks, targeted oxlint, oxfmt, and git diff --check passed. Independent P2 autoreview was scoped-clean.
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 28, 2026
…ker settlement split

Remove the watchdog finalizer escape, retirement abort/removal flags, immediate warning path, recorded exit-code state, and watchdog-only process tests. Retained SQLite work and runtime removal stay joined through the existing settlement owner. A mandatory broker settlement versus disposable termination split remains a separate follow-up.

Keep Doctor legacy pnpm projection reclamation and service TMP/TEMP/TMPDIR discovery, including Windows casing and drive-relative paths. Main already preserves failed barriers and pending nonzero exits without watchdog state; retain that implementation and cover those outcomes directly in signal-exit-barrier tests. Recovery docs describe the reduced scope.

Validation: 101 tests passed across six files with maxWorkers=2 (101.54 seconds); core typecheck and state-logging, config-cli, services, and other core test typecheck lanes passed; targeted oxlint and oxfmt passed; Madge found zero cycles; git diff --check passed. Signal barrier cost with maxWorkers=1: seven tests passed, 3.28 seconds command wall (1.74 seconds Vitest). Autoreview against the merged main base was scoped-clean at P1. Native Windows and published-driver upgrade proof were not run in this scoped reduction.
@steipete steipete changed the title fix(update): bound retained-runtime exit and reclaim legacy runtimes fix(doctor): reclaim legacy pnpm runtimes and TMP/TEMP service scratch Sep 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 28, 2026
@steipete
steipete merged commit 165fd29 into main Sep 28, 2026
212 of 218 checks passed
@steipete
steipete deleted the fix/r97-forward-16 branch September 28, 2026 20:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor Author

Post-merge published-driver proof: Package Acceptance run 36482095098 on main 165fd29 (contains this PR and #160164/#160170) passed both Docker lanes: published-upgrade-survivor (published [email protected] updater driving the candidate package) and upgrade-survivor; package verification succeeded.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
openclaw#160164)

* fix(update): bound stalled runtime cleanup and reclaim legacy projections

Forward-port retained runtime review corrections from c9de04a. Preserve the recorded watchdog outcome and retained files when workers cannot close, recognize legacy pnpm projections within the same store, and inspect service TMP/TEMP roots without guessing relative paths.

Co-authored-by: Vincent Koc <[email protected]>

* test(doctor): type the bounded projection iterator fixture

Narrow the first directory entry and declare the generator's undefined return so the synthetic opendir iterator matches Dir's AsyncIterator contract under the core test typecheck.

* fix(update): keep failed recovery barriers nonzero after the output watchdog

A rejected mutation or recovery drain must turn a recorded successful command result into exit 1. Preserve recorded nonzero results and the original result for disposable retained-worker cleanup stalls. Document the distinction and extend the existing real-child exit cases.

PR openclaw#160164 follow-up. Before the fix, three new failure cases exited 0 instead of 1; after the fix, all 11 retained-runtime exit cases pass. The regression file took 13.50s wall with --maxWorkers=1. After merging main, the five requested test files pass 79/79 in 99.18s. Core, other, infra, and config-cli typechecks, targeted oxlint, formatting, diff checks, and independent review pass.

The published-driver test file passes 11/11 twice on the original branch and once on main. The reported case takes 7.33s and 6.82s on the branch versus 7.88s on main; its stable finalizer exits naturally without invoking the output watchdog. No PR-specific exit regression reproduced, so no CI-related production or test change was made.

* fix(update): keep nonzero exits and in-flight runtime removal ahead of the watchdog

Preserve a pending nonzero exit when the output watchdog records success. Once retained-runtime directory removal starts, keep it joined through success or error; worker and preparation stalls before removal retain the bounded watchdog behavior. Document the installed-updater behavior.

Real-child regressions failed before the fix for pending exit precedence, interrupted removal, and removal error settlement. Validation: 80 tests across retained-runtime exit/runtime, signal-exit-barrier, and one-shot-exit passed with maxWorkers=2 in 72.86s. The 14-case exit file passed with maxWorkers=1 in 15.73s wall. Core, infra-test, and config-cli-test typechecks, targeted oxlint, oxfmt, and git diff --check passed. Independent P2 autoreview was scoped-clean.

* refactor(update): drop the retained-runtime exit watchdog pending broker settlement split

Remove the watchdog finalizer escape, retirement abort/removal flags, immediate warning path, recorded exit-code state, and watchdog-only process tests. Retained SQLite work and runtime removal stay joined through the existing settlement owner. A mandatory broker settlement versus disposable termination split remains a separate follow-up.

Keep Doctor legacy pnpm projection reclamation and service TMP/TEMP/TMPDIR discovery, including Windows casing and drive-relative paths. Main already preserves failed barriers and pending nonzero exits without watchdog state; retain that implementation and cover those outcomes directly in signal-exit-barrier tests. Recovery docs describe the reduced scope.

Validation: 101 tests passed across six files with maxWorkers=2 (101.54 seconds); core typecheck and state-logging, config-cli, services, and other core test typecheck lanes passed; targeted oxlint and oxfmt passed; Madge found zero cycles; git diff --check passed. Signal barrier cost with maxWorkers=1: seven tests passed, 3.28 seconds command wall (1.74 seconds Vitest). Autoreview against the merged main base was scoped-clean at P1. Native Windows and published-driver upgrade proof were not run in this scoped reduction.

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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