Skip to content

Commit e63c0d1

Browse files
committed
fix: select Doctor readiness owners before loading health APIs
1 parent 7c622de commit e63c0d1

8 files changed

Lines changed: 170 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Docs: https://docs.openclaw.ai
3434

3535
### Fixes
3636

37+
- **Update readiness:** select declared health-check owners before loading plugin APIs, preventing unrelated optional Doctor checks from interrupting upgrades while retaining mandatory readiness failures.
38+
3739
- **Apple chat:** make queued messages immediately retryable after session-settings failures, while keeping retries bound to the exact failed attempt.
3840

3941
- **macOS AI setup:** show confirmed capability-review cancellation and retry guidance directly instead of a misleading Gateway failure headline. (#134573)

‎docs/cli/update.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ After plugin convergence, the updated CLI also runs any plugin-owned
291291
post-update readiness checks against an isolated state snapshot. An error keeps
292292
the Gateway stopped and returns the check's remediation before restart; this
293293
gate does not run interactive setup, download models, or change config.
294+
It selects readiness owners before loading their health APIs, so an unrelated
295+
optional Doctor check cannot interrupt the gate. Selected readiness checks
296+
remain mandatory, including when their required artifact is unavailable.
294297
Package-manager updates additionally verify the restarted Gateway reports the
295298
expected package version; git-checkout updates verify gateway health and
296299
service readiness after the rebuild.

‎extensions/memory-core/src/doctor-health.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ describe("managed local embedding setup health check", () => {
7373
it("stays opt-in outside an explicit pre-cutover selection", () => {
7474
expect(captureCheck()).toMatchObject({
7575
defaultEnabled: false,
76-
updateReadiness: "post-plugin",
7776
});
7877
});
7978

‎extensions/memory-core/src/doctor-health.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type MemoryCoreDoctorRegistrationState = Pick<
4040

4141
type MemoryCoreDoctorCheck = HealthCheck & {
4242
readonly defaultEnabled: false;
43-
readonly updateReadiness: "post-plugin";
4443
};
4544

4645
const registrationsByHost = new WeakMap<
@@ -75,7 +74,6 @@ function createManagedLocalEmbeddingSetupCheck(
7574
kind: "plugin",
7675
source: "memory-core",
7776
defaultEnabled: false,
78-
updateReadiness: "post-plugin",
7977
description: "Checks existing semantic indexes for required managed local embedding setup.",
8078
async detect(ctx) {
8179
if (!state.memoryCoreActive) {

‎src/commands/doctor-lint.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ describe("runDoctorLintCli", () => {
720720
const configPath = path.join(stateDir, "openclaw.json");
721721
const config = {
722722
gateway: { mode: "local" },
723+
agents: { defaults: { model: { primary: "openai/gpt-5.5" } } },
723724
memory: { search: { provider: "local", fallback: "none" } },
724725
} satisfies OpenClawConfig;
725726
fs.mkdirSync(stateDir, { recursive: true });

‎src/commands/doctor-lint.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ async function executeDoctorLint(
218218
cwd: ctx.cwd,
219219
env: stateView.pluginMetadataEnv,
220220
runWithPluginStateSnapshot: stateView.runWithPluginStateSnapshot,
221+
updateReadiness: opts.updateReadiness,
221222
});
222223
const registeredExtensionChecks = listExtensionHealthChecksForDoctor([]);
223224
const onlyRegisteredExtensionChecks =

‎src/flows/bundled-health-checks.test.ts‎

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import {
1212
registerBundledHealthChecks,
1313
resolveBundledHealthCheckPluginStateMode,
1414
} from "./bundled-health-checks.js";
15-
import { clearHealthChecksForTest, getHealthCheck } from "./health-check-registry.js";
15+
import { runDoctorLintChecks, selectUpdateReadinessChecks } from "./doctor-lint-flow.js";
16+
import {
17+
clearHealthChecksForTest,
18+
getHealthCheck,
19+
listHealthChecks,
20+
} from "./health-check-registry.js";
1621

1722
const STATE_DEFERRED_CHECK_ID = "memory-core/managed-local-embedding-setup";
1823

@@ -380,6 +385,79 @@ describe("registerBundledHealthChecks", () => {
380385
},
381386
};
382387

388+
it("registers update readiness without loading unselected runtime health APIs", () => {
389+
registerBundledHealthChecks({
390+
cfg: {
391+
...codexConfig,
392+
plugins: {
393+
entries: { policy: { enabled: true }, "cua-computer": { enabled: true } },
394+
},
395+
cloudWorkers: { profiles: { aws: { provider: "crabbox" } } },
396+
},
397+
cwd: workspaceDir,
398+
updateReadiness: "post-plugin",
399+
});
400+
401+
expect(mocks.registerMemoryCoreDoctorChecks).toHaveBeenCalledOnce();
402+
expect(mocks.loadPluginManifestRegistryForPluginRegistry).not.toHaveBeenCalled();
403+
expect(mocks.registerPolicyDoctorChecks).not.toHaveBeenCalled();
404+
expect(mocks.registerCuaDriverDoctorChecks).not.toHaveBeenCalled();
405+
expect(mocks.loadBundledPluginManifestRegistry).not.toHaveBeenCalled();
406+
});
407+
408+
it("retains owner identities and blocking findings across readiness registration", async () => {
409+
const finding = {
410+
checkId: STATE_DEFERRED_CHECK_ID,
411+
severity: "error" as const,
412+
message: "not ready",
413+
};
414+
const check = {
415+
id: STATE_DEFERRED_CHECK_ID,
416+
kind: "plugin" as const,
417+
description: "Readiness owner",
418+
defaultEnabled: false,
419+
detect: vi.fn(async () => [finding]),
420+
};
421+
for (const updateReadiness of [undefined, "post-plugin", "post-plugin"] as const) {
422+
mocks.registerMemoryCoreDoctorChecks.mockImplementationOnce((host) => {
423+
if (host.getHealthCheck(check.id) !== check) {
424+
host.registerHealthCheck(check);
425+
}
426+
});
427+
registerBundledHealthChecks({ cfg: {}, cwd: workspaceDir, updateReadiness });
428+
expect(getHealthCheck(check.id)).toBe(check);
429+
}
430+
const callbacks = mocks.registerMemoryCoreDoctorChecks.mock.calls.map(
431+
([host]) => host.registerHealthCheck,
432+
);
433+
expect(new Set(callbacks).size).toBe(1);
434+
const ctx = {
435+
cfg: {},
436+
mode: "lint" as const,
437+
runtime: { log: vi.fn(), error: vi.fn(), exit: vi.fn() },
438+
};
439+
await expect(runDoctorLintChecks(ctx)).resolves.toMatchObject({ checksRun: 0, findings: [] });
440+
await expect(
441+
runDoctorLintChecks(ctx, {
442+
checks: selectUpdateReadinessChecks(listHealthChecks(), "post-plugin"),
443+
includeAllChecks: true,
444+
}),
445+
).resolves.toMatchObject({ checksRun: 1, findings: [finding] });
446+
});
447+
448+
it("fails when the selected readiness owner cannot load its artifact", () => {
449+
mocks.loadBundledPluginPublicArtifactModuleSync.mockImplementationOnce(() => {
450+
throw new MissingPublicSurfaceError("selected readiness artifact unavailable");
451+
});
452+
expect(() =>
453+
registerBundledHealthChecks({
454+
cfg: codexConfig,
455+
cwd: workspaceDir,
456+
updateReadiness: "post-plugin",
457+
}),
458+
).toThrow("selected readiness artifact unavailable");
459+
});
460+
383461
function codexRecord(
384462
origin: "bundled" | "global",
385463
trustedOfficialInstall?: boolean,

‎src/flows/bundled-health-checks.ts‎

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ type BundledHealthCheckSelection = {
6262

6363
type BundledHealthCheckPluginStateMode = "direct" | "deferred" | "isolated";
6464

65+
type BundledHealthCheckParams = {
66+
cfg: OpenClawConfig;
67+
cwd?: string;
68+
env?: NodeJS.ProcessEnv;
69+
runWithPluginStateSnapshot?: <T>(
70+
run: (pluginMetadataEnv: NodeJS.ProcessEnv) => Promise<T>,
71+
) => Promise<T>;
72+
};
73+
74+
function defineHealthCheckRegistration(
75+
register: (params: BundledHealthCheckParams, registerCheck: typeof registerHealthCheck) => void,
76+
updateReadiness?: "post-plugin",
77+
) {
78+
// Owners retain callback and check identities when refreshing their registration state.
79+
// Declare phase ownership before loading their implementation, then carry it onto each check.
80+
const registerCheck = updateReadiness
81+
? (check: Parameters<typeof registerHealthCheck>[0]) =>
82+
registerHealthCheck(Object.assign(check, { updateReadiness }))
83+
: registerHealthCheck;
84+
return {
85+
updateReadiness,
86+
register: (params: BundledHealthCheckParams) => register(params, registerCheck),
87+
};
88+
}
89+
90+
const HEALTH_CHECK_REGISTRATIONS = [
91+
defineHealthCheckRegistration(registerMemoryCoreHealthChecks, "post-plugin"),
92+
defineHealthCheckRegistration(registerCodexHealthChecks),
93+
defineHealthCheckRegistration(registerPolicyHealthChecks),
94+
defineHealthCheckRegistration(registerCuaHealthChecks),
95+
defineHealthCheckRegistration(registerBundledWorkerProviderHealthChecks),
96+
];
97+
6598
function loadMemoryCoreHealthApi(): BundledHealthApi {
6699
return loadBundledPluginPublicArtifactModuleSync<BundledHealthApi>({
67100
dirName: "memory-core",
@@ -100,18 +133,28 @@ export function resolveBundledHealthCheckPluginStateMode(
100133
}
101134

102135
/** Registers bundled health checks that are explicitly enabled by config and owner policy. */
103-
export function registerBundledHealthChecks(params: {
104-
cfg: OpenClawConfig;
105-
cwd?: string;
106-
env?: NodeJS.ProcessEnv;
107-
runWithPluginStateSnapshot?: <T>(
108-
run: (pluginMetadataEnv: NodeJS.ProcessEnv) => Promise<T>,
109-
) => Promise<T>;
110-
}): void {
136+
export function registerBundledHealthChecks(
137+
params: BundledHealthCheckParams & { updateReadiness?: "post-plugin" },
138+
): void {
139+
for (const registration of HEALTH_CHECK_REGISTRATIONS) {
140+
if (
141+
params.updateReadiness !== undefined &&
142+
registration.updateReadiness !== params.updateReadiness
143+
) {
144+
continue;
145+
}
146+
registration.register(params);
147+
}
148+
}
149+
150+
function registerMemoryCoreHealthChecks(
151+
params: BundledHealthCheckParams,
152+
registerCheck: typeof registerHealthCheck,
153+
): void {
111154
const env = params.env ?? process.env;
112155
loadMemoryCoreHealthApi().registerMemoryCoreDoctorChecks?.({
113156
getHealthCheck,
114-
registerHealthCheck,
157+
registerHealthCheck: registerCheck,
115158
async inspectEmbeddingProviderSetup(providerParams) {
116159
const inspect = async (pluginMetadataEnv: NodeJS.ProcessEnv) => {
117160
const manifestRegistry: PluginManifestRegistry =
@@ -133,6 +176,13 @@ export function registerBundledHealthChecks(params: {
133176
},
134177
memoryCoreActive: isMemoryCoreActive(params.cfg),
135178
});
179+
}
180+
181+
function registerCodexHealthChecks(
182+
params: BundledHealthCheckParams,
183+
registerCheck: typeof registerHealthCheck,
184+
): void {
185+
const env = params.env ?? process.env;
136186
if (shouldRegisterCodexManagedHealth(params.cfg)) {
137187
const registry = loadPluginManifestRegistryForPluginRegistry({
138188
config: params.cfg,
@@ -157,28 +207,43 @@ export function registerBundledHealthChecks(params: {
157207
pluginRoot: owner.rootDir,
158208
artifactBasename: "api.js",
159209
origin: owner.origin === "bundled" ? "bundled" : "global",
160-
}).registerCodexManagedAppServerDoctorChecks({ getHealthCheck, registerHealthCheck });
210+
}).registerCodexManagedAppServerDoctorChecks({
211+
getHealthCheck,
212+
registerHealthCheck: registerCheck,
213+
});
161214
}
162215
}
216+
}
217+
218+
function registerPolicyHealthChecks(
219+
params: BundledHealthCheckParams,
220+
registerCheck: typeof registerHealthCheck,
221+
): void {
163222
if (shouldRegisterPolicyHealth(params)) {
164223
loadBundledPluginPublicArtifactModuleSync<BundledHealthApi>({
165224
dirName: "policy",
166225
artifactBasename: "api.js",
167-
}).registerPolicyDoctorChecks?.({ registerHealthCheck });
226+
}).registerPolicyDoctorChecks?.({ registerHealthCheck: registerCheck });
168227
}
228+
}
229+
230+
function registerCuaHealthChecks(
231+
params: BundledHealthCheckParams,
232+
registerCheck: typeof registerHealthCheck,
233+
): void {
169234
if (shouldRegisterPluginHealth(params.cfg, "cua-computer")) {
170235
loadBundledPluginPublicArtifactModuleSync<BundledHealthApi>({
171236
dirName: "cua-computer",
172237
artifactBasename: "api.js",
173-
}).registerCuaDriverDoctorChecks?.({ registerHealthCheck });
238+
}).registerCuaDriverDoctorChecks?.({ registerHealthCheck: registerCheck });
174239
}
175-
registerBundledWorkerProviderHealthChecks(params, env);
176240
}
177241

178242
function registerBundledWorkerProviderHealthChecks(
179-
params: { cfg: OpenClawConfig; cwd?: string },
180-
env: NodeJS.ProcessEnv,
243+
params: BundledHealthCheckParams,
244+
registerCheck: typeof registerHealthCheck,
181245
): void {
246+
const env = params.env ?? process.env;
182247
const providerIds = collectConfiguredWorkerProviderIds(params.cfg);
183248
if (providerIds.length === 0) {
184249
return;
@@ -191,7 +256,10 @@ function registerBundledWorkerProviderHealthChecks(
191256
loadBundledPluginPublicArtifactModuleFromCandidatesSync<WorkerProviderHealthApi>({
192257
dirName: pluginId,
193258
artifactCandidates: ["doctor-health-api.js"],
194-
})?.registerWorkerProviderDoctorChecks?.({ getHealthCheck, registerHealthCheck });
259+
})?.registerWorkerProviderDoctorChecks?.({
260+
getHealthCheck,
261+
registerHealthCheck: registerCheck,
262+
});
195263
}
196264
}
197265

0 commit comments

Comments
 (0)