Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: mark refusals answered before any model

ogsamrat1aedf88aec25
diff --git a/apps/server/src/model-modes/PARITY.sha256 b/apps/server/src/model-modes/PARITY.sha256
index b8386d41..5f251081 100644
--- a/apps/server/src/model-modes/PARITY.sha256
+++ b/apps/server/src/model-modes/PARITY.sha256
@@ -2,5 +2,5 @@
# A change to one must be ported to the other and this list updated in both.
609bbc9cb508b4f79295e0b2f1f4707bd1facbee83835d5db7eac02fa088f43b model-modes.mjs
ef8a96d1e71ea3f5f3ab7a96796d042c009d90cc2896e7132b8dfc4486540699 model-modes.d.mts
-41d945bb9aab9be941dd1840a61384982a37b986e7d2e7306c57d32ffc2b6e2c strict-sessions.mjs
-7c98a499302e9d32799998f6960f0f5f3b4ff47b85fe24c5cc54bbfa084df54d strict-sessions.d.mts
+bbf8a35e039c958afaee5134e64cce37e693d0c8c48afac89a4eea190fc7b630 strict-sessions.mjs
+e3edeae9aaf20fc318646e5a4b496bfc8174b9cbeb73329aa0eb0005cdf96319 strict-sessions.d.mts
diff --git a/apps/server/src/model-modes/model-modes.test.ts b/apps/server/src/model-modes/model-modes.test.ts
index f3b2ac6d..f6cdd7f0 100644
--- a/apps/server/src/model-modes/model-modes.test.ts
+++ b/apps/server/src/model-modes/model-modes.test.ts
@@ -110,6 +110,7 @@ describe("model modes", () => {
expect((await b.handle(request({ model: "kimi-k3.1-pro", tools }, { "x-omnirush-session-id": "ses_one" }), "responses")).status).toBe(200);
const refused = await b.handle(request({ model: "gpt-6-astra", tools }, { "x-omnirush-session-id": "ses_one" }), "responses");
expect(refused.status).toBe(400);
+ expect(refused.headers.get("x-omnirush-refused")).toBe("1");
expect(((await refused.json()) as { error: { code: string; message: string } }).error).toMatchObject({ code: "session_model_fixed", message: "This chat runs on kimi-k3.1-pro. Start a new chat to use gpt-6-astra." });
expect((await b.handle(request({ model: "gpt-6-astra" }, { "x-omnirush-session-id": "ses_one" }), "responses")).status).toBe(400);
expect((await b.handle(request({ model: "gpt-6-astra" }, { "x-omnirush-session-id": "ses_one" }, "responses/compact"), "responses/compact")).status).toBe(400);
diff --git a/apps/server/src/model-modes/strict-sessions.d.mts b/apps/server/src/model-modes/strict-sessions.d.mts
index f6349777..ebcdfdb3 100644
--- a/apps/server/src/model-modes/strict-sessions.d.mts
+++ b/apps/server/src/model-modes/strict-sessions.d.mts
@@ -10,6 +10,7 @@ export const SESSION_MODEL_USED: "session_model_used";
export const STRICT_SESSION_HEADER: "x-omnirush-strict-session";
export const VERIFICATION_REQUIRED: "verification_required";
export const MODEL_NOT_BOUND: "model_not_bound";
+export const REFUSED_HEADER: "x-omnirush-refused";
export const MODE_NOT_BOUND: "mode_not_bound";
export const BIND_TIMEOUT_MS: number;
export const VERIFICATION_MESSAGE: string;
diff --git a/apps/server/src/model-modes/strict-sessions.mjs b/apps/server/src/model-modes/strict-sessions.mjs
index 92b8c414..74b589c8 100644
--- a/apps/server/src/model-modes/strict-sessions.mjs
+++ b/apps/server/src/model-modes/strict-sessions.mjs
@@ -33,6 +33,8 @@ export const BIND_TIMEOUT_MS = 5_000;
export const VERIFICATION_MESSAGE = "Your account needs to be verified before it can use models. See https://omnirush.ai/console";
export const SESSION_BIND_UNCONFIRMED = "session_bind_unconfirmed";
export const UNCONFIRMED_MESSAGE = "Couldn't confirm this chat with the server. Try again.";
+/** Set on a refusal the client answers itself (or replays): no model saw the request. The engine keeps it with the error, so the server leaves that prompt out of the chat's turns. */
+export const REFUSED_HEADER = "x-omnirush-refused";
const MODES = new Set(["off", "observe", "enforce"]);
const PATH = /^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/;
diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.ts
index 13e411b3..a8e44691 100644
--- a/apps/server/src/omnirush-gateway-broker.ts
+++ b/apps/server/src/omnirush-gateway-broker.ts
@@ -16,7 +16,7 @@ import { builtinOmniRushModelCatalog, omnirushModelWantsReasoningSummary } from
import { RejectedAttachments, isRejectedAttachmentError, type Attachment } from "./rejected-attachments.js";
import { gatewayUrlAllowed, RELEASE_GATEWAY_ERROR } from "./release-guard.js";
import { BOX_HEADER, MODEL_NOT_IN_MODE, notInModeMessage, projectMode } from "./model-modes/model-modes.mjs";
-import { MODE_NOT_BOUND, MODEL_NOT_BOUND, SESSION_BIND_UNCONFIRMED, STRICT_SESSION_HEADER, SESSION_BINDING_CONFLICT, SESSION_MODEL_USED, VERIFICATION_REQUIRED, sessionBinder, strictSessions, type StrictSessions } from "./model-modes/strict-sessions.mjs";
+import { MODE_NOT_BOUND, MODEL_NOT_BOUND, REFUSED_HEADER, SESSION_BIND_UNCONFIRMED, STRICT_SESSION_HEADER, SESSION_BINDING_CONFLICT, SESSION_MODEL_USED, VERIFICATION_REQUIRED, sessionBinder, strictSessions, type StrictSessions } from "./model-modes/strict-sessions.mjs";
import { ClaudeDeviceAccess, type ClaudeDeviceRequest } from "./claude-code/access.js";
import type { ClaudeAuthorization } from "./claude-code/runtime.js";
@@ -2086,7 +2086,7 @@ export class OmniRushGatewayBroker {
if (model && !(await this.modelInMode(model, this.boxRequest(request)))) {
this.log?.("info", "omnirush.ai model not available in this chat's mode; not sent", { model, box: this.boxRequest(request), clientRequestId: requestId });
const message = notInModeMessage(projectMode(this.boxRequest(request)));
- return Response.json({ detail: MODEL_NOT_IN_MODE, error: { type: "invalid_request_error", code: MODEL_NOT_IN_MODE, message } }, { status: 400, headers: { "x-should-retry": "false" } });
+ return Response.json({ detail: MODEL_NOT_IN_MODE, error: { type: "invalid_request_error", code: MODEL_NOT_IN_MODE, message } }, { status: 400, headers: { "x-should-retry": "false", [REFUSED_HEADER]: "1" } });
}
}
// One model per chat: a main chat's agent request on another model than its first is refused here.
@@ -2181,7 +2181,7 @@ export class OmniRushGatewayBroker {
if (body === undefined || (path !== "responses" && path !== "responses/compact")) return null;
const session = request.headers.get("x-omnirush-session-id");
if (!session) return request.headers.has(PARENT_SESSION_HEADER) || request.headers.has(SUBAGENT_ROOT_SESSION_HEADER)
- ? Response.json({error: {type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: "A sub-agent request must name its session and pinned parent."}}, {status: 400, headers: {"x-should-retry": "false"}})
+ ? Response.json({error: {type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: "A sub-agent request must name its session and pinned parent."}}, {status: 400, headers: {"x-should-retry": "false", [REFUSED_HEADER]: "1"}})
: null;
let parsed: unknown;
try {
@@ -2189,7 +2189,7 @@ export class OmniRushGatewayBroker {
} catch {
return null;
}
- if (!isRecord(parsed) || typeof parsed.model !== "string" || !parsed.model.replace(/^omnirush\//, "").trim()) return Response.json({error: {type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: "A session request must name its fixed model."}}, {status: 400, headers: {"x-should-retry": "false"}});
+ if (!isRecord(parsed) || typeof parsed.model !== "string" || !parsed.model.replace(/^omnirush\//, "").trim()) return Response.json({error: {type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: "A session request must name its fixed model."}}, {status: 400, headers: {"x-should-retry": "false", [REFUSED_HEADER]: "1"}});
const model = parsed.model.replace(/^omnirush\//, "");
const parents = [request.headers.get(SUBAGENT_ROOT_SESSION_HEADER), request.headers.get(PARENT_SESSION_HEADER)].filter((id): id is string => Boolean(id));
const pins = [session, ...parents].map(id => this.sessionModels.get(id)).filter((pin): pin is string => Boolean(pin));
@@ -2206,7 +2206,7 @@ export class OmniRushGatewayBroker {
return null;
}
this.log?.("info", "omnirush.ai chat model change refused (one model per chat)", { first, model });
- return Response.json({ detail: SESSION_MODEL_FIXED, error: { type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: first ? `This chat runs on ${first}. Start a new chat to use ${model}.` : "Resume the parent chat before continuing this sub-agent; its fixed model is unavailable." } }, { status: 400, headers: { "x-should-retry": "false" } });
+ return Response.json({ detail: SESSION_MODEL_FIXED, error: { type: "invalid_request_error", code: SESSION_MODEL_FIXED, message: first ? `This chat runs on ${first}. Start a new chat to use ${model}.` : "Resume the parent chat before continuing this sub-agent; its fixed model is unavailable." } }, { status: 400, headers: { "x-should-retry": "false", [REFUSED_HEADER]: "1" } });
}
/**
@@ -2278,8 +2278,8 @@ export class OmniRushGatewayBroker {
if (enforce && !this.bindsConfirmed.has(session)) this.uploadHold(session, "refused");
this.log?.("info", "omnirush.ai refused this chat's binding; not sent", { code: outcome.refused.code });
const { code, message, retry } = outcome.refused;
- if (retry) return Response.json({ detail: code, error: { type: "server_error", code, message } }, { status: 503, headers: { "x-should-retry": "true" } });
- return Response.json({ detail: code, error: { type: "invalid_request_error", code, message } }, { status: code === VERIFICATION_REQUIRED ? 403 : 400, headers: { "x-should-retry": "false" } });
+ if (retry) return Response.json({ detail: code, error: { type: "server_error", code, message } }, { status: 503, headers: { "x-should-retry": "true", [REFUSED_HEADER]: "1" } });
+ return Response.json({ detail: code, error: { type: "invalid_request_error", code, message } }, { status: code === VERIFICATION_REQUIRED ? 403 : 400, headers: { "x-should-retry": "false", [REFUSED_HEADER]: "1" } });
}
private uploadHold(sessionId: string, state: "pending" | "refused" | "confirmed"): void {