Repository navigation
feat(gateway): auto-apply safe doctor config migrations at startup - #132135
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 8:39 PM ET / August 29, 2026, 00:39 UTC. ClawSweeper reviewWhat this changesThe PR lets Gateway startup apply Doctor’s deterministic legacy-key migrations to eligible single-file configurations after full validation, preserving a backup before booting. Merge readinessKeep open for maintainer review: this deliberately changes the upgrade contract from refusing an invalid legacy config to automatically rewriting eligible configurations at Gateway startup. The implementation has no supported blocking defect in the reviewed head, but that compatibility policy requires an explicit maintainer choice. Priority: P1 Review scores
Verification
How this fits togetherGateway startup first prepares a trusted configuration snapshot, then Doctor preflight performs state/config migration before the service starts. This PR makes a fully validated legacy-key migration an allowed preflight write while retaining fail-closed exclusions for includes, Nix, newer configs, deferred plugin validation, and remaining errors. flowchart LR
A[Existing configuration] --> B[Gateway pre-bootstrap]
B --> C[Doctor preflight]
C --> D[Legacy migration plan]
D --> E[Full config and plugin validation]
E --> F[Backup-preserving config write]
F --> G[Gateway ready]
Decision needed
Why: This is an intentional compatibility and operator-experience policy change, not a mechanical defect fix; the supplied context does not include an independently verifiable maintainer decision beyond the PR’s assertion. Before merge
Agent review detailsSecurityNone. PR surfaceSource +65, Tests +206, Docs +18. Total +289 across 21 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one Doctor-owned migration planner and land it only if maintainers endorse automatic rewriting for the documented eligible-config subset, with exact-head CI completing successfully. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: pinned main limits startup repair to two paths, while the new planner transforms additional legacy keys such as Is this the best way to solve the issue? Yes technically: reusing the Doctor migration owner, validating the full result, and deleting the narrower predecessor is the cleanest implementation shape; maintainer approval is still required for the new startup-write policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cb5d89bfaf47. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
c55ed1d to
557dbfc
Compare
e36232f to
d88ebe1
Compare
|
Addressed the ClawSweeper P1 (plugin-only migrations unreachable from the pre-bootstrap trust check) in dd0f6e10ffa85503867cb6e1f531c59a5cfdbedc: Rank-up move ("isolated bootstrap-to-preflight proof for a plugin-only migration"): partially applied. The new unit regression proves the trust check admits a config whose only repair is the bundled Active Memory retired-QMD contract and returns the plugin-migrated snapshot; the guarded config write for plugin migrations goes through the same preflight commit path proven by the existing core-key integration tests (lease, retired-locator ordering, checkpoint reread, canonical-writer drift matcher). A full bootstrap→preflight e2e with a plugin-only fixture is noted as follow-up rather than blocking this landing. |
Gateway startup now runs the same deterministic, prompt-free legacy config-key migrations as "openclaw doctor --fix" when an otherwise invalid single-file config can be fully migrated, instead of refusing readiness with a doctor hint. The write happens under the existing startup migration lease, after state migrations consume retired locators, only when the complete result validates including plugins, and keeps the previous config in the .bak ring. Configs using $include, Nix mode, newer-version configs, update-in-progress runs, and configs that stay invalid keep the current fail-closed refusal. This replaces the narrow two-key stable-upgrade repair with the full migration set (which subsumes it), so headless service gateways just work across upgrades instead of stopping on retired config keys.
resolveStartupConfigSnapshot serves gateway pre-bootstrap selection and backup discovery, which run before state-database admission. The full planner resolves plugin doctor contracts through the installed-plugin registry, which opens the shared SQLite store — a broken store (or backup's pre-validation guarantee) must not break those callers. The preview tier now applies only state-free migrations with raw validation; the preflight committer and canonical-write matcher stay authoritative.
…nments CI unit shards and unbuilt checkouts have no dist/build-info.json, so the checkpoint layer fails open by design and the startup-repair checkpoint assertions could never hold there. Wrap the real module with a pinned build identity so recording and needs-checks stay meaningful.
The pre-bootstrap trust check admitted only state-free core migrations, so a config whose sole repair belongs to a plugin doctor contract was refused before the plugin-aware preflight could migrate it. The resolver now runs the full planner first and falls back to the state-free preview only when the installed-plugin registry store is unreachable, keeping backup discovery and broken-store startups fail-closed.
dd0f6e1 to
2fe948b
Compare
|
Merged via squash.
|
…penclaw#132135) * feat(gateway): auto-apply safe doctor config migrations at startup Gateway startup now runs the same deterministic, prompt-free legacy config-key migrations as "openclaw doctor --fix" when an otherwise invalid single-file config can be fully migrated, instead of refusing readiness with a doctor hint. The write happens under the existing startup migration lease, after state migrations consume retired locators, only when the complete result validates including plugins, and keeps the previous config in the .bak ring. Configs using $include, Nix mode, newer-version configs, update-in-progress runs, and configs that stay invalid keep the current fail-closed refusal. This replaces the narrow two-key stable-upgrade repair with the full migration set (which subsumes it), so headless service gateways just work across upgrades instead of stopping on retired config keys. * fix(doctor): keep startup repair preview off the shared state database resolveStartupConfigSnapshot serves gateway pre-bootstrap selection and backup discovery, which run before state-database admission. The full planner resolves plugin doctor contracts through the installed-plugin registry, which opens the shared SQLite store — a broken store (or backup's pre-validation guarantee) must not break those callers. The preview tier now applies only state-free migrations with raw validation; the preflight committer and canonical-write matcher stay authoritative. * test(doctor): avoid shadowing the path module in repair fixtures * test(doctor): pin checkpoint build provenance for unbuilt test environments CI unit shards and unbuilt checkouts have no dist/build-info.json, so the checkpoint layer fails open by design and the startup-repair checkpoint assertions could never hold there. Wrap the real module with a pinned build identity so recording and needs-checks stay meaningful. * fix(doctor): reach plugin-owned migrations from the startup trust check The pre-bootstrap trust check admitted only state-free core migrations, so a config whose sole repair belongs to a plugin doctor contract was refused before the plugin-aware preflight could migrate it. The resolver now runs the full planner first and falls back to the state-free preview only when the installed-plugin registry store is unreachable, keeping backup discovery and broken-store startups fail-closed.
What Problem This Solves
Resolves a problem where upgrading OpenClaw could leave the Gateway unable to start: a config containing retired legacy keys (for example
session.idleMinutes) failed strict validation, and startup refused readiness withRun "openclaw doctor --fix" to repair, then retry.For headless service installs (launchd/systemd) nobody sees that hint — the gateway simply stays down until an operator SSHes in and runs doctor by hand. This is the worst bug class for the out-of-box path: an upgrade that silently turns into an outage.Why This Change Was Made
Gateway startup already runs a full doctor preflight under the startup migration lease (state migrations, cron store repair, plugin host-link repair, plugin convergence). The one thing it refused to do was rewrite
openclaw.json— except for a deliberately narrow repair that unset exactly two keys authored by stable 2026.7.1-2 (automatic-upgrade-config-repair.ts, whose comment warned that widening it "would turn Gateway startup into a general doctor repair"). This PR makes that product decision deliberately (maintainer-requested): the narrow repair is generalized intoautomatic-startup-config-repair.ts, which applies the full deterministic, prompt-free legacy config migration set — the same pure transformopenclaw doctor --fixuses (applyLegacyDoctorMigrations), which subsumes the old two-key case.Fail-closed conditions preserved:
$includeconfigs, Nix mode, configs written by a newer OpenClaw, and update-in-progress runs (plugin validation deferred) still refuse.cron.storebefore the config write removes them), guarded by a fresh-disk-read drift check immediately before commit, and the previous config lands in the 5-slot.bakring.isStartupConfigRepairResult); anything else refuses startup.Legacy session-store import, SQLite schema migrations requiring doctor, and service repairs intentionally stay doctor-owned.
User Impact
After an upgrade, gateways with migratable legacy config keys now start normally — including non-interactive service startups — logging the applied migrations as a "Doctor changes" panel. Operators no longer need to run
openclaw doctor --fixfor deterministic config-key migrations. Docs updated on 8 pages that stated the old "startup never rewrites config" contract.Evidence
Pre-fix baseline (shipped 2026.8.1, isolated state dir, config with
session.idleMinutes):Patched build, same config (live run, isolated
OPENCLAW_STATE_DIR, own port):session.reset.idleMinutes, stampedmeta.lastTouchedVersion); original preserved byte-identical inopenclaw.json.bak.[gateway] ready(checkpoint hit).definitelyNotAKey): still exits 78 with the doctor hint, file byte-identical, no.bakcreated..bak.pnpm check:changedgreen; regression tests fail on pre-fix code.