Skip to content

Commit ae14816

Browse files
authored
fix(doctor): stop prompting a guaranteed no-op and surface the real migration error (#123164)
Two doctor auth-repair UX defects: 1. When only unreferenced legacy Codex OAuth sidecar files remain (no stores with active profiles), doctor prompted 'Migrate legacy Codex OAuth credentials now?' on every interactive run even though the repair loop never touches unreferenced sidecars — answering yes changed nothing, forever. Gate the confirm prompt on actionable stores; unreferenced sidecars stay informational warnings. 2. The shared legacy oauth.json migration failure warning discarded the underlying error (SQLite unreadable, lock contention, source changed), leaving the user with no cause and no next step while the gateway stays blocked. Append the cause like the sibling per-candidate handler does.
1 parent e391505 commit ae14816

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,12 @@ describe("maybeMigrateAuthProfileJsonStoresToSqlite", () => {
495495
env: state.env,
496496
});
497497

498-
expect(result.warnings).toContain(
499-
"Failed to migrate shared legacy OAuth credentials; the source was left in place.",
500-
);
498+
// The warning must carry the underlying cause so the user can act on it.
499+
expect(result.warnings).toEqual([
500+
expect.stringMatching(
501+
/^Failed to migrate shared legacy OAuth credentials; the source was left in place: .+/,
502+
),
503+
]);
501504
expect(fs.existsSync(oauthPath)).toBe(true);
502505
expectNoMigratedArchive(oauthPath);
503506
expect(readPersistedAuthProfileStoreRaw(state.agentDir())).toEqual(unreadableStore);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,9 @@ export async function maybeMigrateAuthProfileJsonStoresToSqlite(params: {
13801380
} else if (hasLegacyOAuth) {
13811381
try {
13821382
migrateLegacyOAuthFile({ oauthPath, env, now, result });
1383-
} catch {
1383+
} catch (err) {
13841384
result.warnings.push(
1385-
`Failed to migrate shared legacy OAuth credentials; the source was left in place.`,
1385+
`Failed to migrate shared legacy OAuth credentials; the source was left in place: ${String(err)}`,
13861386
);
13871387
}
13881388
}

‎src/commands/doctor-auth-oauth-sidecar.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,25 @@ describe("maybeRepairLegacyOAuthSidecarProfiles", () => {
347347
expect(fs.existsSync(sidecarPath)).toBe(true);
348348
});
349349

350+
it("does not prompt when only unreferenced sidecars remain (guaranteed no-op)", async () => {
351+
const state = await makeTestState();
352+
await state.writeJson(
353+
path.join("credentials", "auth-profiles", "cccccccccccccccccccccccccccccccc.json"),
354+
{
355+
version: 1,
356+
profileId: "openai-codex:orphan",
357+
provider: "openai-codex",
358+
access: "orphaned-access-token",
359+
refresh: "orphaned-refresh-token",
360+
},
361+
);
362+
363+
const prompter = makePrompter(true);
364+
await maybeRepairLegacyOAuthSidecarProfiles({ cfg: {}, prompter });
365+
366+
expect(prompter.confirmAutoFix).not.toHaveBeenCalled();
367+
});
368+
350369
it.runIf(process.platform !== "win32")(
351370
"scans symlinked state agents before treating sidecars as unreferenced",
352371
async () => {

‎src/commands/doctor-auth-oauth-sidecar.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,16 @@ export async function maybeRepairLegacyOAuthSidecarProfiles(params: {
239239
);
240240
}
241241

242-
const shouldRepair = await params.prompter.confirmAutoFix({
243-
message: "Migrate legacy Codex OAuth credentials now?",
244-
initialValue: true,
245-
});
246-
if (!shouldRepair) {
247-
return result;
242+
// Unreferenced sidecars alone are informational: the store loop below never
243+
// touches them, so prompting would confirm a guaranteed no-op on every run.
244+
if (stores.length > 0) {
245+
const shouldRepair = await params.prompter.confirmAutoFix({
246+
message: "Migrate legacy Codex OAuth credentials now?",
247+
initialValue: true,
248+
});
249+
if (!shouldRepair) {
250+
return result;
251+
}
248252
}
249253

250254
const migratedSidecarsByRefId = new Map<string, string>();

0 commit comments

Comments
 (0)