Skip to content

Commit e975d49

Browse files
committed
fix(agents): skip wham probe when oauth access token is locally expired
1 parent 1ad346e commit e975d49

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,24 @@ describe("markAuthProfileFailure — WHAM-aware Codex cooldowns", () => {
11981198
expect(store.usageStats?.["openai:default"]?.cooldownUntil).toBe(now + 43_200_000);
11991199
});
12001200

1201+
it("skips WHAM probe for locally expired OAuth access tokens", async () => {
1202+
const now = 1_700_000_000_000;
1203+
const store = makeStore({});
1204+
const profile = store.profiles["openai:default"];
1205+
if (profile?.type !== "oauth") {
1206+
throw new Error("expected OpenAI OAuth fixture");
1207+
}
1208+
profile.expires = now - 1;
1209+
mockWhamResponse(401);
1210+
1211+
await markCodexFailureAt({ store, now });
1212+
1213+
expect(fetchMock).not.toHaveBeenCalled();
1214+
const stats = store.usageStats?.["openai:default"];
1215+
expect(stats?.cooldownUntil).toBe(now + 30_000);
1216+
expect(stats?.cooldownReason).toBe("rate_limit");
1217+
});
1218+
12011219
it("maps HTTP 403 to a 24h cooldown", async () => {
12021220
const now = 1_700_000_000_000;
12031221
const store = makeStore({});

src/agents/auth-profiles/usage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ function shouldProbeWhamForFailure(
124124
return (
125125
profile?.type === "oauth" &&
126126
Boolean(profile.access) &&
127+
// Expired access tokens are routine and refreshable; probing with one
128+
// guarantees a 401 that looks like a 12h token-family outage.
129+
isFutureDateTimestampMs(profile.expires) &&
127130
normalizedProvider === "openai" &&
128131
(reason === "rate_limit" ||
129132
reason === "empty_response" ||

0 commit comments

Comments
 (0)