Repository navigation
fix(doctor): reclaim updater runtimes while a Gateway runs - #191284
Conversation
Every prepared update leaves its retained runtime for the next eligible update or `openclaw doctor --fix`, but both passes refused to reclaim it whenever any Gateway was running. The runtime census counted every OpenClaw-identified process without artifact path evidence as holding every runtime, and a live Gateway always looks like that: its process title erases the script path. Runtimes therefore accumulated with each update. Without a reference to a runtime, an OpenClaw process can only hold it as the updater that created it, and that updater started before mkdtemp created the directory. The census now releases identity-only holders whose native start time is more than 10 s after the runtime's birth (ctime where birth time is unavailable). Processes that reference any retained artifact, unknown custody, and identity-only processes that predate the runtime still block reclamation. Refs #188868
Review found that comparing process start times with the runtime's birth breaks on Linux: process starts are reconstructed against the current wall clock, so a forward clock step can make the creating updater look newer than its runtime. Releasing also dropped resolved artifact evidence when a later OpenClaw preload replaced the holder. An OpenClaw process without artifact evidence can hold a runtime only as the `openclaw update` that created it, so the census now releases such holders only when their command is known and is not `update`: the `openclaw-gateway` process title or a visible subcommand. Title-erased CLIs and visible updates still block, and any resolved artifact path keeps the holder conservative.
|
🦞👀 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. |
|
Codex review: blocked before merge. What this changesAllow abandoned updater runtimes to be reclaimed while identifiable non-updater OpenClaw processes are running. Example: Run openclaw doctor --fix with openclaw-gateway running and an unused /tmp/openclaw-update-runtime-Gate01 directory.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: it addresses a verified current-main cleanup defect with a focused change, and no actionable introduced bug was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherUpdate and Doctor share a cleanup owner that combines runtime markers, maintenance ownership, resource settlement, and process-census evidence before removing disposable runtime directories. flowchart TD
A[Update or Doctor] --> B[Retained runtime cleanup]
B --> C[Marker and ownership checks]
C --> D[Shared process census]
D --> E[Command and artifact evidence]
E --> F[Preserve runtime]
E --> G[Remove abandoned runtime]
Technical reviewBest possible solution: Keep command-aware runtime custody in the existing census while retaining conservative updater, unresolved-preload, and artifact-reference protection. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the false-holder path, and the linked maintainer discussion reports a matching probe; this read-only review executed no target code. Is this the best way to solve the issue? The patch repairs the shared decision used by both Update and Doctor without file-mapping scans, new markers, or another custody store. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 428b02da8fa7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +34, Tests +54, Docs 0. Total +88 across 5 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 2, 2026, 12:00 PM ET / 17:00 UTC. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Merged via squash.
|
…191284) * fix(doctor): reclaim updater runtimes while a Gateway runs Every prepared update leaves its retained runtime for the next eligible update or `openclaw doctor --fix`, but both passes refused to reclaim it whenever any Gateway was running. The runtime census counted every OpenClaw-identified process without artifact path evidence as holding every runtime, and a live Gateway always looks like that: its process title erases the script path. Runtimes therefore accumulated with each update. Without a reference to a runtime, an OpenClaw process can only hold it as the updater that created it, and that updater started before mkdtemp created the directory. The census now releases identity-only holders whose native start time is more than 10 s after the runtime's birth (ctime where birth time is unavailable). Processes that reference any retained artifact, unknown custody, and identity-only processes that predate the runtime still block reclamation. Refs openclaw#188868 * fix(doctor): release runtimes by command, not start time Review found that comparing process start times with the runtime's birth breaks on Linux: process starts are reconstructed against the current wall clock, so a forward clock step can make the creating updater look newer than its runtime. Releasing also dropped resolved artifact evidence when a later OpenClaw preload replaced the holder. An OpenClaw process without artifact evidence can hold a runtime only as the `openclaw update` that created it, so the census now releases such holders only when their command is known and is not `update`: the `openclaw-gateway` process title or a visible subcommand. Title-erased CLIs and visible updates still block, and any resolved artifact path keeps the holder conservative. * test(doctor): keep a title-erased CLI as the later runtime holder * fix(doctor): keep runtime holders whose preloads are unresolved * fix(doctor): release runtimes from OpenClaw worker entrypoints * fix(doctor): release runtimes only from Gateway processes * fix(update): let the update reclaim runtimes past its respawn launcher
Related: #188868 ## What Problem This Solves Fixes: every Windows update leaves an `openclaw-update-runtime-*` directory behind, and neither the next update nor `openclaw doctor --fix` ever removes it. Each one costs disk on every update. ## User Impact On Windows, `openclaw doctor --fix` now reclaims abandoned updater runtimes. A later `openclaw update` also reclaims earlier runtimes while the Gateway keeps running, as #191284 made possible on Linux and macOS. Runtimes that a live process could still use are kept, and Doctor names that process's PID. There is no config, schema, or migration change. ## Why This Change Was Made The runtime census read processes through `readProcessGroupMembers`, which throws `Exact process command census is unavailable on win32` before it classifies anything. Every Windows cleanup therefore kept every runtime. The update handoff path already uses the native Windows census, so runtime mode now uses it too: - **Readable command lines** are classified exactly as they are on Linux and macOS. - **Rows owned by another account** do not hold runtimes. That includes positively foreign owners and rows that deny even limited query (no identity at all). This matches the existing treatment of unreadable foreign argv on macOS. The handoff census already relies on the same rule: every same-account process grants limited query at any integrity level. - **Same-account rows with a hidden command line** are classified by their image, the same way Linux treats unrelated processes with an unreadable cwd. Non-runtime images do not block; Node.js, Bun, OpenClaw, or unknown images keep runtimes and produce a warning. - **An exited ancestor ends the inspector's ancestry walk**, because Windows never reparents. Before, it aborted the census. - **The Gateway's Windows job anchor** (`service-child-windows-job-anchor`) joins the spawn broker as a non-creator when it has no artifact evidence. Native runs showed that only this process kept blocking in-update reclamation while the Gateway ran. Only the Gateway task supervisor and the TUI's local shell launch it. Accepted edge, named in code: a same-account process whose own DACL denies limited query counts as foreign. OpenClaw never launches one, and update locks and Doctor maintenance already exclude a concurrent updater. The `backup create` scratch-cleanup `EPERM` that the Windows manual-procedure lane reported came from the 2026.10.4 CLI. That rename-onto-reservation bug was fixed by #176836, which shipped from 2026.10.6. Published 2026.10.9 and this build both completed `backup create --verify` five times on native Windows with no `EPERM` and no leftover scratch, so this PR does not change backup code. ## Evidence - **Regression test** in `src/infra/openclaw-process-census.windows.test.ts`. On base it fails with the exact production message: `Could not inspect OpenClaw processes: Error: Exact process command census is unavailable on win32.` It passes with the fix. The case covers path-scoped holders, foreign and denied rows, opaque system and Node images, cwd evidence, the installed Gateway, and its job anchor. Without the anchor exemption, the anchor PID blocks the case. - **Focused suites:** the census suites (runtime, Windows, missing-command, native) and the Doctor retained-runtime suites pass, 119 tests. `openclaw-process-census.native.test.ts` ("finds a real non-Node process holding retained handoff paths") fails on this macOS host only in the combined run, and identically on unmodified base. It is the macOS `incomplete` census path, which this PR does not touch. - **Lint and types:** oxfmt, oxlint `--type-aware` and `tsgo:core` are clean. - **Native Windows (Crabbox AWS m7i.large, Windows Server, OpenSSH, Node 24.22.1, Scheduled Task Gateway).** All hops below ran from published 2026.10.9: | Step | Driver | Result | |---|---|---| | 10.9 → base build | 10.9 | runtime retained: `Exact process command census is unavailable on win32` | | `doctor --fix` on base | base | runtime retained, same error | | base → fix (2026.10.10) | base | both runtimes retained | | fix → fix relabelled 2026.10.11 | fix | census runs; in-update passes are blocked only by live update processes and one Gateway-owned PID | | `doctor --fix` on 2026.10.11 | fix | **removed all three runtimes**; Gateway restarted, `/readyz` ready | | Native census against a fresh runtime with the live Gateway | fix vs. this head | fix: `pids: [1104]` (1104 = `service-child-windows-job-anchor.js`, child of the Gateway); this head: `pids: []` | | The same, plus a same-account worker running from the runtime | this head | `pids: [<worker>]`, still blocks | Every hop ended with the Gateway healthy (`ready`, `coreReady`). The "First restoration refusal observed … databases changed after snapshot capture" line on the second hop also appears on main, is unrelated to this change, and is tracked separately. Gap: the Crabbox Windows image runs every token at High integrity, so a medium-integrity (UAC) inspector was not exercised natively; the policy for rows it cannot read is covered by the unit case above. Production code +58/−11 (one owner file); tests +58/−9; docs +7/−1. Review: `$autoreview` is scoped-clean on the final branch. An independent Codex review of the first head raised the access-denied rule (P1). That rule is kept and named as the accepted edge above. A second independent pass traced the job anchor's spawners and found nothing.
…92129) Related: openclaw#188868 ## What Problem This Solves Fixes: every Windows update leaves an `openclaw-update-runtime-*` directory behind, and neither the next update nor `openclaw doctor --fix` ever removes it. Each one costs disk on every update. ## User Impact On Windows, `openclaw doctor --fix` now reclaims abandoned updater runtimes. A later `openclaw update` also reclaims earlier runtimes while the Gateway keeps running, as openclaw#191284 made possible on Linux and macOS. Runtimes that a live process could still use are kept, and Doctor names that process's PID. There is no config, schema, or migration change. ## Why This Change Was Made The runtime census read processes through `readProcessGroupMembers`, which throws `Exact process command census is unavailable on win32` before it classifies anything. Every Windows cleanup therefore kept every runtime. The update handoff path already uses the native Windows census, so runtime mode now uses it too: - **Readable command lines** are classified exactly as they are on Linux and macOS. - **Rows owned by another account** do not hold runtimes. That includes positively foreign owners and rows that deny even limited query (no identity at all). This matches the existing treatment of unreadable foreign argv on macOS. The handoff census already relies on the same rule: every same-account process grants limited query at any integrity level. - **Same-account rows with a hidden command line** are classified by their image, the same way Linux treats unrelated processes with an unreadable cwd. Non-runtime images do not block; Node.js, Bun, OpenClaw, or unknown images keep runtimes and produce a warning. - **An exited ancestor ends the inspector's ancestry walk**, because Windows never reparents. Before, it aborted the census. - **The Gateway's Windows job anchor** (`service-child-windows-job-anchor`) joins the spawn broker as a non-creator when it has no artifact evidence. Native runs showed that only this process kept blocking in-update reclamation while the Gateway ran. Only the Gateway task supervisor and the TUI's local shell launch it. Accepted edge, named in code: a same-account process whose own DACL denies limited query counts as foreign. OpenClaw never launches one, and update locks and Doctor maintenance already exclude a concurrent updater. The `backup create` scratch-cleanup `EPERM` that the Windows manual-procedure lane reported came from the 2026.10.4 CLI. That rename-onto-reservation bug was fixed by openclaw#176836, which shipped from 2026.10.6. Published 2026.10.9 and this build both completed `backup create --verify` five times on native Windows with no `EPERM` and no leftover scratch, so this PR does not change backup code. ## Evidence - **Regression test** in `src/infra/openclaw-process-census.windows.test.ts`. On base it fails with the exact production message: `Could not inspect OpenClaw processes: Error: Exact process command census is unavailable on win32.` It passes with the fix. The case covers path-scoped holders, foreign and denied rows, opaque system and Node images, cwd evidence, the installed Gateway, and its job anchor. Without the anchor exemption, the anchor PID blocks the case. - **Focused suites:** the census suites (runtime, Windows, missing-command, native) and the Doctor retained-runtime suites pass, 119 tests. `openclaw-process-census.native.test.ts` ("finds a real non-Node process holding retained handoff paths") fails on this macOS host only in the combined run, and identically on unmodified base. It is the macOS `incomplete` census path, which this PR does not touch. - **Lint and types:** oxfmt, oxlint `--type-aware` and `tsgo:core` are clean. - **Native Windows (Crabbox AWS m7i.large, Windows Server, OpenSSH, Node 24.22.1, Scheduled Task Gateway).** All hops below ran from published 2026.10.9: | Step | Driver | Result | |---|---|---| | 10.9 → base build | 10.9 | runtime retained: `Exact process command census is unavailable on win32` | | `doctor --fix` on base | base | runtime retained, same error | | base → fix (2026.10.10) | base | both runtimes retained | | fix → fix relabelled 2026.10.11 | fix | census runs; in-update passes are blocked only by live update processes and one Gateway-owned PID | | `doctor --fix` on 2026.10.11 | fix | **removed all three runtimes**; Gateway restarted, `/readyz` ready | | Native census against a fresh runtime with the live Gateway | fix vs. this head | fix: `pids: [1104]` (1104 = `service-child-windows-job-anchor.js`, child of the Gateway); this head: `pids: []` | | The same, plus a same-account worker running from the runtime | this head | `pids: [<worker>]`, still blocks | Every hop ended with the Gateway healthy (`ready`, `coreReady`). The "First restoration refusal observed … databases changed after snapshot capture" line on the second hop also appears on main, is unrelated to this change, and is tracked separately. Gap: the Crabbox Windows image runs every token at High integrity, so a medium-integrity (UAC) inspector was not exercised natively; the policy for rows it cannot read is covered by the unit case above. Production code +58/−11 (one owner file); tests +58/−9; docs +7/−1. Review: `$autoreview` is scoped-clean on the final branch. An independent Codex review of the first head raised the access-denied rule (P1). That rule is kept and named as the accepted edge above. A second independent pass traced the job anchor's spawners and found nothing.
…191284) * fix(doctor): reclaim updater runtimes while a Gateway runs Every prepared update leaves its retained runtime for the next eligible update or `openclaw doctor --fix`, but both passes refused to reclaim it whenever any Gateway was running. The runtime census counted every OpenClaw-identified process without artifact path evidence as holding every runtime, and a live Gateway always looks like that: its process title erases the script path. Runtimes therefore accumulated with each update. Without a reference to a runtime, an OpenClaw process can only hold it as the updater that created it, and that updater started before mkdtemp created the directory. The census now releases identity-only holders whose native start time is more than 10 s after the runtime's birth (ctime where birth time is unavailable). Processes that reference any retained artifact, unknown custody, and identity-only processes that predate the runtime still block reclamation. Refs openclaw#188868 * fix(doctor): release runtimes by command, not start time Review found that comparing process start times with the runtime's birth breaks on Linux: process starts are reconstructed against the current wall clock, so a forward clock step can make the creating updater look newer than its runtime. Releasing also dropped resolved artifact evidence when a later OpenClaw preload replaced the holder. An OpenClaw process without artifact evidence can hold a runtime only as the `openclaw update` that created it, so the census now releases such holders only when their command is known and is not `update`: the `openclaw-gateway` process title or a visible subcommand. Title-erased CLIs and visible updates still block, and any resolved artifact path keeps the holder conservative. * test(doctor): keep a title-erased CLI as the later runtime holder * fix(doctor): keep runtime holders whose preloads are unresolved * fix(doctor): release runtimes from OpenClaw worker entrypoints * fix(doctor): release runtimes only from Gateway processes * fix(update): let the update reclaim runtimes past its respawn launcher (cherry picked from commit 7fd2b43) Release adaptation: Retain artifact and unknown custody; release only positive Gateway/broker identity without runtime evidence. Existing updater ancestry contract retained; Windows extension is separate. Co-authored-by: RomneyDa <[email protected]>
Release adaptation: restore the source assertion for the existing Darwin unbounded-environment regression after selecting openclaw#191284. A positively identified Gateway is not a retained runtime without artifact evidence; unknown-custody peers remain retained with their original warnings. No production guards or census policy change. Source policy: 7fd2b43 (openclaw#191284). Regression proof: original assertion fails 1/63; corrected census suites pass 64/64, with focused typecheck, lint, and formatting passing. (cherry picked from commit adeda50) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 2df6fef118b367d777b8b1ffe5fa24844f05eeef)
Related: #188868
What Problem This Solves
Fixes: every
openclaw updateleaves a retained updater runtime (openclaw-update-runtime-*). The next update never reclaims it while the Gateway runs, so runtimes accumulate until someone runsopenclaw doctor --fix.User Impact
User impact: the next
openclaw updatenow removes runtimes left by earlier updates while the Gateway keeps running. Processes that reference a runtime, or that may be the update that created it, still block removal as before.Why This Change Was Made
Each prepared update defers its runtime cleanup to the next eligible update or Doctor pass. Native runs showed that Doctor already reclaims these runtimes:
--fixmaintenance stops a managed Gateway first, and it refuses to run against an unmanaged one. The update's own pre-pass (maintainRetainedUpdateRuntimes, run before it prepares its own runtime) never could. A process-tree capture during a live update found three false holders:openclaw-gateway) erases its script path, and the census treated every OpenClaw process without artifact evidence as holding every runtime.node openclaw updateargv stays visible.The census now:
openclaw-gatewaytitle, a visiblegatewaysubcommand after the CLI's--updaterewrite, or the spawn-broker worker entrypoint. Title-erased CLIs,update,doctor(its git-update path runs the updater in-process), update workers, resolved artifact paths, including symlink aliases, and unresolved preloads all stay holders.updateCLI, exempts its direct parent if that parent is a visibleupdateCLI launcher. A nestedupdateCommandinsideupdate-migrated-finalize.workeris not the update CLI, so its outer updater stays a holder.No marker format change, so runtimes left by shipped updaters are reclaimed too.
Rejected:
Accepted edge case: a Gateway launched by hand from inside an updater's private temporary projection would not be recognized as holding it. No product path starts one there.
Not covered: Windows. The runtime-mode census throws
Exact process command census is unavailable on win32before classification, so Windows updates still keep every runtime. Covering it means routing runtime mode throughreadWindowsProcessCensus(today only the handoff census uses it), with a foreign/access-denied process policy and native Windows proof. That is a separate change.Evidence
Native Crabbox (AWS Linux, systemd user Gateway live throughout). Each lane went published 2026.10.9 → hop 1 to a build → hop 2 to the same commit relabelled 2026.10.10 →
doctor --fix. No other processes ran during the lanes.c108c2ce145: the hop-2 pre-pass kept the hop-1 runtime, held by the Gateway, its spawn broker, and the updater's launcher ("other OpenClaw processes are still running (PIDs: 58378, 58491, 58760, 58830)"). Two runtimes remained after hop 2.d6568d9a55b: the hop-2 pre-pass removed the hop-1 runtime while the Gateway ran. Only the current run's runtime remained, correctly held by its own updater family and then deferred. Both hops exited 0,readyzwas ready, and the package database backup stayed intact.751cf0dd9bfwas the update CLI's respawn launcher (100019 node …/openclaw update, parent of the updating child100033).GatewayStateOwnerContentionError. This is the same on main and this PR, so Doctor was never the failing path.Tests, red on main and green here:
src/infra/openclaw-process-census.test.ts: the Gateway release cases, the conservative holders, and the respawn-launcher exemption, including the nested-worker case.src/flows/doctor-retained-runtime.test.ts: Doctor with a live Gateway reclaims; with a title-erased CLI it retains.Sibling suites pass: census missing-command, windows, native;
update-retained-runtime; doctor settlement; plugin source captures;update-repair-cancellation.pnpm run tsgo:core, type-aware oxlint (core shard), and oxfmt pass.Review:
$autoreview(branch, P2) is scoped-clean. An independent Codex review found two real issues in earlier revisions (Linux clock reconstruction; a resolved alias dropped by a later preload), then two more (Doctor's in-process git update; the--updateroot-flag spelling). All four are fixed, and the final head got NO FINDINGS.Credit
@fuller-stack-dev reported the root cause and first investigated it in #188868.