Skip to content

Commit 8aaf937

Browse files
committed
fix(auth): cancel WHAM probe error bodies
1 parent 6467c19 commit 8aaf937

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/agents/auth-profiles/usage.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,19 @@ describe("markAuthProfileFailure — WHAM-aware Codex cooldowns", () => {
10911091
expect(store.usageStats?.["openai:default"]?.cooldownUntil).toBe(now + 300_000);
10921092
});
10931093

1094+
it("cancels WHAM HTTP error response bodies", async () => {
1095+
const now = 1_700_000_000_000;
1096+
const store = makeStore({});
1097+
const response = new Response("server busy", { status: 500 });
1098+
const cancel = vi.spyOn(response.body!, "cancel").mockResolvedValue(undefined);
1099+
fetchMock.mockResolvedValueOnce(response);
1100+
1101+
await markCodexFailureAt({ store, now });
1102+
1103+
expect(cancel).toHaveBeenCalledOnce();
1104+
expect(store.usageStats?.["openai:default"]?.cooldownUntil).toBe(now + 300_000);
1105+
});
1106+
10941107
it("preserves a longer existing cooldown via max semantics", async () => {
10951108
const now = 1_700_000_000_000;
10961109
const existingCooldownUntil = now + 6 * 60 * 60 * 1000;

‎src/agents/auth-profiles/usage.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ function applyWhamCooldownResult(params: {
210210
};
211211
}
212212

213+
async function cancelUnreadResponseBody(response: Response): Promise<void> {
214+
if (!response.bodyUsed) {
215+
await response.body?.cancel().catch(() => undefined);
216+
}
217+
}
218+
213219
async function probeWhamForCooldown(
214220
store: AuthProfileStore,
215221
profileId: string,
@@ -249,6 +255,7 @@ async function probeWhamForCooldown(
249255
});
250256

251257
if (!res.ok) {
258+
await cancelUnreadResponseBody(res);
252259
if (res.status === 401) {
253260
return { cooldownMs: WHAM_TOKEN_EXPIRED_COOLDOWN_MS, reason: "wham_token_expired" };
254261
}

0 commit comments

Comments
 (0)