Skip to content

Commit 2fe948b

Browse files
committed
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.
1 parent 82344b5 commit 2fe948b

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎src/commands/doctor/shared/automatic-startup-config-repair.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ describe("automatic startup config repair", () => {
129129
).toBe(false);
130130
});
131131

132+
it("admits a config whose only migration is plugin-owned", () => {
133+
// Regression: the pre-bootstrap trust check must reach plugin doctor contracts
134+
// (here the bundled Active Memory retired-QMD removal), not only core migrations.
135+
const snapshot = invalidSnapshot({
136+
config: {
137+
plugins: { entries: { "active-memory": { config: { qmd: { enabled: true } } } } },
138+
} as OpenClawConfig,
139+
issuePaths: ["plugins.entries.active-memory.config.qmd"],
140+
});
141+
142+
const resolved = resolveStartupConfigSnapshot(snapshot);
143+
144+
expect(resolved?.valid).toBe(true);
145+
expect(resolved?.sourceConfig.plugins?.entries?.["active-memory"]?.config).toEqual({});
146+
});
147+
132148
it("previews repairable snapshots without touching the shared state database", async () => {
133149
// Backup discovery and gateway pre-bootstrap resolve before state-database admission;
134150
// a broken store (here: a directory at the canonical path) must not break the preview.

‎src/commands/doctor/shared/automatic-startup-config-repair.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,23 @@ function planStartupConfigRepairPreview(
107107
return buildStartupConfigRepairPlan(snapshot, config, changes);
108108
}
109109

110+
/**
111+
* Repairable-snapshot trust check for callers that run before startup state admission
112+
* (gateway pre-bootstrap selection, backup discovery). The full planner covers
113+
* plugin-contract migrations but reads the installed-plugin registry from the shared
114+
* state database; when that store is unreachable, fall back to the state-free preview
115+
* so core-key repairs stay reachable and everything else keeps today's fail-closed
116+
* refusal. The preflight committer and canonical-write matcher stay authoritative.
117+
*/
110118
export function resolveStartupConfigSnapshot(snapshot: ConfigFileSnapshot) {
111-
return snapshot.valid ? snapshot : planStartupConfigRepairPreview(snapshot)?.snapshot;
119+
if (snapshot.valid) {
120+
return snapshot;
121+
}
122+
try {
123+
return planStartupConfigRepair(snapshot)?.snapshot;
124+
} catch {
125+
return planStartupConfigRepairPreview(snapshot)?.snapshot;
126+
}
112127
}
113128

114129
/** Matches only the canonical writer result for a previously admitted startup repair. */

0 commit comments

Comments
 (0)