A desktop coding agent with free access to frontier models.
TypeScript
fix: key refusal analytics on error codes
ogsamrat59df2ee93b29
diff --git a/apps/app/src/app/lib/gateway-refusal.ts b/apps/app/src/app/lib/gateway-refusal.tsindex 6b1bdf13..99e7974e 100644--- a/apps/app/src/app/lib/gateway-refusal.ts+++ b/apps/app/src/app/lib/gateway-refusal.ts@@ -3,11 +3,15 @@ import type { AnalyticsProperties } from "./analytics";/*** Which omnirush.ai refusal an error card shows, for product analytics:* a spent allowance or cap (`limit_shown`) or the request policy- * (`policy_refusal_shown`). Reads only the error's title and technical- * details, and returns coarse labels, never the text.+ * (`policy_refusal_shown`). Keys on the gateway's stable `error.omnirush`+ * code; an error without one (an older backend) falls back to the error's+ * title and technical details. Returns coarse labels, never the text.*/export type GatewayRefusalEvent = { event: "limit_shown" | "policy_refusal_shown"; properties: AnalyticsProperties };+/** The fields of the gateway's `error.omnirush` this reads (session-error.ts parses it). */+type OmniRushErrorDetails = { code: string; scope?: string; retry?: boolean };+const POLICY = /request_policy_refused|OmniRush can[’']t help with this request/i;const GRANT_DAY = /today[’']s tokens are used up|used today[’']s model allowance/i;const GRANT_WEEK = /this week[’']s cap is reached/i;@@ -15,14 +19,42 @@ const GRANT_EMPTY = /you have no tokens left/i;const GRANT = /daily_grant_exhausted/i;const SESSION_CAP = /session_quality_cap/i;-export function gatewayRefusalEvent(error: { title?: string | null; technicalDetails?: string | null } | null | undefined): GatewayRefusalEvent | null {- if (!error) return null;- const text = `${error.title ?? ""}\n${error.technicalDetails ?? ""}`;- if (POLICY.test(text)) return { event: "policy_refusal_shown", properties: { reason: "request_policy" } };- if (GRANT_DAY.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "day" } };- if (GRANT_WEEK.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "week" } };- if (GRANT_EMPTY.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "empty" } };- if (GRANT.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "unknown" } };- if (SESSION_CAP.test(text)) return { event: "limit_shown", properties: { limit_type: "session_cap", scope: "session" } };+/** `error.omnirush.code` -> the event and its `limit_type` (null: the policy refusal). */+const BY_CODE: Record<string, { event: GatewayRefusalEvent["event"]; limitType: string | null; scope: string | null }> = {+ request_policy_refused: { event: "policy_refusal_shown", limitType: null, scope: null },+ limit_tokens: { event: "limit_shown", limitType: "tokens", scope: "unknown" },+ limit_session_cap: { event: "limit_shown", limitType: "session_cap", scope: "session" },+ limit_concurrency: { event: "limit_shown", limitType: "concurrency", scope: "unknown" },+ limit_rate: { event: "limit_shown", limitType: "rate", scope: "unknown" },+ queue_timeout: { event: "limit_shown", limitType: "queue_timeout", scope: null },+};++function fromCode(details: OmniRushErrorDetails): GatewayRefusalEvent | null {+ const known = BY_CODE[details.code];+ if (!known) return null;+ const properties: AnalyticsProperties = { code: details.code, source: "code" };+ if (typeof details.retry === "boolean") properties.retry = details.retry;+ if (known.event === "policy_refusal_shown") return { event: known.event, properties: { reason: "request_policy", ...properties } };+ const scope = details.scope ?? known.scope;+ return { event: known.event, properties: { limit_type: known.limitType, ...(scope ? { scope } : {}), ...properties } };+}++function fromText(text: string): GatewayRefusalEvent | null {+ const fallback = { source: "text" } as const;+ if (POLICY.test(text)) return { event: "policy_refusal_shown", properties: { reason: "request_policy", ...fallback } };+ if (GRANT_DAY.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "day", ...fallback } };+ if (GRANT_WEEK.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "week", ...fallback } };+ if (GRANT_EMPTY.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "empty", ...fallback } };+ if (GRANT.test(text)) return { event: "limit_shown", properties: { limit_type: "tokens", scope: "unknown", ...fallback } };+ if (SESSION_CAP.test(text)) return { event: "limit_shown", properties: { limit_type: "session_cap", scope: "session", ...fallback } };return null;}++export function gatewayRefusalEvent(+ error: { title?: string | null; technicalDetails?: string | null; omnirush?: OmniRushErrorDetails | null } | null | undefined,+): GatewayRefusalEvent | null {+ if (!error) return null;+ // A code this app does not know is an ordinary error, unless its text says otherwise.+ const coded = error.omnirush ? fromCode(error.omnirush) : null;+ return coded ?? fromText(`${error.title ?? ""}\n${error.technicalDetails ?? ""}`);+}diff --git a/apps/app/src/app/lib/good-session.ts b/apps/app/src/app/lib/good-session.tsindex 3e2c32e8..f855cfc9 100644--- a/apps/app/src/app/lib/good-session.ts+++ b/apps/app/src/app/lib/good-session.ts@@ -798,11 +798,13 @@ function sessionErrorOf(message: UIMessage): Record<string, unknown> | null {}/**- * The gateway refusing on purpose: out of tokens for the day, the Windows- * cut-off, the session cap, an app update required. Its messages start with+ * The gateway refusing on purpose: out of tokens for the day, the request+ * policy (or the model's own safety check, `cyber_policy`), the Windows+ * cut-off, the session cap, an app update required, or anything it marks+ * final (`"retry": false`). Its messages start with* "omnirush.ai: " (and usually end on a console link); retrying cannot help.*/-const REFUSAL = /(^|Message: )omnirush\.ai:|daily_grant_exhausted|windows_cutoff|session_quality_cap|update_required|client update required/im;+const REFUSAL = /(^|Message: )omnirush\.ai:|daily_grant_exhausted|request_policy_refused|cyber_policy|limit_tokens|limit_session_cap|"retry":\s*false|windows_cutoff|session_quality_cap|update_required|client update required/im;/*** How a turn that ended on an error ended. The engine's MessageAbortedError@@ -812,7 +814,9 @@ const REFUSAL = /(^|Message: )omnirush\.ai:|daily_grant_exhausted|windows_cutoff*/function errorEnding(error: Record<string, unknown>): { ended: LastTurnEnd; retryable: boolean } {if (error.kind === "aborted") return { ended: "stopped", retryable: false };- const refusal = REFUSAL.test(`${str(error.title)}\n${str(error.technicalDetails)}`) || Boolean(str(record(error.action).link));+ // The gateway marking it final (`error.omnirush.retry === false`, `x-should-retry: false`) is a refusal whatever its words.+ const refusal = record(error.omnirush).retry === false || error.noRetry === true+ || REFUSAL.test(`${str(error.title)}\n${str(error.technicalDetails)}`) || Boolean(str(record(error.action).link));if (/^Error type: APIError$/m.test(str(error.technicalDetails))) return { ended: "gateway", retryable: !refusal };return { ended: "cut", retryable: !refusal && (error.kind === "provider-timeout" || error.kind === "provider-incomplete") };}@@ -894,14 +898,26 @@ function turnEndOf(turn: readonly UIMessage[], last: UIMessage): TurnEnding {* (`endedAt`, ms; null when unknown) and whether one automatic "continue"* could help (`retryable`), for the finish guard and the auto-retry.*/-export function messageFacts(messages: readonly UIMessage[]): { calls: ToolCall[]; lastTurn: LastTurn } & TurnEnding {+export function messageFacts(messages: readonly UIMessage[]): { calls: ToolCall[]; lastTurn: LastTurn; replyOpen: boolean } & TurnEnding {const calls: ToolCall[] = [];for (const message of messages) {if (message.role !== "assistant") continue;calls.push(...messageCalls(message));}const ending = lastTurnEnd(messages);- return { calls, lastTurn: lastTurnOf(ending.ended), ...ending };+ return { calls, lastTurn: lastTurnOf(ending.ended), replyOpen: replyOpen(messages), ...ending };+}++/**+ * Whether the last reply is still open: an assistant message after the+ * last prompt with no end time and no error yet. The engine says idle+ * before it writes a failed turn's error onto the reply, so a turn read+ * at that moment looks cut off and a refusal would be retried.+ */+function replyOpen(messages: readonly UIMessage[]): boolean {+ const last = messages.at(-1);+ if (!last || last.role !== "assistant") return false;+ return typeof messageOpencode(last).completed !== "number" && !sessionErrorOf(last);}// --- The server's checklist (GET /me/sessions/{id}/status) ---------------------------diff --git a/apps/app/src/react-app/domains/quality/good-session.tsx b/apps/app/src/react-app/domains/quality/good-session.tsxindex 2483b622..c6e2eb14 100644--- a/apps/app/src/react-app/domains/quality/good-session.tsx+++ b/apps/app/src/react-app/domains/quality/good-session.tsx@@ -128,6 +128,8 @@ export type GoodSessionChecklistBarProps = {/** How long a turn's end settles before an auto-retry is judged (late Stop or error events land first). */const AUTO_RETRY_SETTLE_MS = 4_000;+/** How much longer it waits for a last reply still open then (no end time, no error yet) to close. */+export const AUTO_RETRY_REPLY_WAIT_MS = 3_000;/** Sessions whose running turn the user stopped (the Stop button); cleared when a turn starts. */const userStops = new Set<string>();/** Automatic retries in a row per session; reset when a turn finishes. */@@ -369,8 +371,18 @@ export function GoodSessionChecklistBar(props: GoodSessionChecklistBarProps) {return;}if (previous.sessionId !== sessionId || !previous.running) return;- const timer = window.setTimeout(() => {+ let replyDeadline = 0;+ const judge = () => {const now = latest.current;+ // The engine says idle before it writes a failed turn's error onto+ // the reply: an open reply is waited for (up to 3 s), never judged.+ if (now.facts.replyOpen && !now.turnRunning) {+ replyDeadline ||= Date.now() + AUTO_RETRY_REPLY_WAIT_MS;+ if (Date.now() < replyDeadline) {+ timer = window.setTimeout(judge, 100);+ return;+ }+ }if (now.facts.ended === "pass" || now.facts.ended === "awaiting") {autoRetries.delete(sessionId);return;@@ -388,7 +400,8 @@ export function GoodSessionChecklistBar(props: GoodSessionChecklistBarProps) {if (!message) return;autoRetries.set(sessionId, retriesInARow + 1);now.onAutoRetry(message);- }, AUTO_RETRY_SETTLE_MS);+ };+ let timer = window.setTimeout(judge, AUTO_RETRY_SETTLE_MS);return () => window.clearTimeout(timer);}, [props.sessionId, props.turnRunning]);diff --git a/apps/app/src/react-app/domains/session/sync/session-error.ts b/apps/app/src/react-app/domains/session/sync/session-error.tsindex e652e305..dfaa94f2 100644--- a/apps/app/src/react-app/domains/session/sync/session-error.ts+++ b/apps/app/src/react-app/domains/session/sync/session-error.ts@@ -5,6 +5,21 @@ import { normalizeErrorText } from "../../../../lib/error-text";export type OpencodeSessionErrorKind = "aborted" | "provider-timeout" | "provider-incomplete" | "free-model-limit" | "disk-full" | "database-error" | "generic";+/**+ * omnirush.ai's stable error object (`error.omnirush` of the gateway's JSON+ * error body or stream `error` frame): what the user hit, independent of the+ * message text. Absent on an older backend and on errors relayed from+ * upstream.+ */+export type OmniRushErrorDetails = {+ code: string;+ scope?: string;+ resets_at?: string;+ /** false: the same request cannot succeed before the user acts or the allowance resets. */+ retry?: boolean;+ retry_after?: number;+};+export type OpencodeSessionErrorPresentation = {kind: OpencodeSessionErrorKind;title: string;@@ -13,8 +28,70 @@ export type OpencodeSessionErrorPresentation = {recoveryPrompt: string | null;/** A page that fixes the error, opened in the browser (omnirush.ai's console for an account out of tokens). */action?: { label: string; link: string } | null;+ /** The gateway's `error.omnirush`, when the error carried one. */+ omnirush?: OmniRushErrorDetails | null;+ /** The answer said `x-should-retry: false`: the same request is refused again. */+ noRetry?: boolean;};+function parsedJson(value: unknown): unknown {+ if (typeof value !== "string" || !value.trim().startsWith("{")) return value;+ try {+ return JSON.parse(value);+ } catch {+ return null;+ }+}++/** A well-formed `error.omnirush` (only its known fields), or null. */+export function omnirushErrorDetails(value: unknown): OmniRushErrorDetails | null {+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;+ const source = value as Record<string, unknown>;+ const code = typeof source.code === "string" ? source.code.trim() : "";+ if (!code) return null;+ const details: OmniRushErrorDetails = { code };+ if (typeof source.scope === "string" && source.scope.trim()) details.scope = source.scope.trim();+ if (typeof source.resets_at === "string" && source.resets_at.trim()) details.resets_at = source.resets_at.trim();+ if (typeof source.retry === "boolean") details.retry = source.retry;+ if (typeof source.retry_after === "number" && Number.isFinite(source.retry_after)) details.retry_after = source.retry_after;+ return details;+}++/** Whether an engine API error's response headers say `x-should-retry: false`. */+function sessionSaysNoRetry(error: unknown): boolean {+ for (const record of [error, recordValue(error, "data"), recordValue(recordValue(error, "cause"), "data")]) {+ const headers = recordValue(record, "responseHeaders");+ if (!headers || typeof headers !== "object") continue;+ for (const [name, value] of Object.entries(headers as Record<string, unknown>)) {+ if (name.toLowerCase() === "x-should-retry" && String(value).trim().toLowerCase() === "false") return true;+ }+ }+ return false;+}++/**+ * The `error.omnirush` an engine session error carries: in the gateway's+ * response body (`data.responseBody`, the JSON of an HTTP error or of a+ * stream's `error` frame), or a raw frame the engine kept as the message.+ */+function sessionOmniRushDetails(error: unknown): OmniRushErrorDetails | null {+ if (!error || typeof error !== "object") return null;+ const data = recordValue(error, "data");+ const cause = recordValue(error, "cause");+ for (const record of [error, data, cause, recordValue(cause, "data")]) {+ for (const key of ["responseBody", "body", "message"]) {+ const payload = parsedJson(recordValue(record, key));+ const nested = recordValue(payload, "error");+ // A stream frame's object rides in its `param` (the engine keeps only type, code, message and param).+ const found = omnirushErrorDetails(recordValue(nested, "omnirush"))+ ?? omnirushErrorDetails(recordValue(payload, "omnirush"))+ ?? omnirushErrorDetails(recordValue(parsedJson(recordValue(nested, "param")), "omnirush"));+ if (found) return found;+ }+ }+ return null;+}+/*** An omnirush.ai error that ends with its console page ("… earn tokens every* day: https://omnirush.ai/console/account"): the sentence without the link,@@ -211,6 +288,7 @@ export function presentOpencodeSessionError(error: unknown, fallback = "Sessionconst fields = sessionErrorFields(error, fallback);const kind = sessionErrorKind(fields.name, fields.message, fields.code, fields.responseBody);const consoleLink = consoleLinkAction(fields.message);+ const omnirush = sessionOmniRushDetails(error);const fallbackTitle = normalizeSessionError(consoleLink?.text ?? fields.message ?? defaultErrorMessage(fields.name, fallback));return {kind,@@ -219,6 +297,8 @@ export function presentOpencodeSessionError(error: unknown, fallback = "SessiontechnicalDetails: technicalErrorDetails(error, fallback, fields),recoveryPrompt: errorRecoveryPrompt(kind),...(consoleLink ? { action: consoleLink.action } : {}),+ ...(omnirush ? { omnirush } : {}),+ ...(sessionSaysNoRetry(error) ? { noRetry: true } : {}),};}diff --git a/apps/app/tests/analytics.test.ts b/apps/app/tests/analytics.test.tsindex 29cf170d..5dc1323f 100644--- a/apps/app/tests/analytics.test.ts+++ b/apps/app/tests/analytics.test.ts@@ -22,6 +22,7 @@ const recordedNames = () => inspector().events(500).map((entry) => entry.name);const analytics = await import("../src/app/lib/analytics");const { ensureInspectorInstalled } = await import("../src/app/lib/app-inspector");const { gatewayRefusalEvent } = await import("../src/app/lib/gateway-refusal");+const { presentOpencodeSessionError } = await import("../src/react-app/domains/session/sync/session-error");const { reportSandboxFallback, sandboxFallbackProperties } = await import("../src/react-app/domains/settings/linux-sandbox");const ACCOUNT = "3f2504e0-4f89-11d3-9a0c-0305e82c3301";@@ -149,22 +150,76 @@ describe("onboarding survey", () => {});describe("refusals shown", () => {- test("request policy", () => {- expect(gatewayRefusalEvent({ title: "OmniRush can't help with this request. Free model access isn't for attacking systems.", technicalDetails: "" }))- .toEqual({ event: "policy_refusal_shown", properties: { reason: "request_policy" } });- expect(gatewayRefusalEvent({ title: "x", technicalDetails: "Code: request_policy_refused" })?.event).toBe("policy_refusal_shown");+ const apiError = (status: number, body: unknown, message = "x") => ({+ name: "APIError",+ data: { message, statusCode: status, isRetryable: false, responseBody: JSON.stringify(body) },+ });++ test("keyed on error.omnirush.code, whatever the words", () => {+ const policy = presentOpencodeSessionError(apiError(403, { error: { type: "invalid_request_error", code: "request_policy_refused", message: "Reworded.", omnirush: { code: "request_policy_refused", retry: false } } }, "Reworded."));+ expect(policy.omnirush).toEqual({ code: "request_policy_refused", retry: false });+ expect(gatewayRefusalEvent(policy)).toEqual({+ event: "policy_refusal_shown",+ properties: { reason: "request_policy", code: "request_policy_refused", source: "code", retry: false },+ });++ const tokens = presentOpencodeSessionError(apiError(429, { error: { code: "daily_grant_exhausted", message: "Anything.", omnirush: { code: "limit_tokens", scope: "week", resets_at: "2026-10-26T00:00:00Z", retry: false, retry_after: 600000 } } }));+ expect(gatewayRefusalEvent(tokens)).toEqual({+ event: "limit_shown",+ properties: { limit_type: "tokens", scope: "week", code: "limit_tokens", source: "code", retry: false },+ });++ const cases: Array<[Record<string, unknown>, Record<string, unknown>]> = [+ [{ code: "limit_session_cap", scope: "session", retry: false }, { limit_type: "session_cap", scope: "session" }],+ [{ code: "limit_concurrency", scope: "model", retry: true, retry_after: 5 }, { limit_type: "concurrency", scope: "model", retry: true }],+ [{ code: "limit_rate", scope: "account", retry: true }, { limit_type: "rate", scope: "account" }],+ [{ code: "queue_timeout", retry: true, retry_after: 15 }, { limit_type: "queue_timeout" }],+ [{ code: "limit_tokens", retry: false }, { limit_type: "tokens", scope: "unknown" }],+ ];+ for (const [omnirush, expected] of cases) {+ const shown = gatewayRefusalEvent({ title: "x", technicalDetails: "", omnirush: omnirush as { code: string } });+ expect(shown?.event).toBe("limit_shown");+ expect(shown?.properties).toMatchObject({ ...expected, code: omnirush.code, source: "code" });+ }+ expect(gatewayRefusalEvent({ title: "x", technicalDetails: "", omnirush: { code: "queue_timeout" } })?.properties).not.toHaveProperty("scope");+ });++ test("read from a stream error frame the engine kept, and from the broker's 403", () => {+ const frame = { type: "error", sequence_number: 3, error: { type: "invalid_request_error", code: "invalid_prompt", message: "OmniRush can't help.", param: "request_policy_refused", omnirush: { code: "request_policy_refused", retry: false } } };+ expect(presentOpencodeSessionError(apiError(0, frame)).omnirush?.code).toBe("request_policy_refused");+ expect(presentOpencodeSessionError({ name: "UnknownError", data: { message: JSON.stringify(frame) } }).omnirush?.code).toBe("request_policy_refused");+ // What the engine keeps of a stream frame: type, code, message and param (the broker's carrier).+ const kept = { type: "error", sequence_number: 3, error: { type: "invalid_request_error", code: "omnirush.ai", message: "OmniRush can't help.", param: JSON.stringify({ detail: "request_policy_refused", omnirush: { code: "request_policy_refused", retry: false } }) } };+ const cut = presentOpencodeSessionError(apiError(400, kept, "OmniRush can't help."));+ expect(cut.omnirush).toEqual({ code: "request_policy_refused", retry: false });+ expect(gatewayRefusalEvent(cut)?.properties).toMatchObject({ code: "request_policy_refused", source: "code" });+ // x-should-retry: false in the engine's copy of the response headers.+ expect(presentOpencodeSessionError({ name: "APIError", data: { message: "x", statusCode: 403, responseHeaders: { "X-Should-Retry": "false" } } }).noRetry).toBe(true);+ expect(presentOpencodeSessionError({ name: "APIError", data: { message: "x", statusCode: 429, responseHeaders: { "retry-after": "5" } } }).noRetry).toBeUndefined();+ // Malformed objects are ignored.+ expect(presentOpencodeSessionError(apiError(403, { error: { omnirush: { code: 7 } } })).omnirush).toBeUndefined();+ expect(presentOpencodeSessionError(apiError(403, { error: { omnirush: "limit_tokens" } })).omnirush).toBeUndefined();});- test("limits", () => {+ test("an older backend: the words, as before", () => {+ expect(gatewayRefusalEvent({ title: "OmniRush can't help with this request. Free model access isn't for attacking systems.", technicalDetails: "" }))+ .toEqual({ event: "policy_refusal_shown", properties: { reason: "request_policy", source: "text" } });+ expect(gatewayRefusalEvent({ title: "x", technicalDetails: "Code: request_policy_refused" })?.event).toBe("policy_refusal_shown");expect(gatewayRefusalEvent({ title: "omnirush.ai: today's tokens are used up. They refill at 5:30 AM (in 3 h).", technicalDetails: "" })?.properties)- .toEqual({ limit_type: "tokens", scope: "day" });+ .toEqual({ limit_type: "tokens", scope: "day", source: "text" });expect(gatewayRefusalEvent({ title: "omnirush.ai: this week's cap is reached. It resets Monday.", technicalDetails: "" })?.properties.scope).toBe("week");expect(gatewayRefusalEvent({ title: "omnirush.ai: you have no tokens left.", technicalDetails: "" })?.properties.scope).toBe("empty");expect(gatewayRefusalEvent({ title: "x", technicalDetails: "Code: daily_grant_exhausted" })?.properties.scope).toBe("unknown");expect(gatewayRefusalEvent({ title: "x", technicalDetails: "session_quality_cap" })?.properties.limit_type).toBe("session_cap");+ // The same old-shape errors through the real presentation.+ const old = presentOpencodeSessionError(apiError(429, { error: { message: "omnirush.ai: you have used today's model allowance. It refills at 00:00 UTC.", type: "omnirush_error", code: "daily_grant_exhausted" } }, "omnirush.ai: you have used today's model allowance. It refills at 00:00 UTC."));+ expect(old.omnirush).toBeUndefined();+ expect(gatewayRefusalEvent(old)).toEqual({ event: "limit_shown", properties: { limit_type: "tokens", scope: "day", source: "text" } });});- test("other errors are not refusals", () => {+ test("an unknown code falls back to the words; other errors are not refusals", () => {+ expect(gatewayRefusalEvent({ title: "Provider did not respond in time", technicalDetails: "Status: 504", omnirush: { code: "something_new" } })).toBeNull();+ expect(gatewayRefusalEvent({ title: "x", technicalDetails: "session_quality_cap", omnirush: { code: "something_new" } })?.properties.source).toBe("text");expect(gatewayRefusalEvent({ title: "Provider did not respond in time", technicalDetails: "Status: 504" })).toBeNull();expect(gatewayRefusalEvent(null)).toBeNull();});diff --git a/apps/app/tests/good-session.test.tsx b/apps/app/tests/good-session.test.tsxindex 5542724a..f73bbade 100644--- a/apps/app/tests/good-session.test.tsx+++ b/apps/app/tests/good-session.test.tsx@@ -608,6 +608,40 @@ describe("how the last turn ended (session_qc._completion)", () => {}expect(retryable([prompt(), assistant("a", [{ type: "text", text: "Half done" }], { finish: "length" })])).toBe(false);});++ test("retryable: never what the gateway marks final in error.omnirush, whatever its words", () => {+ const retryable = (omnirush: Record<string, unknown>) => messageFacts([prompt(), errorMessage({+ kind: "generic", title: "Something new", technicalDetails: "Error type: APIError\nStatus: 429", omnirush,+ })]).retryable;+ expect(retryable({ code: "limit_tokens", scope: "day", retry: false })).toBe(false);+ expect(retryable({ code: "something_new", retry: false })).toBe(false);+ expect(retryable({ code: "limit_concurrency", scope: "account", retry: true })).toBe(true);+ });++ test("retryable: never the policy, the model's safety check, the stable limit codes or x-should-retry: false", () => {+ const retryable = (sessionError: Record<string, unknown>) => messageFacts([prompt(), errorMessage({ kind: "generic", title: "Refused", ...sessionError })]).retryable;+ for (const details of [+ "Error type: APIError\nMessage: OmniRush can't help with this request.\nResponse: {\"error\":{\"code\":\"request_policy_refused\"}}",+ "Error type: APIError\nMessage: This content was flagged.\nResponse: {\"type\":\"error\",\"error\":{\"code\":\"cyber_policy\"}}",+ "Error type: APIError\nResponse: {\"error\":{\"omnirush\":{\"code\":\"limit_tokens\",\"retry\": false}}}",+ "Error type: APIError\nResponse: {\"error\":{\"omnirush\":{\"code\":\"limit_session_cap\"}}}",+ ]) {+ expect(retryable({ technicalDetails: details })).toBe(false);+ }+ expect(retryable({ technicalDetails: "Error type: APIError\nStatus: 400", noRetry: true })).toBe(false);+ expect(retryable({ technicalDetails: "Error type: APIError\nStatus: 400" })).toBe(true);+ });++ test("replyOpen: the last reply has no end time and no error yet (the engine's idle comes first)", () => {+ const open = assistant("a", [tool("bash", { command: "npm test" }, "input-streaming")]);+ expect(messageFacts([prompt(), open]).replyOpen).toBe(true);+ // Looks cut off and retryable while open: the auto-retry waits for it to close.+ expect(messageFacts([prompt(), open]).retryable).toBe(true);+ const refused = errorMessage({ kind: "generic", title: "OmniRush can't help with this request.", technicalDetails: "Error type: APIError", omnirush: { code: "request_policy_refused", retry: false } });+ expect(messageFacts([prompt(), open, refused])).toMatchObject({ replyOpen: false, ended: "gateway", retryable: false });+ expect(messageFacts([prompt(), assistant("a", [{ type: "text", text: "Done." }], { completed: 5 })]).replyOpen).toBe(false);+ expect(messageFacts([prompt()]).replyOpen).toBe(false);+ });});describe("the finish guard", () => {@@ -678,6 +712,13 @@ describe("the server's auto-retry and one-more-turn nudge", () => {expect(autoRetryMessage({ ...base, turnRunning: true })).toBeNull();});+ test("never after an error the gateway marks final (error.omnirush.retry false)", () => {+ const facts = messageFacts([prompt(), errorMessage({ kind: "generic", title: "x", technicalDetails: "Error type: APIError", omnirush: { code: "request_policy_refused", retry: false } })]);+ expect(autoRetryMessage({ ...base, ended: facts.ended, retryable: facts.retryable })).toBeNull();+ const busy = messageFacts([prompt(), errorMessage({ kind: "generic", title: "x", technicalDetails: "Error type: APIError", omnirush: { code: "limit_rate", retry: true } })]);+ expect(autoRetryMessage({ ...base, ended: busy.ended, retryable: busy.retryable })).toBe("Continue.");+ });+test("never after the Stop button or on a refusal", () => {expect(autoRetryMessage({ ...base, userStopped: true })).toBeNull();expect(autoRetryMessage({ ...base, ended: "stopped", retryable: false })).toBeNull();