Skip to content

Commit aaa7dd3

Browse files
authored
fix(doctor): reject incomplete exec approvals migration (#135454)
Check canonical approvals readiness after migration contributions and before managed maintenance can restart the Gateway. Preserve legacy bytes and existing policy while reporting incomplete repair as an error. Fixes #135437.
1 parent 28164d0 commit aaa7dd3

4 files changed

Lines changed: 211 additions & 130 deletions

File tree

‎docs/cli/doctor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Doctor reports interrupted auth-profile archive recovery even when no new migrat
283283

284284
For malformed legacy `exec-approvals.json`, Doctor preserves the original bytes and reports the first validation problem, for example `agents entry #2.allowlist[1].lastUsedAt: expected a finite number`. Agent entries are numbered from 1 in JavaScript `Object.keys` order; allowlist indices start at 0. This can differ from JSON text order, especially for numeric keys. To locate entry #2 locally, use `Object.keys(JSON.parse(raw).agents)[1]`, where `raw` is the file contents. Diagnostics omit agent keys and policy values, and migration receipts contain no diagnostic detail. JSON syntax and invalid UTF-8 receive separate reasons.
285285

286-
Repair the preserved file locally, then rerun `openclaw doctor --fix` with the same `OPENCLAW_STATE_DIR` setting (leave it unset if it was unset before). Exec approvals remain blocked until migration succeeds. Do not delete the file or broaden its policy to bypass validation.
286+
Repair the preserved file locally, then rerun `openclaw doctor --fix` with the same `OPENCLAW_STATE_DIR` setting (leave it unset if it was unset before). Exec approvals remain blocked until migration succeeds. Explicit repair exits nonzero while the legacy file or an interrupted `.doctor-importing` claim remains, before restarting any Gateway stopped for that repair. Do not delete the file or broaden its policy to bypass validation.
287287

288288
Agent database schema upgrades are reported with the database path and the observed before and after versions, independently of media rewrites. The media persistence message appears only when transcript sessions or trajectory rows were rewritten and includes both counts. A run that does both reports both; an unchanged rerun reports neither.
289289

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { vi } from "vitest";
2+
import type { OpenClawConfig } from "../config/types.openclaw.js";
3+
import type { DoctorHealthFlowContext } from "./doctor-health-contributions.js";
4+
5+
const mocks = vi.hoisted(() => ({
6+
outro: vi.fn(),
7+
config: vi.fn<() => OpenClawConfig>(),
8+
runContributions: vi.fn<(ctx: DoctorHealthFlowContext) => Promise<void>>(),
9+
writeUpdatePostInstallDoctorResult: vi.fn(),
10+
service: vi.fn(),
11+
packageRoot: vi.fn<() => string | undefined>(),
12+
restartedHealthy: true,
13+
emulateNativeInstall: true,
14+
servicePlatform: undefined as NodeJS.Platform | undefined,
15+
taskDefinitelyStopped: vi.fn(() => true),
16+
startupFallbackRuntime: vi.fn<() => Promise<{ status: string } | null>>(async () => null),
17+
}));
18+
19+
vi.mock("@clack/prompts", () => ({
20+
intro: vi.fn(),
21+
note: vi.fn(),
22+
outro: mocks.outro,
23+
}));
24+
25+
vi.mock("../commands/doctor-prompter.js", () => ({
26+
createDoctorPrompter: () => ({}),
27+
}));
28+
29+
vi.mock("../infra/openclaw-root.js", async (importOriginal) => ({
30+
...(await importOriginal<typeof import("../infra/openclaw-root.js")>()),
31+
resolveOpenClawPackageRoot: async () => mocks.packageRoot(),
32+
}));
33+
34+
vi.mock("../daemon/service.js", async (importOriginal) => ({
35+
...(await importOriginal<typeof import("../daemon/service.js")>()),
36+
resolveGatewayService: () => mocks.service(),
37+
}));
38+
39+
vi.mock("../config/paths.js", async (importOriginal) => {
40+
const actual = await importOriginal<typeof import("../config/paths.js")>();
41+
return {
42+
...actual,
43+
// Native-manager cases use isolated storage; runtime-only coverage retains
44+
// the real install-identity policy instead of adopting the host service.
45+
isDefaultInstallIdentity: (env: NodeJS.ProcessEnv) =>
46+
mocks.emulateNativeInstall || actual.isDefaultInstallIdentity(env),
47+
};
48+
});
49+
50+
vi.mock("../daemon/schtasks-runtime.js", async (importOriginal) => ({
51+
...(await importOriginal<typeof import("../daemon/schtasks-runtime.js")>()),
52+
isScheduledTaskDefinitelyNotRunning: mocks.taskDefinitelyStopped,
53+
readWindowsStartupFallbackRuntimeForUpdate: mocks.startupFallbackRuntime,
54+
}));
55+
56+
vi.mock("../cli/update-cli/update-command-service-maintenance.js", async (importOriginal) => {
57+
const actual =
58+
await importOriginal<
59+
typeof import("../cli/update-cli/update-command-service-maintenance.js")
60+
>();
61+
return {
62+
...actual,
63+
maybeStopManagedServiceBeforeMutableUpdate: async (
64+
params: Parameters<typeof actual.maybeStopManagedServiceBeforeMutableUpdate>[0],
65+
) => {
66+
// Emulate the native manager only; workspace and SQLite identities must
67+
// retain the host filesystem's case semantics during real migration.
68+
const platform = mocks.servicePlatform
69+
? vi.spyOn(process, "platform", "get").mockReturnValue(mocks.servicePlatform)
70+
: undefined;
71+
try {
72+
return await actual.maybeStopManagedServiceBeforeMutableUpdate(params);
73+
} finally {
74+
platform?.mockRestore();
75+
}
76+
},
77+
};
78+
});
79+
80+
vi.mock("../cli/update-cli/update-command-service-plan.js", async (importOriginal) => ({
81+
...(await importOriginal<typeof import("../cli/update-cli/update-command-service-plan.js")>()),
82+
// The fixture owns an in-memory manager; native machine profile policy is
83+
// covered at the updater boundary and must not select a host service here.
84+
assertGatewayServiceManagementAllowedForUpdate: () => undefined,
85+
resolveGatewayServiceManagementBlockMessageForUpdate: () => undefined,
86+
}));
87+
88+
vi.mock("../cli/daemon-cli/restart-health.js", async (importOriginal) => ({
89+
...(await importOriginal<typeof import("../cli/daemon-cli/restart-health.js")>()),
90+
waitForGatewayHealthyRestart: async () => ({ healthy: mocks.restartedHealthy }),
91+
renderRestartDiagnostics: () => ["synthetic readiness failure"],
92+
}));
93+
94+
vi.mock("../commands/doctor-update.js", () => ({
95+
maybeOfferUpdateBeforeDoctor: async () => ({ handled: false }),
96+
}));
97+
98+
vi.mock("../commands/doctor-ui.js", () => ({
99+
maybeRepairUiProtocolFreshness: async () => undefined,
100+
}));
101+
102+
vi.mock("../commands/doctor-install.js", () => ({
103+
noteSourceInstallIssues: () => undefined,
104+
}));
105+
106+
vi.mock("../commands/doctor/shared/plugin-runtime-symlinks.js", () => ({
107+
noteStalePluginRuntimeSymlinks: async () => undefined,
108+
}));
109+
110+
vi.mock("../commands/doctor-platform-notes.js", () => ({
111+
noteStartupOptimizationHints: () => undefined,
112+
}));
113+
114+
vi.mock("../commands/doctor-config-flow.js", () => ({
115+
loadAndMaybeMigrateDoctorConfig: async () => ({ cfg: mocks.config(), shouldWriteConfig: true }),
116+
}));
117+
118+
vi.mock("../config/config.js", async (importOriginal) => ({
119+
...(await importOriginal<typeof import("../config/config.js")>()),
120+
CONFIG_PATH: "/tmp/openclaw.json",
121+
}));
122+
123+
vi.mock("../infra/update-doctor-result.js", () => ({
124+
UPDATE_POST_INSTALL_DOCTOR_ADVISORY_EXIT_CODE: 86,
125+
UPDATE_POST_INSTALL_DOCTOR_RESULT_PATH_ENV: "OPENCLAW_UPDATE_POST_INSTALL_DOCTOR_RESULT_PATH",
126+
writeUpdatePostInstallDoctorResult: mocks.writeUpdatePostInstallDoctorResult,
127+
}));
128+
129+
vi.mock("./doctor-health-contributions.js", () => ({
130+
runDoctorHealthContributions: mocks.runContributions,
131+
}));
132+
133+
export { mocks };

0 commit comments

Comments
 (0)