Repository navigation
refactor: record which doctor --fix steps have work before the Gateway stop can become conditional - #206152
Conversation
Each Doctor maintenance step now reports a read-only pending decision (work, none or undecidable) to the startup trace. Steps without an owner check default to work. The legacy state move, state schema migration and SQLite NOCOW rewrite use their existing predicates. Every step still runs and the Gateway is still stopped on every --fix. The post-check store rewrites and runtime cleanup move to a sibling module unchanged, keeping doctor-health.ts under its line cap.
|
🦞👀 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 records conservative pending-work decisions for Doctor maintenance steps while preserving existing repairs and Gateway shutdown behavior. Example: Run openclaw doctor --fix with OPENCLAW_GATEWAY_STARTUP_TRACE=1 on a btrfs host without lsattr.
Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides useful groundwork for reducing Doctor outages, and inspection found no introduced correctness or security defect. Reviewed head: Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDoctor coordinates offline state repairs and Gateway restoration; the added checks consume existing path metadata, schema-preflight results, and NOCOW inspection results and emit startup-trace diagnostics. flowchart TD
A[Doctor CLI] --> B[Maintenance custody and Gateway stop]
B --> C[Existing repair steps]
C --> D[Pending work checks]
D --> E[Startup trace]
C --> F[Existing repairs and cleanup]
F --> G[Gateway restoration]
Technical reviewBest possible solution: Retain this conservative instrumentation stage and defer conditional Gateway shutdown until the remaining repair owners can reliably identify pending work. Do we have a high-confidence way to reproduce the issue? This is staged instrumentation rather than a bug fix; the supplied base and head CLI logs demonstrate the diagnostic difference. Is this the best way to solve the issue? Reusing the startup trace and existing owner predicates is a focused approach, and preserving unconditional repairs avoids silently dropping maintenance before detection is complete. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bf298a53334a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +152, Tests +165. Total +317 across 12 files. Added test files: 1. 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. Review metrics
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, 3:34 PM ET / 20:34 UTC. |
|
Merged via squash.
|
) Each Doctor maintenance step now reports a read-only pending decision (work, none or undecidable) to the startup trace. Steps without an owner check default to work. The legacy state move, state schema migration and SQLite NOCOW rewrite use their existing predicates. Every step still runs and the Gateway is still stopped on every --fix. The post-check store rewrites and runtime cleanup move to a sibling module unchanged, keeping doctor-health.ts under its line cap.
Related: #204775
What Problem This Solves
Every
openclaw doctor --fixstops a running Gateway before it knows whether any repair has work, and at 4 GiB of state that stop lasts about 40 to 45 seconds. Skipping the stop safely needs each repair step to answer "is there work?" without writing. No step can answer that today, and nothing records which steps would say "no".This is step 1 of the six-step plan in the #204775 design comment: give every step that answer and trace it. Nothing changes in what Doctor does.
User Impact
None visible.
doctor --fixstill stops the Gateway, runs every step and restores it, as before. WithOPENCLAW_GATEWAY_STARTUP_TRACE=1the trace now has onedoctor.pending.<step>line per step withpending=work|none|undecidableandcheck=owner|default. The next PRs use these lines to see which steps still lack a check.Why This Change Was Made
doctor-maintenance-pending.ts. A step's check returnswork,noneorundecidable. A step without a check counts as work, and anundecidableanswer or a thrown error counts as work too. A check must not write, must not open a store in a mode that can create or modify files, and must not copy a database.pendingon the contribution contract), external config, maintenance-ready, boot lifecycle, NOCOW, SQLite reclamation, retained runtimes and service definition repair.resolvePendingLegacyStateDirMigrationPaths(lstat only);pendingMigrations(no IO); the step's own gate now calls the same check, so the trace cannot drift from the gate;inspectDoctorSqliteNoCowresult. A failed inspection (for example, nolsattr) isundecidable. Before this change that case was indistinguishable from "nothing to do".needsOpenClawStateDatabaseSchemaRepaircopies the database under an update capture and runs an integrity check, and the repair also changes file modes on every run. These are listed for steps 3 to 5.measureGatewayBootstrapStep). No new stored field, config option, CLI flag or schema.doctor-health.tswas at its 700-line cap. The post-check NOCOW, reclamation and retained-runtime block moved unchanged intodoctor-health-maintenance-steps.ts. The contribution timing moved intomeasureDoctorContributionin the contribution utilities, so that file keeps its cap too.Update behavior
There is no update-path change. A published updater that runs Doctor on this build runs the same steps in the same order. The only difference is extra trace lines when the trace variable is set.
Evidence
Real cell, Linux, systemd user Gateway, npm install, 4 GiB agent database with 1 MiB/s of writes,
/readyzprobed every 250 ms. Base pack ismainat541ebfbbe75. Head pack is this PR's first commit,3366380abca. Both packs use unpublished version numbers. Twoopenclaw doctor --fix --non-interactive --yesruns per cell:--fix--fixNRestarts=0, stop request to stopped 0.3 s, started to ready 6.5 to 7.0 s, exit 0. The difference between runs is host noise: head's second run is faster than base's.doctor.pending.*lines per run:legacy-state-dirandstate-schemaarenone(owner check),sqlite-nocowisundecidable(owner check), and the other 91 arework(default).sqlite-nocowisundecidablebecause the cell's store is on btrfs and its image has nolsattr. Base prints the sameNOCOW check skipped: lsattr is unavailablenote and silently treats it as nothing to do. On such a host a conditional stop must still stop.Recordings are replays of the raw cell logs. Each shows, per run, the systemd PIDs before and after, Doctor's stop and restart lines, the per-step pending lines on head, and the measured outage.
RED/BASE,
541ebfbbe75(no pending trace):red-base-541ebfbbe75.mp4
GREEN/HEAD,
3366380abca:green-head-3366380abca.mp4
Raw trace lines, head, first run (home path shortened)
Raw systemd and outage lines, both cells
Tests
src/commands/doctor-maintenance-pending.test.ts:check=default;noneis the only answer that is not work; a thrown check is tracedundecidableand counts as work. All are asserted on the real trace line on stderr.workwith a legacy root and no current root,noneonce the current root exists. The tree's bytes and mtimes are unchanged in both cases. An unreadable home isundecidable.none. The same database against a newer supported version giveswork. Database family bytes and mtimes are unchanged.nonefails 3 of the 8 cases.src/commands/doctor-sqlite-nocow.test.ts, new case:work, thennoneonce NOCOW is set, thenundecidablewhenlsattris unavailable. The WAL store, its sidecars and the directory keep their bytes, mtimes and inode.6221503cc12, all green:src/flows/doctor-health*.test.ts,src/commands/doctor-maintenance*.test.ts,src/commands/doctor-sqlite-nocow.test.ts,src/flows/doctor-retained-runtime.test.ts(246 passed, 4 skipped; 232 passed, 11 skipped; 99 passed; 3 passed; the skips are existing platform skips). Also green:pnpm tsgo:core,pnpm tsgo:core:test, the line-cap ratchet, the session identity ratchet andgit diff --check./procandfuser). Nothing was removed.$autoreview(Codex route, branch mode againstorigin/main, P0 to P2) returned scoped-clean.Not proven
undecidablepath on a host wherelsattrexists but fails. The unit test covers it with a stubbed tool.3366380abca. The branch later mergedmain(unrelated changes, including fix: remove the updater copies that earlier releases leave behind after an update #206124 in retained-runtime cleanup). The focused suites were rerun on the merged head; the cell was not.