Skip to content

Commit 84247cd

Browse files
committed
fix(gui): reconcile main account pause sentinel
1 parent ebac7ba commit 84247cd

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎gui/src/components/codex-account-pool-main-card.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function CodexAccountPoolMainCard({
101101
disabled={pauseBusy}
102102
>
103103
{main.paused ? <IconPlay width={14} /> : <IconPause width={14} />}
104-
{pauseUpdatingId === main.id ? t("common.saving") : t(main.paused ? "codexAuth.resume" : "codexAuth.pause")}
104+
{pauseUpdatingId === "__main__" ? t("common.saving") : t(main.paused ? "codexAuth.resume" : "codexAuth.pause")}
105105
</button>
106106
)}
107107
<span className="card-right"><IconLock width={14} /> {t("codexAuth.appLogin")}</span>

‎gui/src/hooks/useCodexAccountPool.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ export function useCodexAccountPool(apiBase: string, enabled = true): CodexAccou
251251
});
252252
if (!response.ok) return { ok: false, reason: "request" } as const;
253253
const result = await response.json() as { activeCodexAccountId?: string | null };
254-
setAccounts(current => current.map(account => account.id === id ? { ...account, paused } : account));
254+
setAccounts(current => current.map(account => (
255+
account.id === id || (id === "__main__" && account.isMain)
256+
? { ...account, paused }
257+
: account
258+
)));
255259
const nextActiveId = result.activeCodexAccountId ?? null;
256260
pendingActiveIdRef.current = { id: nextActiveId };
257261
setActiveId(nextActiveId);

‎gui/tests/codex-account-pool-behaviour.test.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let calls: string[] = [];
2222
let originalFetch: typeof globalThis.fetch;
2323
let accounts: unknown[] = [];
2424
let threshold = 80;
25+
let nextAccountsResponseGate: Promise<void> | null = null;
2526

2627
beforeEach(() => {
2728
previous = Object.fromEntries(globals.map((k) => [k, Reflect.get(globalThis, k)])) as typeof previous;
@@ -36,6 +37,7 @@ beforeEach(() => {
3637

3738
originalFetch = globalThis.fetch;
3839
calls = [];
40+
nextAccountsResponseGate = null;
3941
accounts = [{ id: "a1", email: "account-one", isMain: true, paused: false, hasCredential: true, quota: null }];
4042
Object.defineProperty(globalThis, "fetch", {
4143
configurable: true,
@@ -45,7 +47,8 @@ beforeEach(() => {
4547
if (path === "codex-auth/accounts/pause") {
4648
const body = JSON.parse(String(init?.body)) as { id: string; paused: boolean };
4749
accounts = accounts.map(account => (
48-
typeof account === "object" && account !== null && "id" in account && account.id === body.id
50+
typeof account === "object" && account !== null && "id" in account
51+
&& (account.id === body.id || (body.id === "__main__" && "isMain" in account && account.isMain === true))
4952
? { ...account, paused: body.paused }
5053
: account
5154
));
@@ -63,6 +66,9 @@ beforeEach(() => {
6366
} as unknown as Response;
6467
}
6568
if (path.startsWith("codex-auth/accounts")) {
69+
const gate = nextAccountsResponseGate;
70+
nextAccountsResponseGate = null;
71+
if (gate) await gate;
6672
return { ok: true, json: async () => ({ accounts }) } as unknown as Response;
6773
}
6874
if (path.startsWith("codex-auth/active")) {
@@ -138,6 +144,25 @@ test("pausing an account writes the persisted endpoint and updates shared state"
138144
expect(seen.current!.activeId).toBeNull();
139145
});
140146

147+
test("pausing the main sentinel updates its distinct account row before reload", async () => {
148+
const seen = await mountController();
149+
let releaseReload!: () => void;
150+
nextAccountsResponseGate = new Promise<void>(resolve => { releaseReload = resolve; });
151+
152+
await act(async () => {
153+
expect(await seen.current!.setAccountPaused("__main__", true)).toEqual({ ok: true });
154+
});
155+
156+
expect(calls).toContain("PUT codex-auth/accounts/pause");
157+
expect(seen.current!.accounts.find(account => account.isMain)?.id).toBe("a1");
158+
expect(seen.current!.accounts.find(account => account.isMain)?.paused).toBe(true);
159+
160+
await act(async () => {
161+
releaseReload();
162+
await new Promise((resolve) => setTimeout(resolve, 30));
163+
});
164+
});
165+
141166
test("bulk pausing writes one endpoint and updates every returned account", async () => {
142167
accounts = [
143168
{ id: "a1", email: "account-one", isMain: true, paused: false, hasCredential: true, quota: null },

0 commit comments

Comments
 (0)