Repository navigation
fix(doctor): keep state repairs running with an externally managed read-only config - #164235
Conversation
Keep writable state repairs enabled for externally managed configuration. Report config edits without writing them or authorizing dependent cleanup, and fail when the persisted config still blocks Gateway startup. Preserve Nix repair restrictions and the state-first migration order. Reported by @JD8855122 in #162259.
|
🦞👀 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. Reviewed October 3, 2026, 6:09 AM ET / 10:09 UTC. ClawSweeper reviewWhat this changesDoctor repairs writable runtime state while reporting externally managed config edits without writing them, and refuses startup when the persisted config still requires repair. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful fix: current main and the latest release still reject repairing Doctor with read-only config. No concrete introduced defect was found, but the stock-image upgrade behavior remains unverified. Priority: P1 Review scores
Verification
How this fits togetherThe official Docker entrypoint runs Doctor before starting the Gateway. Doctor coordinates state migrations and config repairs, and its exit status determines whether container activation continues. flowchart TD
A[Docker activation] --> B[Doctor maintenance]
B --> C[Writable state repairs]
B --> D[Config repair candidate]
D --> E[Report external edits]
E --> F[Validate persisted config]
F -->|Valid| G[Start Gateway]
F -->|Invalid or legacy| H[Exit with repair guidance]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +101, Tests +90, Docs +10. Total +201 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep Doctor as the single repair owner, preserve deployment-owned config bytes, and establish stock-image activation and backup recovery on disposable retained state. Do we have a high-confidence way to reproduce the issue? Yes from source: stock Docker activation invokes repairing Doctor, and current main rejects that invocation when OPENCLAW_CONFIG_READONLY=1. No complete container reproduction was executed during this read-only review. Is this the best way to solve the issue? Yes, the config-write boundary is the narrowest supported repair point; preserving persisted config for later work avoids a second repair orchestrator. Full image-upgrade validation remains necessary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 48ff3d1efde5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…ad-only config (openclaw#164235) The official Docker image's entrypoint runs doctor --fix before the Gateway; with the documented externally managed config mode (OPENCLAW_CONFIG_READONLY=1, read-only mounted config) Doctor refused the whole run because it could not write the config, so a working 2026.9.6 deployment went down on the 2026.9.7 image bump. Doctor now keeps state repairs and migrations running, reports config edits instead of writing them, and fails only when a persisted config change is required for startup; Gateway admission covers both cases. State-first migration (18→19 before config repair) is intentional and documented. Closes openclaw#162259. Thanks @JD8855122 for the report.
Closes #162259
What Problem This Solves
Fixes official Docker image upgrades failing before Gateway startup when
OPENCLAW_CONFIG_READONLY=1protects an externally managed config. Reported by @JD8855122.User Impact
Doctor can repair writable state while leaving externally managed config untouched. It prints a redacted merge patch for external config edits; valid config permits startup with optional repairs pending. Legacy or invalid config that still blocks startup produces a nonzero exit and actionable edits. Existing Nix repair restrictions remain unchanged.
Why This Change Was Made
The image entrypoint correctly runs
doctor --fix --non-interactive, but Doctor previously treated any repair as permission to write config and rejected the entire run. Doctor now handles the external-config outcome at its config-write boundary, restores the persisted config for subsequent work, and preserves the persistence requirement for dependent auth cleanup and cron repairs. The legacy config-copy path also honors immutability. Gateway's existing admission gate already accepts valid read-only config; no Gateway exception or new option is needed.State-first migration is intentional: plugin migration obligations need the current shared SQLite schema before later config work. The reported 18 → 19 advance is readable by the candidate build, rather than database corruption. Older builds cannot safely read the newer authorization semantics, so an image rollback requires the matched, verified pre-upgrade state backup. This change does not alter schema versions or downgrade guards.
Evidence
pnpm test src/flows/doctor-health.readonly-config.test.ts --maxWorkers=1) took 20.43s wall time, with 2.867s and 1.038s for its two cases.node scripts/check-changed.mjspassed, including core typechecking, all 27 test typechecking graphs, core/script lint, and schema/storage/import-cycle/security guards.git diff --checkpassed.Slow pre-existing suites (waived)
test/scripts/pr-worktree-provision.test.tstook 456.576s of test time in the three-file batch. Its cold/warm/sparse transition case hit the existing 120s timeout (128.735s observed); the authorized file-only retry passed all 16 active tests with one existing skip, in 354.162s of test time / 384.29s wrapper wall time. The same case passed in 111.459s. The batch also measured 33.602s for disabled-acceleration seed/checkpoint/cleanup custody and 39.171s for command-scopedsafe.directoryparameter transport. These are unchanged provisioning tests on the loaded host; no timeout, retry configuration, assertion, or skip was changed. A passing retry is recorded as the approved isolation check, not a flake fix.Additional local importer timings:
doctor-config-flow.cron-owners.test.tsaccumulated 136.558s across its cases;managed-handoff-build-config.test.tstook 31.965s, including 30.952s for loading the staged production package runtime without neighboring assets. Batch 1 passed all 266 tests in 1802.49s wall time; roughly 20 minutes were shared build/compiler preparation, not test time.doctor-config-flow.billing-route.test.tsaccumulated 136.459s, including package-swap deferral through run-id (31.228s) and result-channel (35.585s).update-command-fresh-preview.test.tsaccumulated 145.145s. The unchanged July-upgrade composition case indoctor-config-flow.legacy-composition.test.tstook 44.750s. All passed.doctor-health.managed-settlement.test.tsaccumulated 159.399s, including the ready multi-agent settlement case (43.647s).doctor-health.test.tsaccumulated 236.596s, and the unchanged fleet-preflight evidence revalidation case took 31.454s. These also passed under the standing slow-suite waiver.Live bind-mount replay (pending)
The 24 mock-image entrypoint tests and the Doctor/Gateway admission regression cover the changed path. A live read-only bind-mount replay remains pending. From a checkout of this PR head, set
PROOF_STATE_DIRto an absolute path containing a disposable, container-writable copy of retained state andPROOF_CONFIG_PATHto an absolute path containing its external config. Then run:Use a valid config with an optional repair, such as a custom
tools.exec.safeBinsentry lacking its scaffold profile. Expected: Doctor reports the external edit, leaves the bind-mounted config unchanged, repairs writable state, and the Gateway starts. A startup-required legacy config edit should instead produce the exact edit and a nonzero exit. Stop the disposable container with Ctrl-C after inspecting the result. Hosted CI is pending; the completed validation above is local or earlier isolated test proof.