Repository navigation
fix: shorten doctor --fix Gateway downtime by removing old updater folders before the stop - #206185
Conversation
…teway Retained updater runtime cleanup ran inside the doctor --fix Gateway stop. It reads no database, and each runtime's owner record and the process census decide custody, as in the release updater, which already runs it beside a serving Gateway. It now runs before the stop; a failure is reported and no longer blocks the repairs that need the stop. The startup readiness steps that stay inside the stop move unchanged into the maintenance steps module.
…untimes-after-restore
|
🦞👀 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: passed. What this changesThis PR moves abandoned updater-runtime cleanup before Doctor stops the Gateway and makes cleanup failures advisory. Example: Run openclaw doctor --fix with an abandoned 596 MB updater folder.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a useful, focused improvement, and no definite introduced defect was found. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDoctor coordinates Gateway maintenance; the shared retained-runtime owner inspects temporary folders, checks process custody, and removes eligible abandoned artifacts. flowchart TD
A[Doctor repair request] --> B[Retained runtime cleanup]
B --> C[Owner records and process census]
C --> D[Remove or preserve runtime]
D --> E[Gateway maintenance and repairs]
E --> F[Readiness checks and restoration]
Technical reviewBest possible solution: Keep runtime deletion with its existing owner before maintenance while preserving custody checks and advisory failure reporting. Do we have a high-confidence way to reproduce the issue? Current-main ordering establishes that cleanup runs inside maintenance, and supplied base CLI logs show its removal work between stop and restoration; no target code was executed during this review. Is this the best way to solve the issue? Moving the existing filesystem cleanup before the stop addresses unnecessary stopped-window work without introducing a second deletion policy; the readiness extraction preserves its prior ordering. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 47b2cdd86ee6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +46, Tests +6. Total +52 across 9 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 26, 2026, 5:02 PM ET / 22:02 UTC. |
|
Merged via squash.
|
…teway (openclaw#206185) Retained updater runtime cleanup ran inside the doctor --fix Gateway stop. It reads no database, and each runtime's owner record and the process census decide custody, as in the release updater, which already runs it beside a serving Gateway. It now runs before the stop; a failure is reported and no longer blocks the repairs that need the stop. The startup readiness steps that stay inside the stop move unchanged into the maintenance steps module.
…teway (#206185) Retained updater runtime cleanup ran inside the doctor --fix Gateway stop. It reads no database, and each runtime's owner record and the process census decide custody, as in the release updater, which already runs it beside a serving Gateway. It now runs before the stop; a failure is reported and no longer blocks the repairs that need the stop. The startup readiness steps that stay inside the stop move unchanged into the maintenance steps module. (cherry picked from commit 3495c16) Backport adaptation: Call the guarded retained-runtime cleanup before the existing inline Doctor maintenance start, preserve existing readiness sequencing, and omit the separate post-check flow extraction. Co-authored-by: RomneyDa <[email protected]>
…teway (#206185) Retained updater runtime cleanup ran inside the doctor --fix Gateway stop. It reads no database, and each runtime's owner record and the process census decide custody, as in the release updater, which already runs it beside a serving Gateway. It now runs before the stop; a failure is reported and no longer blocks the repairs that need the stop. The startup readiness steps that stay inside the stop move unchanged into the maintenance steps module. (cherry picked from commit 3495c16) Release adaptation: move only standalone Doctor cleanup to the stable flow before beginDoctorMaintenance; keep startup readiness inline and retain updater-owned cleanup for managed update children. Do not import the already-removed maintenance-steps split or change the existing authority grant. Follow-up audit: 43b5b52, 19e9dd6, 218d29f, e2e0974, 52eccde, 18e53d8, 91d4912, fd681ab, c32abfe, 5c81526 and 33ba1b1 cover separate shutdown/readiness, update recovery, work planning, and export concerns; the stable cleanup owner needs none of them. Co-authored-by: RomneyDa <[email protected]>
Related: #204775
What Problem This Solves
Every
openclaw doctor --fixstops a running Gateway, and the stop covered steps that never needed it. One of them is the cleanup of abandoned updater folders (openclaw-update-runtime-*, about 600 MB each). Removing one took 0.8 to 1.1 s inside the stop in our test cell. This is step 2 of the plan in the #204775 design comment: run the steps that do not need the stop while the Gateway serves.User Impact
doctor --fixremoves abandoned updater folders before it stops the Gateway, so the Gateway is down for that much less time. The folders it removes, the ones it keeps and its messages are unchanged. A cleanup failure is reported and no longer blocks the repairs that need the stop. Every--fixstill stops the Gateway.Why This Change Was Made
I checked each step named in the plan against what the stopped window protects (state and agent databases, config the Gateway holds or rewrites, files it writes concurrently):
owner.jsonand the process census decide custody. The release updater (reclaimRetainedUpdateRuntimesinsrc/update/cli.ts) already runs the same pass beside a serving Gateway.Why before the stop and not after the restart: a first version ran the cleanup right after the restart. In two of three runs the census found a process it could not classify (a child the new Gateway starts during startup, such as its SQLite integrity worker) and conservatively kept the folder. The serving Gateway before the stop is in steady state, like the release updater's case.
What the Gateway can do meanwhile: it never runs code from an updater runtime; the census classifies it as a non-updater and treats any process that references the folder as a holder. An update it starts creates a new folder with an owner record naming a live PID, so that folder is kept. Doctor still retires its own idle readers and spawn broker first and keeps any folder one of its own workers loaded code from. A signal lets an in-progress removal finish.
Not changed: the readiness steps that stay in the stop moved unchanged into
doctor-health-maintenance-steps.tssodoctor-health.tsstays under its line cap. The cleanup no longer checks the update requester's write authority, which only governs Doctor's state writes; the release updater runs this pass without it too.Update behavior
No update-path change. A published updater that runs Doctor on this build gets the cleanup before Doctor's maintenance begins. The updater's own runtime has an owner record with its live PID, so it is kept, as before.
Evidence
Linux cell, systemd user Gateway, npm install, 4 GiB agent database with 1 MiB/s of writes,
/readyzprobed every 250 ms. Base pack ismainatd0f76989509, head pack isfe42d651b7d(this PR), both under unpublished version numbers. Each cell runsopenclaw doctor --fix --non-interactive --yesthree times. Before each run the harness plants an abandoned updater folder (owner record of an exited PID, hard-linked copy of the installed package: 47,883 entries, 596 MB) and a look-alike folder without an updater's marks (negative control). Run 3 also plants a second folder whose inner directory is read-only, so its removal fails.Fixture note: the census refuses inside any container it detects, by design. These cells run with a private cgroup namespace and without
/.dockerenv, so the real census runs. No other container shares the cell's volume. A first base cell without that change kept every folder with "Host process visibility cannot be established from this container".cleanup failed: EACCESreported. Every run exits 0 with a new Gateway PID,NRestarts=0, and the Gateway ready.RED/BASE,
d0f76989509(cleanup inside the stop):red-base-d0f76989509.mp4
GREEN/HEAD,
fe42d651b7d(cleanup before the stop):green-head-fe42d651b7d.mp4
Raw lines, base d0f7698 (home path shortened)
Raw lines, head fe42d65 (home path shortened)
Tests
src/flows/doctor-retained-runtime.settlement.test.ts: the complete Doctor flow now asserts the cleanup runs before Doctor takes state custody (no maintenance scope, state owner free, checks not started), that the folder is already gone when the checks run, and that a broker settlement failure is reported while the stopped repairs still run. Red on base: 7 of 7 fail (base runs the cleanup after the checks, under custody). The checks-scope reader case (PID 42421) was removed: that scope does not exist before the stop. The idle read pool and plugin preparation cases now create their workers before the flow, as Doctor's own earlier reads do.src/flows/doctor-health.migration-refusal.test.ts: the ordering case now expects cleanup, then checks, SQLite repairs and restoration. New case: a cleanup failure is reported and maintenance, checks and restoration still run. The cleanup is mocked for this file because the real one scans the host temp directory.src/commands/doctor-maintenance.requester-authority.test.ts: the post-repair drain-and-reenter step now uses SQLite reclamation, the post-repair step that stays in custody, instead of the removed in-custody cleanup.fe42d651b7d:src/commands/doctor-maintenance*.test.ts,src/flows/doctor-health*.test.ts,src/flows/doctor-retained-runtime*.test.ts,src/cli/update-cli/update-command-lifecycle.test.ts,src/update/cli.test.ts,src/infra/temp-artifact-cleanup.test.ts: all green (5 Vitest shards: 635 passed, 13 skipped; the skips are existing platform skips). Also green:pnpm tsgo:core,pnpm tsgo:core:test, the line-cap ratchet, the session identity ratchet,git diff --check.doctor-maintenance.test-support.ts(itscleanupRetainedRuntimesstub went with the method).$autoreview(Codex, branch mode againstorigin/main, P0 to P2) returned scoped-clean.Not proven
--fixor update retries.fe42d651b7d. The branch then mergedmain(unrelated changes, including plugin preparation worker release in fix(plugins): release idle workers after preparing bundled state operations #206172). The settlement, retained-runtime, migration-refusal and requester-authority suites were rerun on the merged head877ca888d77(59 passed); the cells were not.