Skip to content

Commit 4d947ef

Browse files
committed
fix: disable default rate-limit replay
1 parent 79ba2a0 commit 4d947ef

3 files changed

Lines changed: 50 additions & 14 deletions

File tree

lib/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ export const DEFAULT_PLUGIN_CONFIG: PluginConfig = {
166166
fastSession: false,
167167
fastSessionStrategy: "hybrid",
168168
fastSessionMaxInputItems: 30,
169-
retryAllAccountsRateLimited: true,
169+
retryAllAccountsRateLimited: false,
170170
retryAllAccountsMaxWaitMs: 0,
171-
retryAllAccountsMaxRetries: Infinity,
171+
retryAllAccountsMaxRetries: 0,
172172
unsupportedCodexPolicy: "strict",
173173
fallbackOnUnsupportedCodexModel: false,
174174
fallbackToGpt52OnUnsupportedGpt53: true,
@@ -873,7 +873,7 @@ export function getRetryAllAccountsRateLimited(
873873
return resolveBooleanSetting(
874874
"CODEX_AUTH_RETRY_ALL_RATE_LIMITED",
875875
pluginConfig.retryAllAccountsRateLimited,
876-
true,
876+
false,
877877
);
878878
}
879879

@@ -894,7 +894,7 @@ export function getRetryAllAccountsMaxRetries(
894894
return resolveNumberSetting(
895895
"CODEX_AUTH_RETRY_ALL_MAX_RETRIES",
896896
pluginConfig.retryAllAccountsMaxRetries,
897-
Infinity,
897+
0,
898898
{ min: 0 },
899899
);
900900
}

test/index-retry.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,42 @@ describe("OpenAIAuthPlugin rate-limit retry", () => {
441441
expect(response.status).toBe(200);
442442
});
443443

444+
it("does not replay across all accounts by default when every account is rate-limited", async () => {
445+
delete process.env.CODEX_AUTH_RETRY_ALL_RATE_LIMITED;
446+
delete process.env.CODEX_AUTH_RETRY_ALL_MAX_WAIT_MS;
447+
delete process.env.CODEX_AUTH_RETRY_ALL_MAX_RETRIES;
448+
vi.resetModules();
449+
450+
const { OpenAIAuthPlugin } = await import("../index.js");
451+
const client = {
452+
tui: { showToast: vi.fn() },
453+
auth: { set: vi.fn() },
454+
} as any;
455+
456+
const plugin = await OpenAIAuthPlugin({ client });
457+
458+
const getAuth = async () => ({
459+
type: "oauth" as const,
460+
access: "a",
461+
refresh: "r",
462+
expires: Date.now() + 60_000,
463+
multiAccount: true,
464+
});
465+
466+
const sdk = (await plugin.auth.loader(getAuth, { options: {}, models: {} })) as any;
467+
const response = await sdk.fetch("https://example.com", {});
468+
const payload = await response.json();
469+
470+
expect(globalThis.fetch).not.toHaveBeenCalled();
471+
expect(response.status).toBe(429);
472+
expect(payload).toEqual({
473+
error: {
474+
message:
475+
"All 1 account(s) are rate-limited. Try again in 1000ms or add another account with `codex login`.",
476+
},
477+
});
478+
});
479+
444480
it("rebuilds request headers after rotating to the next workspace", async () => {
445481
const account = createMockAccount({
446482
workspaces: [

test/plugin-config.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ describe('Plugin Configuration', () => {
107107
fastSession: false,
108108
fastSessionStrategy: 'hybrid',
109109
fastSessionMaxInputItems: 30,
110-
retryAllAccountsRateLimited: true,
110+
retryAllAccountsRateLimited: false,
111111
retryAllAccountsMaxWaitMs: 0,
112-
retryAllAccountsMaxRetries: Infinity,
112+
retryAllAccountsMaxRetries: 0,
113113
unsupportedCodexPolicy: 'strict',
114114
fallbackOnUnsupportedCodexModel: false,
115115
fallbackToGpt52OnUnsupportedGpt53: true,
@@ -167,9 +167,9 @@ describe('Plugin Configuration', () => {
167167
fastSession: false,
168168
fastSessionStrategy: 'hybrid',
169169
fastSessionMaxInputItems: 30,
170-
retryAllAccountsRateLimited: true,
170+
retryAllAccountsRateLimited: false,
171171
retryAllAccountsMaxWaitMs: 0,
172-
retryAllAccountsMaxRetries: Infinity,
172+
retryAllAccountsMaxRetries: 0,
173173
unsupportedCodexPolicy: 'strict',
174174
fallbackOnUnsupportedCodexModel: false,
175175
fallbackToGpt52OnUnsupportedGpt53: true,
@@ -433,9 +433,9 @@ describe('Plugin Configuration', () => {
433433
fastSession: false,
434434
fastSessionStrategy: 'hybrid',
435435
fastSessionMaxInputItems: 30,
436-
retryAllAccountsRateLimited: true,
436+
retryAllAccountsRateLimited: false,
437437
retryAllAccountsMaxWaitMs: 0,
438-
retryAllAccountsMaxRetries: Infinity,
438+
retryAllAccountsMaxRetries: 0,
439439
unsupportedCodexPolicy: 'strict',
440440
fallbackOnUnsupportedCodexModel: false,
441441
fallbackToGpt52OnUnsupportedGpt53: true,
@@ -499,9 +499,9 @@ describe('Plugin Configuration', () => {
499499
fastSession: false,
500500
fastSessionStrategy: 'hybrid',
501501
fastSessionMaxInputItems: 30,
502-
retryAllAccountsRateLimited: true,
502+
retryAllAccountsRateLimited: false,
503503
retryAllAccountsMaxWaitMs: 0,
504-
retryAllAccountsMaxRetries: Infinity,
504+
retryAllAccountsMaxRetries: 0,
505505
unsupportedCodexPolicy: 'strict',
506506
fallbackOnUnsupportedCodexModel: false,
507507
fallbackToGpt52OnUnsupportedGpt53: true,
@@ -559,9 +559,9 @@ describe('Plugin Configuration', () => {
559559
fastSession: false,
560560
fastSessionStrategy: 'hybrid',
561561
fastSessionMaxInputItems: 30,
562-
retryAllAccountsRateLimited: true,
562+
retryAllAccountsRateLimited: false,
563563
retryAllAccountsMaxWaitMs: 0,
564-
retryAllAccountsMaxRetries: Infinity,
564+
retryAllAccountsMaxRetries: 0,
565565
unsupportedCodexPolicy: 'strict',
566566
fallbackOnUnsupportedCodexModel: false,
567567
fallbackToGpt52OnUnsupportedGpt53: true,

0 commit comments

Comments
 (0)