Skip to content

Commit 1ade870

Browse files
committed
fix(codex): honor websocket abort state for reauth
1 parent 0c70407 commit 1ade870

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎src/codex/auth-context.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export async function resolveCodexAuthContext(
618618
} catch (cause) {
619619
if (probeLeaseId && probeQuotaScope) releaseCodexQuotaScopeProbeLease(accountId, probeQuotaScope, probeLeaseId);
620620
else if (probeLeaseId) releaseCodexQuotaProbeLease(accountId, probeLeaseId);
621-
if (shouldMarkAccountNeedsReauthForCodexAuthFailure(cause)) {
621+
if (!options.signal?.aborted && shouldMarkAccountNeedsReauthForCodexAuthFailure(cause)) {
622622
markAccountNeedsReauth(accountId, writerGeneration);
623623
}
624624
throw new CodexAuthContextError(accountId, cause);
@@ -663,7 +663,7 @@ export async function resolveCodexAuthContext(
663663
} catch (cause) {
664664
if (probeLeaseId && probeQuotaScope) releaseCodexQuotaScopeProbeLease(accountId, probeQuotaScope, probeLeaseId);
665665
else if (probeLeaseId) releaseCodexQuotaProbeLease(accountId, probeLeaseId);
666-
if (shouldMarkAccountNeedsReauthForCodexAuthFailure(cause)) {
666+
if (!options.signal?.aborted && shouldMarkAccountNeedsReauthForCodexAuthFailure(cause)) {
667667
markAccountNeedsReauth(accountId, writerGeneration);
668668
}
669669
throw new CodexAuthContextError(accountId, cause);

‎tests/responses-native-main-refresh.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe("native main 401 refresh and replay", () => {
254254
}
255255

256256
test.each(["/v1/responses", "/v1/responses/compact"] as const)(
257-
"%s keeps an outer native-main claim cancellation as 499 without quarantining main",
257+
"%s keeps the WebSocket string-abort claim cancellation as 499 without quarantining main",
258258
async path => {
259259
writeFileSync(join(home, "auth.json"), JSON.stringify({
260260
tokens: { refresh_token: "refresh-grant", account_id: "account-main" },
@@ -287,15 +287,15 @@ describe("native main 401 refresh and replay", () => {
287287
request(path, controller.signal),
288288
config(),
289289
{ model: "", provider: "" } as RequestLogContext,
290-
{ abortSignal: controller.signal },
290+
{ abortSignal: controller.signal, inboundTransport: "websocket" },
291291
)
292292
: handleResponsesCompact(
293293
request(path, controller.signal),
294294
config(),
295295
{ model: "", provider: "" } as RequestLogContext,
296296
);
297297
while (!claimWaitListener?.mock.calls.some(([type]) => type === "abort")) await Promise.resolve();
298-
controller.abort();
298+
controller.abort("websocket turn superseded or closed");
299299

300300
const response = await pending;
301301
expect(response.status).toBe(499);

0 commit comments

Comments
 (0)