mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-01 13:23:37 +00:00
fix(auth): cancel WHAM probe error bodies
This commit is contained in:
@@ -1091,6 +1091,19 @@ describe("markAuthProfileFailure — WHAM-aware Codex cooldowns", () => {
|
||||
expect(store.usageStats?.["openai:default"]?.cooldownUntil).toBe(now + 300_000);
|
||||
});
|
||||
|
||||
it("cancels WHAM HTTP error response bodies", async () => {
|
||||
const now = 1_700_000_000_000;
|
||||
const store = makeStore({});
|
||||
const response = new Response("server busy", { status: 500 });
|
||||
const cancel = vi.spyOn(response.body!, "cancel").mockResolvedValue(undefined);
|
||||
fetchMock.mockResolvedValueOnce(response);
|
||||
|
||||
await markCodexFailureAt({ store, now });
|
||||
|
||||
expect(cancel).toHaveBeenCalledOnce();
|
||||
expect(store.usageStats?.["openai:default"]?.cooldownUntil).toBe(now + 300_000);
|
||||
});
|
||||
|
||||
it("preserves a longer existing cooldown via max semantics", async () => {
|
||||
const now = 1_700_000_000_000;
|
||||
const existingCooldownUntil = now + 6 * 60 * 60 * 1000;
|
||||
|
||||
@@ -210,6 +210,12 @@ function applyWhamCooldownResult(params: {
|
||||
};
|
||||
}
|
||||
|
||||
async function cancelUnreadResponseBody(response: Response): Promise<void> {
|
||||
if (!response.bodyUsed) {
|
||||
await response.body?.cancel().catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
async function probeWhamForCooldown(
|
||||
store: AuthProfileStore,
|
||||
profileId: string,
|
||||
@@ -249,6 +255,7 @@ async function probeWhamForCooldown(
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
await cancelUnreadResponseBody(res);
|
||||
if (res.status === 401) {
|
||||
return { cooldownMs: WHAM_TOKEN_EXPIRED_COOLDOWN_MS, reason: "wham_token_expired" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user