Skip to content

Commit 9c30c92

Browse files
fix(doctor): surface the resume failure cause for interrupted auth-profile archives (#123459)
maybeMigrateAuthProfileJsonStoresToSqlite discarded the error from resumePendingAuthProfileMigrationArchives entirely, so the warning was always the same generic string regardless of which of 5 distinct causes fired (invalid receipt, target verification failure, lock failure, SQLite failure, corrupt JSON). PR #123164 fixed the identical defect class in the sibling shared-OAuth catch block 20 lines below in this same function, explicitly modeling the fix on the third, already-correct sibling. This was the unaddressed third catch block in that same family.
1 parent 8f22534 commit 9c30c92

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,21 @@ import {
4444
maybeMigrateAuthProfileJsonStoresToSqlite,
4545
maybeRepairOpenAICodexAuthConfig,
4646
} from "./doctor-auth-flat-profiles.js";
47+
import {
48+
createAuthProfileMigrationSourceReceipt,
49+
type AuthProfileMigrationSourceReceipt,
50+
} from "./doctor-auth-migration-receipts.js";
4751
import type { DoctorPrompter } from "./doctor-prompter.js";
4852
import { maybeRepairCodexSessionRoutes } from "./doctor/shared/codex-route-session-repair.js";
4953

54+
type MigrationReceiptTestApi = {
55+
recordAuthProfileMigrationImported: (receipt: AuthProfileMigrationSourceReceipt) => void;
56+
};
57+
58+
const { recordAuthProfileMigrationImported } = (globalThis as Record<PropertyKey, unknown>)[
59+
Symbol.for("openclaw.authProfileMigrationReceiptsTestApi")
60+
] as MigrationReceiptTestApi;
61+
5062
const states: OpenClawTestState[] = [];
5163

5264
function makePrompter(shouldRepair: boolean): DoctorPrompter {
@@ -580,6 +592,38 @@ describe("maybeMigrateAuthProfileJsonStoresToSqlite", () => {
580592
expect(readPersistedAuthProfileStoreRaw(state.agentDir())).toEqual(unreadableStore);
581593
});
582594

595+
it("surfaces the resume failure cause instead of a generic warning", async () => {
596+
const state = await makeTestState();
597+
const sourcePath = await state.writeText(
598+
"credentials/oauth.json",
599+
`${JSON.stringify({ openai: { access: "fake", refresh: "fake", expires: 42 } })}\n`,
600+
);
601+
const receipt = createAuthProfileMigrationSourceReceipt({
602+
sourcePath,
603+
sourceBytes: fs.readFileSync(sourcePath),
604+
sourceRecordCount: 1,
605+
targetDatabasePath: path.join(state.agentDir(), "openclaw-agent.sqlite"),
606+
// An out-of-union target table makes resumePendingAuthProfileMigrationArchives throw
607+
// "invalid pending auth profile migration receipt" — the cheapest way to reproduce one of
608+
// its 5 distinct throw causes without corrupting on-disk state.
609+
targetTable: "bogus_table" as AuthProfileMigrationSourceReceipt["targetTable"],
610+
env: state.env,
611+
});
612+
recordAuthProfileMigrationImported(receipt);
613+
614+
const result = await maybeMigrateAuthProfileJsonStoresToSqlite({
615+
cfg: {},
616+
prompter: makePrompter(true),
617+
env: state.env,
618+
});
619+
620+
expect(result.warnings).toContainEqual(
621+
expect.stringMatching(
622+
/^Could not finalize an interrupted auth profile archive; legacy sources were left for recovery: .*invalid pending auth profile migration receipt.*/,
623+
),
624+
);
625+
});
626+
583627
it.each(["legacy-main", "state-db"] as const)(
584628
"imports legacy JSON auth profiles and state into the %s shared database",
585629
async (location) => {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,8 @@ export async function maybeMigrateAuthProfileJsonStoresToSqlite(params: {
905905
let resumeWarning: string | undefined;
906906
try {
907907
resumedChanges = resumePendingAuthProfileMigrationArchives(env);
908-
} catch {
909-
resumeWarning =
910-
"Could not finalize an interrupted auth profile archive; legacy sources were left for recovery.";
908+
} catch (err) {
909+
resumeWarning = `Could not finalize an interrupted auth profile archive; legacy sources were left for recovery: ${String(err)}`;
911910
}
912911
const candidates = listAuthProfileSqliteMigrationCandidates(params.cfg, env);
913912
const configStore = coerceLegacyConfigAuthProfileStore(params.cfg);

0 commit comments

Comments
 (0)