Skip to content

Commit 2aa4430

Browse files
committed
fix: resolve unanswered auth and provider issues
1 parent 897bdcc commit 2aa4430

42 files changed

Lines changed: 523 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Unanswered issue resolution: #239, #240, #242, #246, #253, #257
2+
3+
## Outcome
4+
5+
- #239: a Codex OAuth 409 now cancels the abandoned server flow and retries once.
6+
- #240: Codex, OAuth, and API-key pools support display-only aliases through GUI, API, and CLI.
7+
- #242: GitHub Copilot device codes are structured, prominent, copyable, and no longer hidden by an automatic foreground browser launch.
8+
- #246: adaptive Anthropic thinking receives effort-sized total-token headroom and `max_tokens` is preserved as an incomplete response.
9+
- #253: subscription-mode Claude launches no longer claim host-managed authentication without a host token.
10+
- #257: freshly initialized configs carry the current OpenAI tier version, so an older immutable migration backup cannot block startup. Bare OpenAI model ids still intentionally fail closed when no canonical OpenAI provider is enabled.
11+
12+
[Decision Log]
13+
- 목적과 의도: Reproduce and resolve every unanswered report against current `dev`, while preserving existing routing and credential-security invariants.
14+
- 기존 구현 및 제약 조건: OAuth and API-key pools use different stores; Codex accounts use config plus a separate credential ledger. Browser APIs cannot promise a background tab. The OpenAI migration backup is intentionally immutable.
15+
- 검토한 주요 대안: Overwrite old migration backups; auto-open device verification and rely on users switching windows; use aliases as lookup keys; expose a manual-only OAuth recovery button.
16+
- 선택한 방식: Mark new configs as current instead of weakening backup immutability; suppress automatic device-flow navigation and expose the code structurally; persist aliases only as optional display metadata; automatically cancel and retry one stale Codex login.
17+
- 다른 대안 대신 이 방식을 선택한 이유: It fixes the reported dead ends without changing credential identity, account ids, active selection, routing, or backup evidence.
18+
- 장점, 단점 및 영향: Existing data remains backward compatible and aliases may duplicate safely. Copilot login now needs an intentional link click, but the code stays visible and no browser focus theft occurs. The native/main Codex App slot remains non-renamable because it has no OpenCodex-owned persisted account row.
19+
20+
## Verification
21+
22+
- Focused adapter, bridge, Claude env, OpenAI migration, OAuth store, Codex API, provider key API, CLI account, Copilot OAuth, and workspace auth tests.
23+
- Repository TypeScript typecheck, GUI i18n lint, privacy scan, and full test suite before push.

‎gui/src/components/AddCodexAccountModal.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default function AddCodexAccountModal({
101101
setError("");
102102
try {
103103
const accountId = reauthAccountId ?? requestedId?.trim() ?? "";
104-
const resp = await fetch(`${apiBase}/api/codex-auth/login`, {
104+
const requestLogin = () => fetch(`${apiBase}/api/codex-auth/login`, {
105105
signal: controller.signal,
106106
method: "POST",
107107
headers: { "Content-Type": "application/json" },
@@ -111,11 +111,25 @@ export default function AddCodexAccountModal({
111111
: (accountId ? { id: accountId } : {}),
112112
),
113113
});
114-
const data = await resp.json() as { url?: string; flowId?: string; error?: string; status?: string };
114+
let resp = await requestLogin();
115+
let data = await resp.json() as { url?: string; flowId?: string; error?: string; status?: string };
115116
if (!aliveRef.current) return;
116117
if (resp.status === 409) {
117-
setError(t("codexAuth.oauthAlreadyInProgress"));
118-
return;
118+
// A newly mounted modal has no flow id for an abandoned server-side login.
119+
// Cancel that scratch flow and retry once so interruption never leaves the
120+
// account pool permanently stuck behind "already in progress".
121+
await fetch(`${apiBase}/api/codex-auth/login/cancel`, {
122+
method: "POST",
123+
headers: { "Content-Type": "application/json" },
124+
body: "{}",
125+
});
126+
if (!aliveRef.current || controller.signal.aborted) return;
127+
resp = await requestLogin();
128+
data = await resp.json() as typeof data;
129+
if (resp.status === 409) {
130+
setError(t("codexAuth.oauthAlreadyInProgress"));
131+
return;
132+
}
119133
}
120134
if (data.url) {
121135
flowRef.current = data.flowId ?? null;

‎gui/src/components/CodexAccountPool.tsx‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { ReactNode } from "react";
99
import type { CodexAccountModeState } from "../codex-multi-state";
1010

1111
export interface CodexAccountEntry {
12-
id: string; email: string; plan?: string; isMain: boolean;
12+
id: string; alias?: string; email: string; plan?: string; isMain: boolean;
1313
hasCredential: boolean; quota: AccountQuota | null;
1414
needsReauth?: boolean;
1515
}
@@ -147,6 +147,24 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
147147
}
148148
};
149149

150+
const editAlias = async (account: CodexAccountEntry) => {
151+
const entered = window.prompt(t("prov.aliasPrompt"), account.alias ?? "");
152+
if (entered === null) return;
153+
const response = await fetch(`${apiBase}/api/codex-auth/accounts/alias`, {
154+
method: "PUT",
155+
headers: { "Content-Type": "application/json" },
156+
body: JSON.stringify({ id: account.id, alias: entered.trim() }),
157+
});
158+
if (!response.ok) {
159+
setToastError(true);
160+
setToast(t("prov.aliasSaveFailed"));
161+
return;
162+
}
163+
await load();
164+
setToastError(false);
165+
setToast(t("prov.aliasSaved"));
166+
};
167+
150168
const remove = async (id: string) => {
151169
const label = accounts.find(account => account.id === id)?.email ?? t("pws.accountOrdinal", { count: "1" });
152170
if (!window.confirm(t("codexAuth.removeConfirm", { id: label }))) return;
@@ -320,7 +338,7 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
320338
<div key={a.id} className={`card ${isNext(a.id) ? "card-active" : ""}`} style={{ marginBottom: 8 }}>
321339
<div className="card-head">
322340
<span className={`dot ${a.needsReauth ? "dot-amber" : isNext(a.id) ? "dot-blue" : "dot-muted"}`} />
323-
<strong>{a.email}</strong>
341+
<strong>{a.alias ?? a.email}</strong>
324342
<span className="card-badges">
325343
{a.plan && <span className="badge badge-green">{a.plan}</span>}
326344
<TicketBadge t={t} account={a} onClick={() => openResetPopup(a)} />
@@ -341,6 +359,9 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
341359
{t("codexAuth.reauthenticate")}
342360
</button>
343361
)}
362+
<button type="button" className="btn btn-ghost btn-sm" onClick={() => void editAlias(a)}>
363+
{t("prov.editAlias")}
364+
</button>
344365
<button
345366
className="btn-icon btn-icon-danger card-right"
346367
aria-label={`${t("common.remove")} — ${a.email}`}
@@ -350,6 +371,7 @@ export default function CodexAccountPool({ apiBase, accountModeState = null, ban
350371
<IconX width={14} />
351372
</button>
352373
</div>
374+
<div className="card-sub">{a.email}{a.plan ? ` · ${a.plan}` : ""} · {t("prov.accountId")}: {a.id}</div>
353375
{a.needsReauth
354376
? <div className="card-sub faint">{t("codexAuth.tokenExpired")}</div>
355377
: <QuotaBars quota={a.quota} plan={a.plan} threshold={autoThreshold} t={t} />}

‎gui/src/components/provider-workspace/ProviderAuthPanel.tsx‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default function ProviderAuthPanel({
3131
const [addingKey, setAddingKey] = useState(false);
3232
const [newKey, setNewKey] = useState("");
3333
const [keyBusy, setKeyBusy] = useState(false);
34+
const [deviceCodeCopied, setDeviceCodeCopied] = useState(false);
3435

3536
const surface = providerAuthSurface({ ...item, hasApiKey: item.hasApiKey || keys.length > 0 });
3637
const isOauth = surface === "oauth-accounts";
@@ -97,6 +98,18 @@ export default function ProviderAuthPanel({
9798
<span className="pwi-spin-inline" aria-hidden="true" />
9899
<div className="pwi-auth-wait-copy">
99100
<div className="pwi-auth-wait-title">{t("prov.waitingBrowser")}</div>
101+
{hintForThis.deviceCode && (
102+
<div className="pwi-device-code-wrap">
103+
<span>{t("prov.deviceCode")}</span>
104+
<code className="pwi-device-code">{hintForThis.deviceCode}</code>
105+
<button type="button" className="btn btn-primary btn-sm" onClick={() => {
106+
navigator.clipboard.writeText(hintForThis.deviceCode ?? "").then(() => {
107+
setDeviceCodeCopied(true);
108+
setTimeout(() => setDeviceCodeCopied(false), 2500);
109+
}).catch(() => {});
110+
}}>{deviceCodeCopied ? t("prov.codeCopied") : t("prov.copyCode")}</button>
111+
</div>
112+
)}
100113
{hintForThis.url && (
101114
<a href={hintForThis.url} target="_blank" rel="noreferrer" className="pwi-auth-open-link">
102115
<IconExternal style={{ width: 13, height: 13 }} /> {t("prov.didntOpen")}
@@ -139,7 +152,10 @@ export default function ProviderAuthPanel({
139152
aria-label={`${label}${account.active ? ` — ${t("pws.accountCurrent")}` : ""}`}
140153
disabled={Boolean(account.needsReauth || (switchingAccountId && !switching))}>
141154
<span className={`pwi-auth-dot ${account.needsReauth ? "pwi-auth-dot--warn" : account.active ? "pwi-auth-dot--ok" : "pwi-auth-dot--off"}`} aria-hidden="true" />
142-
<span className="pwi-auth-row-label">{label}</span>
155+
<span className="pwi-auth-row-copy">
156+
<span className="pwi-auth-row-label">{label}</span>
157+
<span className="pwi-auth-row-secondary">{[account.email, `${t("prov.accountId")}: ${account.id}`].filter(Boolean).join(" · ")}</span>
158+
</span>
143159
{account.needsReauth && <span className="badge badge-amber">{t("pws.reauth")}</span>}
144160
{account.active && <span className="badge badge-primary">{t("prov.accountActive")}</span>}
145161
{switching && <span className="badge badge-muted">{t("pws.accountSwitching")}</span>}
@@ -154,6 +170,10 @@ export default function ProviderAuthPanel({
154170
{t("pws.reauthenticate")}
155171
</button>
156172
)}
173+
<button type="button" className="btn btn-ghost btn-sm"
174+
onClick={() => void authHandlers.onEditAlias(item.name, "oauth", account.id, account.alias)}>
175+
{t("prov.editAlias")}
176+
</button>
157177
<button type="button" className="btn btn-ghost btn-sm pwi-auth-row-remove"
158178
aria-label={`${t("common.remove")} — ${label}`}
159179
title={`${t("common.remove")} — ${label}`}
@@ -188,9 +208,16 @@ export default function ProviderAuthPanel({
188208
onClick={() => void authHandlers.onSwitchApiKey(item.name, entry)}
189209
disabled={entry.active}>
190210
<span className={`pwi-auth-dot ${entry.active ? "pwi-auth-dot--ok" : "pwi-auth-dot--off"}`} aria-hidden="true" />
191-
<code className="pwi-auth-row-label">{entry.masked}</code>
211+
<span className="pwi-auth-row-copy">
212+
<span className="pwi-auth-row-label">{entry.label ?? entry.masked}</span>
213+
{entry.label && <code className="pwi-auth-row-secondary">{entry.masked} · {t("prov.accountId")}: {entry.id}</code>}
214+
</span>
192215
{entry.active && <span className="badge badge-primary">{t("prov.accountActive")}</span>}
193216
</button>
217+
<button type="button" className="btn btn-ghost btn-sm"
218+
onClick={() => void authHandlers.onEditAlias(item.name, "api-key", entry.id, entry.label)}>
219+
{t("prov.editAlias")}
220+
</button>
194221
<button type="button" className="btn btn-ghost btn-sm pwi-auth-row-remove"
195222
aria-label={`${t("common.remove")} — ${entry.label ?? entry.masked}`}
196223
title={`${t("common.remove")} — ${entry.label ?? entry.masked}`}

‎gui/src/components/provider-workspace/types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface ProviderModelUsageRow {
3939
// Auth types consumed by ProviderAuthPanel (WP091).
4040
export type OAuthAccountRow = {
4141
id: string;
42+
alias?: string;
4243
email?: string;
4344
active: boolean;
4445
needsReauth?: boolean;
@@ -55,6 +56,7 @@ export type LoginHint = {
5556
provider: string;
5657
url?: string;
5758
instructions?: string;
59+
deviceCode?: string;
5860
};
5961

6062
export type AccountLoadState = "idle" | "loading" | "ready" | "error";
@@ -70,6 +72,7 @@ export interface ProviderAuthHandlers {
7072
onAddApiKey: (provider: string, key: string) => Promise<boolean>;
7173
onSwitchApiKey: (provider: string, entry: ApiKeyRow) => void | Promise<void>;
7274
onRemoveApiKey: (provider: string, entry: ApiKeyRow) => void | Promise<void>;
75+
onEditAlias: (provider: string, type: "oauth" | "api-key", id: string, current?: string) => void | Promise<void>;
7376
}
7477

7578
export type ProviderUpdatePatch = {

‎gui/src/i18n/de.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ export const de = {
127127
"prov.didntOpen": "Hat sich nicht geöffnet? Hier klicken",
128128
"prov.copyLink": "Link kopieren",
129129
"prov.linkCopied": "Kopiert",
130+
"prov.deviceCode": "Gerätecode",
131+
"prov.copyCode": "Code kopieren",
132+
"prov.codeCopied": "Code kopiert",
133+
"prov.editAlias": "Alias bearbeiten",
134+
"prov.aliasPrompt": "Anzeigename (leer lassen zum Entfernen)",
135+
"prov.aliasSaved": "Alias gespeichert",
136+
"prov.aliasSaveFailed": "Alias konnte nicht gespeichert werden",
137+
"prov.accountId": "ID",
130138
"prov.pasteRedirect": "Redirect-URL oder Code einfügen",
131139
"prov.pasteRedirectHint": "Zeigt der Browser einen localhost-Fehler, kopiere die vollständige URL aus der Adressleiste und füge sie hier ein (oder den Autorisierungscode).",
132140
"prov.pasteSubmit": "Senden",

‎gui/src/i18n/en.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ export const en = {
138138
"prov.didntOpen": "Didn't open? Click here",
139139
"prov.copyLink": "Copy link",
140140
"prov.linkCopied": "Copied",
141+
"prov.deviceCode": "Device code",
142+
"prov.copyCode": "Copy code",
143+
"prov.codeCopied": "Code copied",
144+
"prov.editAlias": "Edit alias",
145+
"prov.aliasPrompt": "Display name (leave empty to clear)",
146+
"prov.aliasSaved": "Alias saved",
147+
"prov.aliasSaveFailed": "Could not save alias",
148+
"prov.accountId": "ID",
141149
"prov.pasteRedirect": "Paste redirect URL or code",
142150
"prov.pasteRedirectHint": "If the browser shows a localhost error, copy the full URL from its address bar and paste it here (or paste the authorization code).",
143151
"prov.pasteSubmit": "Submit",

‎gui/src/i18n/ko.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ export const ko: Record<TKey, string> = {
133133
"prov.didntOpen": "안 열렸나요? 여기를 클릭하세요",
134134
"prov.copyLink": "링크 복사",
135135
"prov.linkCopied": "복사됨",
136+
"prov.deviceCode": "기기 인증 코드",
137+
"prov.copyCode": "코드 복사",
138+
"prov.codeCopied": "코드 복사됨",
139+
"prov.editAlias": "별칭 편집",
140+
"prov.aliasPrompt": "표시 이름 (비우면 삭제)",
141+
"prov.aliasSaved": "별칭이 저장되었습니다",
142+
"prov.aliasSaveFailed": "별칭을 저장하지 못했습니다",
143+
"prov.accountId": "ID",
136144
"prov.pasteRedirect": "리다이렉트 URL 또는 코드 붙여넣기",
137145
"prov.pasteRedirectHint": "브라우저에 localhost 오류가 표시되면, 주소창의 전체 URL을 복사해 여기에 붙여넣으세요(또는 인증 코드 붙여넣기).",
138146
"prov.pasteSubmit": "제출",

‎gui/src/i18n/ru.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ export const ru: Record<TKey, string> = {
138138
"prov.didntOpen": "Не открылось? Нажмите здесь",
139139
"prov.copyLink": "Копировать ссылку",
140140
"prov.linkCopied": "Скопировано",
141+
"prov.deviceCode": "Код устройства",
142+
"prov.copyCode": "Копировать код",
143+
"prov.codeCopied": "Код скопирован",
144+
"prov.editAlias": "Изменить псевдоним",
145+
"prov.aliasPrompt": "Отображаемое имя (оставьте пустым для удаления)",
146+
"prov.aliasSaved": "Псевдоним сохранен",
147+
"prov.aliasSaveFailed": "Не удалось сохранить псевдоним",
148+
"prov.accountId": "ID",
141149
"prov.pasteRedirect": "Вставьте URL перенаправления или код",
142150
"prov.pasteRedirectHint": "Если браузер показывает ошибку localhost, скопируйте полный URL из его адресной строки и вставьте сюда (или вставьте код авторизации).",
143151
"prov.pasteSubmit": "Отправить",

‎gui/src/i18n/zh.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ export const zh: Record<TKey, string> = {
133133
"prov.didntOpen": "没有打开?点击这里",
134134
"prov.copyLink": "复制链接",
135135
"prov.linkCopied": "已复制",
136+
"prov.deviceCode": "设备验证码",
137+
"prov.copyCode": "复制验证码",
138+
"prov.codeCopied": "验证码已复制",
139+
"prov.editAlias": "编辑别名",
140+
"prov.aliasPrompt": "显示名称(留空以清除)",
141+
"prov.aliasSaved": "别名已保存",
142+
"prov.aliasSaveFailed": "无法保存别名",
143+
"prov.accountId": "ID",
136144
"prov.pasteRedirect": "粘贴重定向 URL 或授权码",
137145
"prov.pasteRedirectHint": "如果浏览器显示 localhost 错误,请复制地址栏中的完整 URL 并粘贴到此处(或粘贴授权码)。",
138146
"prov.pasteSubmit": "提交",

0 commit comments

Comments
 (0)