From 427334a8a3b48072b5ab7586670574e94e432d60 Mon Sep 17 00:00:00 2001 From: bitkyc08-arch Date: Sun, 30 Aug 2026 00:13:04 +0900 Subject: [PATCH 1/2] test(codex): prove stored replay 402 closes compact recovery --- tests/responses-pool-401-refresh.test.ts | 132 ++++++++++++----------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/tests/responses-pool-401-refresh.test.ts b/tests/responses-pool-401-refresh.test.ts index dbac95851a..9349dff961 100644 --- a/tests/responses-pool-401-refresh.test.ts +++ b/tests/responses-pool-401-refresh.test.ts @@ -375,72 +375,76 @@ describe("ordinary pool 401 refresh and replay (#2887)", () => { expect(harness.refreshes).toEqual(["refresh-grant"]); }); - test("compact does not compose a stored-account replay 429 with a remembered model", async () => { - const headers = { "x-codex-parent-thread-id": "compact-refresh-budget" }; - writeStoredAccount({ - [OTHER_ACCOUNT_ID]: storedRecord({ - accessToken: "other-access", - refreshToken: "other-grant", - generation: 1, - chatgptAccountId: "acc-other", - }), - }); - const cfg = config({ secondAccount: true }); - cfg.accountPoolStrategy = "fill-first"; - cfg.providers.seed = { - adapter: "openai-responses", - baseUrl: "https://seed.example/v1", - authMode: "key", - apiKey: "seed-test-key", - }; - const harness = installHarness({ - responseForSend: (authorization, _sendNumber, url) => { - if (url.hostname === "seed.example") { - return Response.json({ - id: "seed", - object: "response", - status: "completed", - output: [{ - type: "message", - role: "assistant", - content: [{ type: "output_text", text: "seed summary", annotations: [] }], - }], - }); - } - if (authorization === "Bearer rejected-access") { - return Response.json({ error: { message: "rejected bearer" } }, { status: 401 }); - } - if (authorization === "Bearer refreshed-access") { - return Response.json({ error: { message: "pool exhausted" } }, { status: 429 }); - } - if (authorization === "Bearer other-access") { - return Response.json({ id: "must-not-run", object: "response", status: "completed", output: [] }); - } - return undefined; - }, - }); + for (const replayStatus of [429, 402] as const) { + test(`compact does not compose a stored-account replay ${replayStatus} with another account or remembered model`, async () => { + const headers = { "x-codex-parent-thread-id": `compact-refresh-budget-${replayStatus}` }; + writeStoredAccount({ + [OTHER_ACCOUNT_ID]: storedRecord({ + accessToken: "other-access", + refreshToken: "other-grant", + generation: 1, + chatgptAccountId: "acc-other", + }), + }); + const cfg = config({ secondAccount: true }); + cfg.accountPoolStrategy = "fill-first"; + cfg.providers.seed = { + adapter: "openai-responses", + baseUrl: "https://seed.example/v1", + authMode: "key", + apiKey: "seed-test-key", + }; + let seedModelSends = 0; + let alternateAccountSends = 0; + const harness = installHarness({ + responseForSend: (authorization, _sendNumber, url) => { + if (url.hostname === "seed.example") { + seedModelSends += 1; + return Response.json({ + id: "seed", + object: "response", + status: "completed", + output: [{ + type: "message", + role: "assistant", + content: [{ type: "output_text", text: "seed summary", annotations: [] }], + }], + }); + } + if (authorization === "Bearer rejected-access") { + return Response.json({ error: { message: "rejected bearer" } }, { status: 401 }); + } + if (authorization === "Bearer refreshed-access") { + return Response.json({ error: { message: "pool exhausted" } }, { status: replayStatus }); + } + if (authorization === "Bearer other-access") { + alternateAccountSends += 1; + return Response.json({ id: "must-not-run", object: "response", status: "completed", output: [] }); + } + return undefined; + }, + }); - const seed = await handleResponsesCompact( - request("/v1/responses/compact", { model: "seed/seed-model", headers }), - cfg, - { model: "", provider: "" } as RequestLogContext, - ); - expect(seed.status).toBe(200); + const seed = await handleResponsesCompact( + request("/v1/responses/compact", { model: "seed/seed-model", headers }), + cfg, + { model: "", provider: "" } as RequestLogContext, + ); + expect(seed.status).toBe(200); - const response = await handleResponsesCompact( - request("/v1/responses/compact", { headers }), - cfg, - { model: "", provider: "" } as RequestLogContext, - ); + const response = await handleResponsesCompact( + request("/v1/responses/compact", { headers }), + cfg, + { model: "", provider: "" } as RequestLogContext, + ); - expect(response.status).toBe(429); - expect(harness.sends).toEqual([ - "Bearer seed-test-key", - "Bearer rejected-access", - "Bearer refreshed-access", - ]); - expect(harness.refreshes).toEqual(["refresh-grant"]); - }); + expect(response.status).toBe(replayStatus); + expect(harness.sends).toHaveLength(3); + expect(alternateAccountSends).toBe(0); + expect(seedModelSends).toBe(1); + expect(harness.refreshes).toHaveLength(1); + }); + } test("the replayed account is still selectable on the NEXT request, not just this one", async () => { // The affinity entry is bound under generation G; the forced refresh CAS-writes G+1 and @@ -641,7 +645,7 @@ describe("ordinary pool 401 refresh and replay (#2887)", () => { expect(harness.refreshes).toEqual(["refresh-grant"]); }); - test("a stored-account replay 429 cannot reach another account even when one is eligible", async () => { + test("a stored-account replay 402 cannot reach another account even when one is eligible", async () => { // The mirror of the case above: a quota failure has no same-account move left, so it is // terminal. Asserted with a healthy alternate present, so passing means the budget stopped // it rather than there being nowhere to go. From f06e8ca837ff55ab073468440ff4d6db7e2f5eab Mon Sep 17 00:00:00 2001 From: bitkyc08-arch Date: Sun, 30 Aug 2026 00:18:44 +0900 Subject: [PATCH 2/2] test(codex): restore exact compact replay sends --- tests/responses-pool-401-refresh.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/responses-pool-401-refresh.test.ts b/tests/responses-pool-401-refresh.test.ts index 9349dff961..2b42c4ee34 100644 --- a/tests/responses-pool-401-refresh.test.ts +++ b/tests/responses-pool-401-refresh.test.ts @@ -439,10 +439,14 @@ describe("ordinary pool 401 refresh and replay (#2887)", () => { ); expect(response.status).toBe(replayStatus); - expect(harness.sends).toHaveLength(3); + expect(harness.sends).toEqual([ + "Bearer seed-test-key", + "Bearer rejected-access", + "Bearer refreshed-access", + ]); expect(alternateAccountSends).toBe(0); expect(seedModelSends).toBe(1); - expect(harness.refreshes).toHaveLength(1); + expect(harness.refreshes).toEqual(["refresh-grant"]); }); }