Skip to content

Commit fa0f9e7

Browse files
fix(doctor): report interrupted auth archive recovery (#134009)
* fix(doctor): report interrupted auth archive recovery * test(ui): isolate workspace icon recovery fetches * docs(changelog): note Doctor archive recovery outcomes * test(ui): split workspace icon header coverage * fix: authenticate CI checkout and lazy blob fetches * fix: prepare immutable reader history during CI checkout * fix(ci): declare historical reader selector entry point * perf(anthropic): defer auth and catalog runtime imports Keep provider descriptors synchronous without importing credential stores, external auth discovery, or live catalog transport during registration. Load those implementations only when the existing asynchronous setup, doctor, usage, and catalog hooks need them. Expose the existing lightweight API-key descriptor factory through provider-entry while preserving the shipped auth SDK helpers and their synchronous contracts. The unchanged fresh-process registry proof retains its original timeout and verifies scoped failover without global activation. * test: include historical prerequisite in routing expectations * docs(plugins): use public provider auth import in tutorial * fix: restore gateway recovery fixture lint and types Preserve the recovery coverage added in #134165 while using the actual WebSocket dependency and authored SecretRef fixture boundary. Co-authored-by: Shakker <[email protected]> --------- Co-authored-by: Shakker <[email protected]>
1 parent 644470e commit fa0f9e7

5 files changed

Lines changed: 86 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Docs: https://docs.openclaw.ai
7171

7272
### Fixes
7373

74+
- **Doctor recovery notes:** show interrupted auth-profile archive recovery failures and completions even when no further migration runs or another migration is declined. (#134009) Thanks @angeliti999.
7475
- Matrix lifecycle: drain in-flight monitor tasks without deadlocking shared-client retirement, and reject late acquisitions after their owning task closes.
7576
- Provider error handling: reuse prepared or already loaded provider hooks instead of cold-loading plugins during error classification, avoiding long stalls in failure reporting and model fallback.
7677
- **Session settings:** restore merging of concurrent first writes after a startup optimization regressed lock ordering, preserving both global and project settings without adding filesystem side effects to missing-settings reads. Thanks @MrSwagatRathod, @obviyus, and @yetval for the original fix.

‎docs/cli/doctor.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ the container normally.
250250

251251
`openclaw doctor --fix` is the only owner for persistent file-to-SQLite migrations. It validates and claims each recognized source, writes and verifies canonical rows, records a migration receipt, then removes the retired source. Runtime code does not perform lazy imports or fallback reads.
252252

253+
Doctor reports interrupted auth-profile archive recovery even when no new migration remains or you decline another migration. If recovery cannot finish, its warning includes the failure cause and leaves the pending source for recovery; do not delete it to silence the warning.
254+
253255
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.
254256

255257
Device Pair and Active Memory legacy JSON imports check namespace capacity before writing. If the missing entries do not fit, doctor warns and leaves the source unchanged. These imports also verify that source keys and pre-existing destination keys remain in SQLite before reporting completion and archiving the source. A retention warning keeps the source available for inspection and retry; do not delete it to silence the warning, because it may contain state that SQLite did not retain. Resolve the capacity problem before rerunning `openclaw doctor --fix`.

‎src/commands/doctor-auth-flat-profiles.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,12 +1349,6 @@ export async function maybeMigrateAuthProfileJsonStoresToSqlite(params: {
13491349
}
13501350
clearRuntimeAuthProfileStoreSnapshots();
13511351
clearAuthProfileMigrationDiagnostics();
1352-
if (result.changes.length > 0) {
1353-
note(result.changes.map((change) => `- ${change}`).join("\n"), "Doctor changes");
1354-
}
1355-
if (result.warnings.length > 0) {
1356-
note(result.warnings.map((warning) => `- ${warning}`).join("\n"), "Doctor warnings");
1357-
}
13581352
return result;
13591353
}
13601354

‎src/flows/doctor-health-contributions.auth-import-order.test.ts‎

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import { stripVTControlCharacters } from "node:util";
34
import { afterEach, describe, expect, it, vi } from "vitest";
45
import {
56
loadPersistedAuthProfileStore,
67
loadPersistedSharedAuthProfileStore,
78
} from "../agents/auth-profiles/persisted.js";
89
import { clearRuntimeAuthProfileStoreSnapshots } from "../agents/auth-profiles/runtime-snapshots.js";
10+
import {
11+
createAuthProfileMigrationSourceReceipt,
12+
type AuthProfileMigrationSourceReceipt,
13+
} from "../commands/doctor-auth-migration-receipts.js";
914
import type { DoctorPrompter } from "../commands/doctor-prompter.js";
1015
import type { OpenClawConfig } from "../config/types.openclaw.js";
1116
import { closeOpenClawAgentDatabasesForTest } from "../state/openclaw-agent-db.js";
12-
import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js";
17+
import {
18+
closeOpenClawStateDatabaseForTest,
19+
openOpenClawStateDatabase,
20+
} from "../state/openclaw-state-db.js";
1321
import {
1422
createOpenClawTestState,
1523
type OpenClawTestState,
@@ -37,6 +45,11 @@ vi.mock("../commands/doctor-auth.js", () => ({
3745
}));
3846

3947
const states: OpenClawTestState[] = [];
48+
const { recordAuthProfileMigrationImported } = (globalThis as Record<PropertyKey, unknown>)[
49+
Symbol.for("openclaw.authProfileMigrationReceiptsTestApi")
50+
] as {
51+
recordAuthProfileMigrationImported: (receipt: AuthProfileMigrationSourceReceipt) => void;
52+
};
4053

4154
function makePrompter(shouldRepair: boolean): DoctorPrompter {
4255
return {
@@ -138,6 +151,7 @@ function authProfilesContribution() {
138151
}
139152

140153
afterEach(async () => {
154+
vi.restoreAllMocks();
141155
clearRuntimeAuthProfileStoreSnapshots();
142156
closeOpenClawAgentDatabasesForTest();
143157
closeOpenClawStateDatabaseForTest();
@@ -147,6 +161,68 @@ afterEach(async () => {
147161
});
148162

149163
describe("interactive Doctor auth migration", () => {
164+
it.each(["failed", "completed", "declined"] as const)(
165+
"reports interrupted archive recovery when the remaining migration is %s",
166+
async (outcome) => {
167+
const state = await makeState();
168+
const sourcePath = await state.writeText("credentials/oauth.json", "{}\n");
169+
const sourceBytes = fs.readFileSync(sourcePath);
170+
const receipt = createAuthProfileMigrationSourceReceipt({
171+
sourcePath,
172+
sourceBytes,
173+
sourceRecordCount: 0,
174+
targetDatabasePath: path.join(state.agentDir(), "openclaw-agent.sqlite"),
175+
targetTable: "auth_profile_store",
176+
env: state.env,
177+
});
178+
recordAuthProfileMigrationImported(receipt);
179+
if (outcome === "failed") {
180+
// A persisted receipt with an invalid target cannot be safely resumed.
181+
openOpenClawStateDatabase({ env: state.env })
182+
.db.prepare("UPDATE migration_sources SET target_table = ? WHERE source_key = ?")
183+
.run("invalid_target", receipt.sourceKey);
184+
}
185+
const remainingPath = outcome === "declined" ? await writeLegacyCredentialStore(state) : null;
186+
const prompter = makePrompter(false);
187+
const ctx = createDoctorHealthFlowContext({
188+
cfg: {},
189+
prompter,
190+
env: state.env,
191+
configPath: path.join(state.stateDir, "openclaw.json"),
192+
});
193+
const stdout = vi.spyOn(process.stdout, "write").mockReturnValue(true);
194+
195+
await authProfilesContribution().run(ctx);
196+
197+
const output = stripVTControlCharacters(
198+
stdout.mock.calls.map(([chunk]) => String(chunk)).join(""),
199+
)
200+
.replaceAll("│", "")
201+
.replace(/\s+/g, " ");
202+
stdout.mockRestore();
203+
if (outcome === "failed") {
204+
expect(output).toContain("Doctor warnings");
205+
expect(
206+
output.match(/Could not finalize an interrupted auth profile archive/g),
207+
).toHaveLength(1);
208+
expect(output).toContain("invalid pending auth profile migration receipt");
209+
expect(fs.readFileSync(sourcePath)).toEqual(sourceBytes);
210+
expect(fs.existsSync(receipt.archivePath)).toBe(false);
211+
} else {
212+
expect(output).toContain("Doctor changes");
213+
expect(output.match(/Finalized interrupted auth profile archive/g)).toHaveLength(1);
214+
expect(fs.existsSync(sourcePath)).toBe(false);
215+
expect(fs.readFileSync(receipt.archivePath)).toEqual(sourceBytes);
216+
}
217+
if (remainingPath) {
218+
expect(prompter.confirmAutoFix).toHaveBeenCalledOnce();
219+
expect(fs.existsSync(remainingPath)).toBe(true);
220+
} else {
221+
expect(prompter.confirmAutoFix).not.toHaveBeenCalled();
222+
}
223+
},
224+
);
225+
150226
it("commits config credentials and standalone state with one mapping after acceptance", async () => {
151227
const state = await makeState();
152228
const cfg = makeLegacyConfig();

‎src/flows/doctor-health-contributions.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fs from "node:fs";
44
import { isDeepStrictEqual } from "node:util";
55
import { shouldManageGatewayService } from "../commands/doctor-service-repair-policy.js";
6+
import { emitDoctorNotes } from "../commands/doctor/emit-notes.js";
67
import { scrubDoctorErrorMessage } from "./doctor-error-message.js";
78
import { hasActiveGatewayExecCredential } from "./doctor-gateway-exec-credential.js";
89
import {
@@ -136,6 +137,11 @@ async function runAuthProfileHealth(ctx: DoctorHealthFlowContext): Promise<void>
136137
openAICodexAuthProfileIdMap,
137138
...(ctx.env ? { env: ctx.env } : {}),
138139
});
140+
emitDoctorNotes({
141+
note,
142+
changeNotes: authProfileMigration.changes,
143+
warningNotes: authProfileMigration.warnings,
144+
});
139145
if (authProfileMigration.configOwnerMigrationApplied) {
140146
// The candidate is safe only after the migration verifies and archives its source.
141147
ctx.cfg = authConfigCandidate;

0 commit comments

Comments
 (0)