Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Chat runtime retries: drop the unused noRetry option so openai-chat.ts stays within its 1,000-line cap

milind-sonia82ded72d9f1
diff --git a/scripts/testing/file-size-ratchet.test.ts b/scripts/testing/file-size-ratchet.test.ts
index b3805b7cef..50e360ff4a 100644
--- a/scripts/testing/file-size-ratchet.test.ts
+++ b/scripts/testing/file-size-ratchet.test.ts
@@ -46,7 +46,6 @@ const LINES: Record<string, number> = {
"src/components/AttachmentPreview.tsx": 1034,
"server/meetings/meetbot.ts": 1047,
"electron/data-dir-lease.node-test.mjs": 846, // the data-folder lease's own tests: many platform cases (Windows probes in data-dir-lease-windows.node-test.mjs)
- "server/drivers/openai-chat.ts": 1002,
};
function sourceFiles(): string[] {
diff --git a/server/drivers/openai-chat.test.ts b/server/drivers/openai-chat.test.ts
index bdd844a344..e50e859e3e 100644
--- a/server/drivers/openai-chat.test.ts
+++ b/server/drivers/openai-chat.test.ts
@@ -10,7 +10,6 @@ import { discardNativeLog, flushNativeLog } from "./native.ts";
import type { RuntimeEvent, SendTurnInput } from "../contracts.ts";
import { GrokDriver } from "./grok.ts";
import { MinimaxDriver } from "./minimax.ts";
-import { createOpenAIChatRuntime } from "./openai-chat.ts";
import { OpenAICompatDriver } from "./openai-compat.ts";
import { MistralDriver } from "./mistral.ts";
import { startFakeHttpMcp } from "../testing/fake-http-mcp-server.ts";
@@ -1141,39 +1140,7 @@ describe("createOpenAIChatRuntime transient retries", () => {
expect(events.at(-1)).toMatchObject({ type: "turn.completed", ok: true });
}, 20_000);
- it("does not retry a 429 when the caller opts out", async () => {
- let requests = 0;
- vi.stubGlobal("fetch", vi.fn(async (url: string | URL) =>
- String(url).endsWith("/chat/completions")
- ? (requests++, rateLimited())
- : new Response("", { status: 404 })));
- const runtime = createOpenAIChatRuntime({
- input: { instanceId: "runtime", displayName: "Runtime", environment: {}, enabled: true, config: {} },
- driverKind: "test",
- apiKey: "secret",
- apiUrl: "https://api.example.com/v1",
- models: () => ({ default: "m", options: [{ id: "m", label: "m" }] }),
- requestBody: (model, messages, stream) => ({ model, messages, stream }),
- httpErrorLabel: "Test",
- missingKeyError: "missing key",
- unavailableReason: "missing key",
- timeoutMs: 10_000,
- noRetry: true,
- nativeLog: { source: "test", outgoing: () => ({}), incoming: () => ({}) },
- });
- const events: RuntimeEvent[] = [];
- runtime.adapter.onEvent((event) => events.push(event));
- await runtime.adapter.sendTurn({ threadId: "thread", text: "hi" });
- await vi.waitFor(() => {
- if (!events.some((event) => event.type === "turn.completed")) throw new Error("turn still running");
- }, { timeout: 10_000 });
- await runtime.dispose();
- expect(requests).toBe(1);
- expect(events.filter((event) => event.type === "turn.retrying")).toHaveLength(0);
- expect(events.at(-1)).toMatchObject({ type: "turn.completed", ok: false });
- }, 20_000);
-
- it("retries a 429 from an endpoint that omits retryScale, then answers", async () => {
+ it("retries a 429 from an OpenAI-compatible endpoint, then answers", async () => {
let requests = 0;
const events = await runRetryTurn(() => ++requests === 1 ? rateLimited() : answer());
expect(requests).toBe(2);
diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.ts
index 5bd0e91f5b..f1a8aa922d 100644
--- a/server/drivers/openai-chat.ts
+++ b/server/drivers/openai-chat.ts
@@ -110,8 +110,6 @@ interface RuntimeOptions<Config> {
includeUsageInCompleted?: boolean;
noBodyError?: string;
retryScale?: number;
- /** A caller that must not resend a turn after an ambiguous failure: no retry even for transient errors. */
- noRetry?: boolean;
tools?: boolean;
computerUse?: boolean;
/** A text-only model keeps the computer and browser tools but never receives a screenshot or attachment. */
@@ -725,7 +723,7 @@ export function createOpenAIChatRuntime<Config>(options: RuntimeOptions<Config>)
}
// Never replay a handled call. A stream closed before any completion marker ran nothing upstream, so it may resend even where the caller never opted into retries.
const truncation = error instanceof StreamTruncatedError, retryScale = truncation ? options.retryScale ?? 1 : options.retryScale;
- if (retryScale === undefined || abort.signal.aborted || streamed || seenCalls.size || error instanceof RuntimeNoticeError || options.noRetry || (!truncation && (error instanceof ChatProtocolError || !verdict.transient)) || attempt >= RETRY_MAX_ATTEMPTS - 1) throw error;
+ if (retryScale === undefined || abort.signal.aborted || streamed || seenCalls.size || error instanceof RuntimeNoticeError || (!truncation && (error instanceof ChatProtocolError || !verdict.transient)) || attempt >= RETRY_MAX_ATTEMPTS - 1) throw error;
const delayMs = computeBackoff(attempt++);
emit({ ...base(turn.threadId, turnId), type: "turn.retrying", attempt, delayMs, reason: truncation ? "stream_truncated" : verdict.reason });
await interruptibleDelay(delayMs * retryScale, abort.signal).promise;