fix(ai): disable hidden provider 429 retries (#4991)
This commit is contained in:
@@ -1131,7 +1131,11 @@ describe("openai-codex streaming", () => {
|
||||
messages: [{ role: "user", content: "Say hello", timestamp: Date.now() }],
|
||||
};
|
||||
|
||||
const resultPromise = streamOpenAICodexResponses(model, context, { apiKey: token, transport: "sse" }).result();
|
||||
const resultPromise = streamOpenAICodexResponses(model, context, {
|
||||
apiKey: token,
|
||||
transport: "sse",
|
||||
maxRetries: 1,
|
||||
}).result();
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), expectedDelay);
|
||||
|
||||
@@ -1193,7 +1197,11 @@ describe("openai-codex streaming", () => {
|
||||
messages: [{ role: "user", content: "Say hello", timestamp: Date.now() }],
|
||||
};
|
||||
|
||||
const resultPromise = streamOpenAICodexResponses(model, context, { apiKey: token, transport: "sse" }).result();
|
||||
const resultPromise = streamOpenAICodexResponses(model, context, {
|
||||
apiKey: token,
|
||||
transport: "sse",
|
||||
maxRetries: 3,
|
||||
}).result();
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
expect(setTimeoutSpy).toHaveBeenNthCalledWith(1, expect.any(Function), 1000);
|
||||
|
||||
|
||||
86
packages/ai/test/openai-completions-retry.test.ts
Normal file
86
packages/ai/test/openai-completions-retry.test.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { streamOpenAICompletions } from "../src/providers/openai-completions.ts";
|
||||
import type { Context, Model } from "../src/types.ts";
|
||||
|
||||
const mockState = vi.hoisted(() => ({
|
||||
requestOptions: [] as unknown[],
|
||||
}));
|
||||
|
||||
vi.mock("openai", () => {
|
||||
class FakeOpenAI {
|
||||
chat = {
|
||||
completions: {
|
||||
create: (_params: unknown, options: unknown) => {
|
||||
mockState.requestOptions.push(options);
|
||||
const stream = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield {
|
||||
id: "chatcmpl-test",
|
||||
choices: [{ index: 0, delta: { content: "ok" } }],
|
||||
};
|
||||
yield {
|
||||
id: "chatcmpl-test",
|
||||
choices: [{ index: 0, delta: {}, finish_reason: "stop" }],
|
||||
};
|
||||
},
|
||||
};
|
||||
const promise = Promise.resolve(stream) as Promise<typeof stream> & {
|
||||
withResponse: () => Promise<{
|
||||
data: typeof stream;
|
||||
response: { status: number; headers: Headers };
|
||||
}>;
|
||||
};
|
||||
promise.withResponse = async () => ({
|
||||
data: stream,
|
||||
response: { status: 200, headers: new Headers() },
|
||||
});
|
||||
return promise;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return { default: FakeOpenAI };
|
||||
});
|
||||
|
||||
const model: Model<"openai-completions"> = {
|
||||
id: "test-model",
|
||||
name: "Test Model",
|
||||
api: "openai-completions",
|
||||
provider: "opencode-go",
|
||||
baseUrl: "https://opencode.ai/zen/go/v1",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 1000,
|
||||
maxTokens: 100,
|
||||
};
|
||||
|
||||
const context: Context = {
|
||||
systemPrompt: "",
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi" }], timestamp: 0 }],
|
||||
tools: [],
|
||||
};
|
||||
|
||||
async function consume(options?: { maxRetries?: number }) {
|
||||
const stream = streamOpenAICompletions(model, context, { apiKey: "test", ...options });
|
||||
for await (const _event of stream) {
|
||||
void _event;
|
||||
}
|
||||
return stream.result();
|
||||
}
|
||||
|
||||
describe("openai-completions provider retries", () => {
|
||||
beforeEach(() => {
|
||||
mockState.requestOptions = [];
|
||||
});
|
||||
|
||||
it("disables SDK retries by default", async () => {
|
||||
await consume();
|
||||
expect(mockState.requestOptions).toEqual([expect.objectContaining({ maxRetries: 0 })]);
|
||||
});
|
||||
|
||||
it("honors explicit provider retry settings", async () => {
|
||||
await consume({ maxRetries: 2 });
|
||||
expect(mockState.requestOptions).toEqual([expect.objectContaining({ maxRetries: 2 })]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user