A desktop coding agent with free access to frontier models.
TypeScript
fix: end the turn when the queue wait runs out
ogsamrat1da97bfbc4fb
diff --git a/apps/server/src/omnirush-gateway-broker.test.ts b/apps/server/src/omnirush-gateway-broker.test.tsindex f90ab1ac..e0b88b1f 100644--- a/apps/server/src/omnirush-gateway-broker.test.ts+++ b/apps/server/src/omnirush-gateway-broker.test.ts@@ -882,6 +882,32 @@ describe("upstream stream guard with recorded Muse streams", () => {}});+ test("a queue timeout in the stream ends the turn with readable copy the engine does not retry", async () => {+ const created = 'event: response.created\ndata: {"response":{"id":"resp_1"},"sequence_number":0,"type":"response.created"}\n\n';+ for (const code of ["omni_queue_timeout", "upstream_omni_queue_timeout"]) {+ const frame = `event: error\ndata: ${JSON.stringify({ type: "error", sequence_number: -1, error: { type: "server_error", code, message: "omnirush.ai: the turn waited too long (503)" } })}\n\n`;+ const { text, reasons } = await replayStream(new TextEncoder().encode(created + frame), 50);+ expect(reasons).toEqual([]);+ const last = eventPayloads(text)[1] as { error: { type: string; code: string; message: string; param: string } };+ expect(last).toMatchObject({ type: "error", sequence_number: -1, error: { type: "invalid_request_error", code: "invalid_prompt", param: "omni_queue_timeout" } });+ // The engine's retry patterns (session/retry.ts) must not match the copy or the body.+ // RETRYABLE_MESSAGE_PATTERNS of the engine (1.18.32).+ const retryable = [+ /429|500|502|503|504|524/i,+ /rate increased too quickly|rate limit|rate-limit|rate_limit|too many requests/i,+ /overloaded|service unavailable|service_unavailable|service-unavailable|internal error|internal_error|internal server error|server error|server_error|server-error|provider returned error|provider_returned_error|provider-returned-error/i,+ /terminated|fetch failed|failed to fetch|network[-_\s]error|upstream connect|connection error|connection refused|connection lost|socket connection was closed|socket hang up|reset before headers|getaddrinfo|enotfound|eai_again|econnrefused|econnreset|etimedout/i,+ /^timeout$|\b(?:request|response|connection|network|stream|read) (?:timeout|timed out|time out)\b/i,+ /try your request again|retry your request|resource exhausted|resource_exhausted/i,+ /\btry again (?:later|in\b)|\b(?:currently|temporarily) at capacity\b/i,+ ];+ for (const pattern of retryable) {+ expect(pattern.test(last.error.message)).toBe(false);+ expect(pattern.test(JSON.stringify(last))).toBe(false);+ }+ }+ });+test("a relay error frame that was not rewritten becomes one the engine parses", async () => {const created = 'event: response.created\ndata: {"response":{"id":"resp_1"},"sequence_number":0,"type":"response.created"}\n\n';const relay = 'event: error\ndata: {"error":{"code":"idle_timeout","message":"Upstream stopped sending data","request_id":"req_1","type":"timeout"}}\n\n';diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.tsindex f1879aa6..62319788 100644--- a/apps/server/src/omnirush-gateway-broker.ts+++ b/apps/server/src/omnirush-gateway-broker.ts@@ -191,6 +191,7 @@ const GATEWAY_ERROR_COPY: Record<string, string> = {token_capacity: BUSY_COPY,gateway_overload: BUSY_COPY,queue_timeout: BUSY_COPY,+ omni_queue_timeout: "every model seat is taken right now, and this turn waited in line too long. Send your message again; your place in line is kept for a few minutes.",provider_rate_limited: BUSY_COPY,voice_unavailable: "voice input is not available on this account yet.",transcription_unavailable: "the transcription service did not answer. Try again in a moment.",@@ -260,9 +261,33 @@ function stringField(value: unknown): string | null {* type, code or message), which would end the turn silently, and the engine* shows only a nested error's message.*/+/**+ * Codes that end the turn instead of being retried by the engine. A turn the+ * gateway's omni queue held past its maximum wait (`omni_queue_timeout`,+ * sent inside the committed stream) would otherwise be retried up to five+ * times by the engine, each retry waiting in line again: the chat shows+ * "running" for many minutes with nothing happening. The engine retries any+ * stream error except a few codes; `invalid_prompt` is one it shows as it is+ * and never retries (provider/error.ts, session/retry.ts), as long as the+ * message names nothing its retry patterns match.+ */+const TURN_ENDING_STREAM_CODES = new Set(["omni_queue_timeout"]);+const QUEUE_TIMEOUT_COPY = "omnirush.ai: every model seat is taken right now, and this turn waited in line too long. Send your message again; your place in line is kept for a few minutes.";++function turnEndingEvent(code: string, sequence: unknown): Uint8Array {+ const frame = {+ type: "error",+ sequence_number: typeof sequence === "number" && Number.isFinite(sequence) ? sequence : -1,+ error: { type: "invalid_request_error", code: "invalid_prompt", message: QUEUE_TIMEOUT_COPY, param: code },+ };+ return new TextEncoder().encode(`event: error\ndata: ${JSON.stringify(frame)}\n\n`);+}+function errorEvent(block: Uint8Array, payload: Record<string, unknown>): Uint8Array {const nested = isRecord(payload.error) ? payload.error : null;const code = stringField(nested ? nested.code : payload.code);+ const baseCode = code?.replace(/^upstream_/, "") ?? null;+ if (baseCode && TURN_ENDING_STREAM_CODES.has(baseCode)) return turnEndingEvent(baseCode, payload.sequence_number);const original = stringField(nested ? nested.message : payload.message);const readable = code ? gatewayErrorMessage(code, original) : null;const sequence = payload.sequence_number;