Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: one model per chat; native-only models skip the sandbox

ogsamrat6404368c82ea
diff --git a/apps/app/src/app/lib/good-session.ts b/apps/app/src/app/lib/good-session.ts
index 2776d804..f99308e1 100644
--- a/apps/app/src/app/lib/good-session.ts
+++ b/apps/app/src/app/lib/good-session.ts
@@ -804,7 +804,7 @@ function sessionErrorOf(message: UIMessage): Record<string, unknown> | null {
* 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|request_policy_refused|cyber_policy|limit_tokens|limit_session_cap|"retry":\s*false|windows_cutoff|session_quality_cap|model_not_in_mode|This model isn't available (?:in sandbox projects|in normal projects|outside the sandbox|in this project)|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|model_not_in_mode|session_model_fixed|This chat runs on |This model isn't available (?:in sandbox projects|in normal projects|outside the sandbox|in this project)|update_required|client update required/im;
/**
* How a turn that ended on an error ended. The engine's MessageAbortedError
diff --git a/apps/app/src/react-app/domains/session/surface/model-modes.ts b/apps/app/src/react-app/domains/session/surface/model-modes.ts
index 20fefec6..8dbed3df 100644
--- a/apps/app/src/react-app/domains/session/surface/model-modes.ts
+++ b/apps/app/src/react-app/domains/session/surface/model-modes.ts
@@ -1,6 +1,10 @@
-// Per-model modes in the app: a sandbox (box) project shows and sends only the
-// models that may run in the sandbox, a project without it only the ones that
-// may run outside it. The server lists each catalog model's `modes`
+// Per-model modes in the app. A chat's model is fixed when it starts (its
+// sub-agents and compactions use it too). A new chat may start on a model the
+// project's mode allows, or, in a sandbox project, on a model that runs only
+// outside the sandbox (Kimi): that chat then runs on this computer, exempt
+// from the required sandbox (box/service.ts beforePrompt nativeModel). A model
+// that runs only in the sandbox is never offered outside it. The server lists
+// each catalog model's `modes`
// (GET /omnirush/subagent-model, normalized from the backend's catalog by the
// shared apps/server/src/model-modes/model-modes.mjs: no `modes` means both).
// The gateway broker sends X-OmniRush-Box for box chats and refuses a model
@@ -23,10 +27,20 @@ export function modeAllowsModel(models: CatalogModels | undefined, mode: Mode |
return !entry?.modes || entry.modes.includes(mode);
}
-/** The model a project in `mode` uses instead of `model`: the catalog default among the allowed ones, else the first allowed. */
+/**
+ * Whether a NEW chat in a project in `mode` may start on `model`: one its mode
+ * allows, or in a sandbox project one that runs only on this computer (the
+ * chat then runs here).
+ */
+export function newChatAllowsModel(models: CatalogModels | undefined, mode: Mode | null, model: ModelRef | null | undefined): boolean {
+ if (modeAllowsModel(models, mode, model)) return true;
+ return mode === "box" && modeAllowsModel(models, "native", model);
+}
+
+/** The model a new chat in `mode` starts on instead of `model`: the catalog default among the allowed ones, else the first allowed. */
export function modeFallbackModel(models: CatalogModels | undefined, mode: Mode | null, model: ModelRef | null | undefined): ModelRef | null {
- if (modeAllowsModel(models, mode, model)) return model ?? null;
- const allowed = (models ?? []).filter((entry) => !entry.modes || entry.modes.includes(mode!));
+ if (newChatAllowsModel(models, mode, model)) return model ?? null;
+ const allowed = (models ?? []).filter((entry) => newChatAllowsModel(models, mode, { providerID: "omnirush", modelID: entry.id }));
const pick = allowed.find((entry) => entry.default) ?? allowed[0];
return pick ? { providerID: "omnirush", modelID: pick.id } : null;
}
@@ -37,6 +51,36 @@ export function modeSwitchNote(models: CatalogModels | undefined, mode: Mode, fr
return `${name(from)} isn't available ${mode === "box" ? "in sandbox projects" : "outside the sandbox"}. Using ${name(to)} here.`;
}
+/** "This chat runs on Kimi K3.1 Pro. Start a new chat to use GPT 6 Astra." */
+export function fixedModelNote(models: CatalogModels | undefined, current: ModelRef, wanted: ModelRef): string {
+ const name = (ref: ModelRef) => models?.find((entry) => entry.id === ref.modelID)?.name ?? ref.modelID;
+ return `This chat runs on ${name(current)}. Start a new chat to use ${name(wanted)}.`;
+}
+
+/** "This chat runs on Kimi K3.1 Pro, which isn't available in sandbox projects. Start a new chat." */
+export function chatModeNote(models: CatalogModels | undefined, mode: Mode, model: ModelRef): string {
+ const name = models?.find((entry) => entry.id === model.modelID)?.name ?? model.modelID;
+ return `This chat runs on ${name}, which isn't available ${mode === "box" ? "in sandbox projects" : "outside the sandbox"}. Start a new chat.`;
+}
+
+const STARTED_KEY = "omnirush.sessionModelFixed";
+
+/** Chats that sent a prompt: their model is fixed (one model per chat). */
+export function chatStarted(sessionId: string | null | undefined): boolean {
+ if (!sessionId || typeof window === "undefined") return false;
+ try { return (JSON.parse(window.localStorage.getItem(STARTED_KEY) ?? "[]") as unknown[]).includes(sessionId); } catch { return false; }
+}
+
+export function markChatStarted(sessionId: string): void {
+ if (typeof window === "undefined" || chatStarted(sessionId)) return;
+ try {
+ const ids = (JSON.parse(window.localStorage.getItem(STARTED_KEY) ?? "[]") as unknown[]).filter((id): id is string => typeof id === "string");
+ window.localStorage.setItem(STARTED_KEY, JSON.stringify([...ids, sessionId].slice(-2000)));
+ } catch {
+ // quota: the broker still keeps the chat on its model
+ }
+}
+
/**
* The open project's rule for every model list the app shows (the composer's
* model menu, the model picker): set by the session route, all models while
@@ -61,12 +105,17 @@ export function useProjectModelModes(
const models = state?.models;
const rules = useMemo(() => ({
mode,
+ /** An existing chat's model in the chat's own mode. */
allows: (model: ModelRef | null | undefined) => modeAllowsModel(models, mode, model),
+ /** What a new chat may start on (the pickers' list). */
+ allowsNew: (model: ModelRef | null | undefined) => newChatAllowsModel(models, mode, model),
fallback: (model: ModelRef | null | undefined) => modeFallbackModel(models, mode, model),
note: (from: ModelRef, to: ModelRef) => modeSwitchNote(models, mode ?? "native", from, to),
+ fixedNote: (current: ModelRef, wanted: ModelRef) => fixedModelNote(models, current, wanted),
+ chatNote: (model: ModelRef) => chatModeNote(models, mode ?? "native", model),
}), [mode, models]);
useEffect(() => {
- useModelModeFilter.setState({ allows: rules.allows });
+ useModelModeFilter.setState({ allows: rules.allowsNew });
}, [rules]);
useEffect(() => () => useModelModeFilter.setState({ allows: () => true }), []);
return rules;
diff --git a/apps/app/src/react-app/shell/session-route.tsx b/apps/app/src/react-app/shell/session-route.tsx
index 3c6f1bc3..62679bee 100644
--- a/apps/app/src/react-app/shell/session-route.tsx
+++ b/apps/app/src/react-app/shell/session-route.tsx
@@ -141,7 +141,7 @@ import { computeModelAvailability, createUnavailableConfirmationGate, sessionMod
import { useSessionFindStore } from "@/react-app/domains/session/surface/find-store";
import { useModelPicker } from "@/react-app/domains/session/modals/use-model-picker";
import { getSessionModelSelection, resolveSendVariant, useSessionModelStore } from "@/react-app/domains/session/surface/session-model-store";
-import { useProjectModelModes } from "@/react-app/domains/session/surface/model-modes";
+import { chatStarted, markChatStarted, useProjectModelModes } from "@/react-app/domains/session/surface/model-modes";
import { useWorkbenchStore } from "@/react-app/domains/session/chat/workbench-store";
import { resolveWorkbenchPaneEndpoint } from "@/react-app/domains/session/chat/pane-runtime";
import {
@@ -1004,13 +1004,19 @@ export function SessionRoute() {
// The default as this project may use it: one its mode does not allow moves to the allowed default.
const projectDefaultModel = modelModes.fallback(local.prefs.defaultModel ?? null) ?? local.prefs.defaultModel ?? null;
/**
- * The model a send in the open project goes out on: one its mode does not
- * allow moves to the allowed default before anything is sent, with a note,
- * and the chat remembers it.
+ * The model a send in the open project goes out on. A chat's model is fixed
+ * once it sent a prompt: if its project's mode no longer allows it (the
+ * sandbox turned on or off since), nothing is sent and the person is told to
+ * start a new chat. Only a new chat moves to the allowed default, with a note.
*/
const modeSendModel = (model: ModelRef | null | undefined, sessionId: string | null): ModelRef | null => {
const rules = modelModesRef.current;
- if (!model || rules.allows(model)) return model ?? null;
+ if (!model) return null;
+ if (sessionId && chatStarted(sessionId)) {
+ if (!rules.allows(model)) throw new Error(rules.chatNote(model));
+ return model;
+ }
+ if (rules.allowsNew(model)) return model;
const next = rules.fallback(model);
if (!next) return model;
toast(rules.note(model, next), { id: `model-mode:${sessionId ?? "new"}` });
@@ -1120,11 +1126,6 @@ export function SessionRoute() {
(selectedSessionId ? state.bySessionId[selectedSessionId] ?? null : null),
);
const activeComposerModel = selectedSessionModelSelection?.model ?? projectDefaultModel;
- // A chat whose model its project's mode does not allow (the sandbox turned on or off since): moved before any send.
- useEffect(() => {
- const model = selectedSessionModelSelection?.model;
- if (selectedSessionId && model && !modelModes.allows(model)) modeSendModel(model, selectedSessionId);
- }, [modelModes, selectedSessionId, selectedSessionModelSelection?.model]);
const activeComposerAvailability = resolveModelAvailability(activeComposerModel);
const activeComposerTargetsSession = Boolean(selectedSessionModelSelection && selectedSessionId);
const selectedModelUnavailableKey = activeComposerAvailability.status === "unavailable" && activeComposerModel
@@ -1570,6 +1571,8 @@ export function SessionRoute() {
if (sendModel && getQueuedSendGeneration(targetSessionId) === generation) {
useSessionModelStore.getState().setModel(targetSessionId, sendModel, sendVariant ?? null);
}
+ // Its first prompt went out: the chat keeps this model from now on.
+ markChatStarted(targetSessionId);
},
unrevert: async () => {
try {
@@ -1908,6 +1911,8 @@ export function SessionRoute() {
if (sendModel && getQueuedSendGeneration(targetSessionId) === generation) {
useSessionModelStore.getState().setModel(targetSessionId, sendModel, sendVariant ?? null);
}
+ // Its first prompt went out: the chat keeps this model from now on.
+ markChatStarted(targetSessionId);
},
unrevert: async () => {
try {
@@ -2839,6 +2844,12 @@ export function SessionRoute() {
behavior?: { value: string | null },
) => {
const explicitBehavior = behavior !== undefined;
+ // One model per chat: a chat that sent a prompt keeps its model.
+ const fixed = targetSessionId && chatStarted(targetSessionId) ? getSessionModelSelection(targetSessionId)?.model : null;
+ if (fixed && (fixed.providerID !== next.providerID || fixed.modelID !== next.modelID)) {
+ toast(modelModesRef.current.fixedNote(fixed, next), { id: `model-fixed:${targetSessionId}` });
+ return;
+ }
useModelCollectionsStore.getState().recordRecent(next);
if (targetSessionId) {
const sessionStore = useSessionModelStore.getState();
@@ -4120,7 +4131,7 @@ export function SessionRoute() {
onOpenAutomations={() => navigate(automationsRoute())}
onOpenDashboard={() => navigate(dashboardRoute())}
onCreateWorkspace={handleOpenCreateWorkspace}
- modelOptions={modelPicker.options.filter((option) => modelModes.allows(option))}
+ modelOptions={modelPicker.options.filter((option) => modelModes.allowsNew(option))}
selectedModel={paletteSelectedModel}
selectedModelBehavior={paletteSelectedModelBehavior}
onSelectModel={(next, behavior) => {
@@ -4161,7 +4172,7 @@ export function SessionRoute() {
/>
<ModelPickerModal
open={modelPicker.open}
- options={modelPicker.options.filter((option) => modelModes.allows(option))}
+ options={modelPicker.options.filter((option) => modelModes.allowsNew(option))}
organizationModelsEmpty={organizationModelsEmpty}
organizationModelsSettingsUrl={organizationModelsSettingsUrl}
diff --git a/apps/app/tests/model-modes.test.ts b/apps/app/tests/model-modes.test.ts
index 9a337816..72c98978 100644
--- a/apps/app/tests/model-modes.test.ts
+++ b/apps/app/tests/model-modes.test.ts
@@ -1,7 +1,7 @@
import { expect, test } from "bun:test";
import { modeSwitchNote as sharedNote } from "../../server/src/model-modes/model-modes.mjs";
-import { modeAllowsModel, modeFallbackModel, modeSwitchNote } from "../src/react-app/domains/session/surface/model-modes";
+import { chatModeNote, fixedModelNote, modeAllowsModel, modeFallbackModel, modeSwitchNote, newChatAllowsModel } from "../src/react-app/domains/session/surface/model-modes";
// As GET /omnirush/subagent-model lists them: `modes` normalized by the server.
const MODELS = [
@@ -24,8 +24,17 @@ test("a project's mode decides which omnirush models it may use; others, unknown
});
test("a refused model moves to the default the mode allows, with the CLI's note", () => {
- expect(modeFallbackModel(MODELS, "box", ref("kimi-k3.1-pro"))).toEqual(ref("gpt-6-astra"));
+ expect(modeFallbackModel(MODELS, "native", ref("boxonly-x"))).toEqual(ref("gpt-6-astra"));
expect(modeFallbackModel(MODELS, "box", ref("gpt-6-astra"))).toEqual(ref("gpt-6-astra"));
- expect(modeFallbackModel([MODELS[1]!, MODELS[2]!].map((m) => ({ ...m, default: m.id === "kimi-k3.1-pro" })), "box", ref("kimi-k3.1-pro"))).toEqual(ref("boxonly-x"));
+ expect(modeFallbackModel([MODELS[1]!, MODELS[2]!].map((m) => ({ ...m, default: m.id === "boxonly-x" })), "native", ref("boxonly-x"))).toEqual(ref("kimi-k3.1-pro"));
expect(modeSwitchNote(MODELS, "box", ref("kimi-k3.1-pro"), ref("gpt-6-astra"))).toBe(sharedNote("Kimi K3.1 Pro", "GPT 6 Astra", "box"));
});
+
+test("a new chat in a sandbox project may start on a model that runs only on this computer (it runs here); never on a sandbox-only one outside it", () => {
+ expect(newChatAllowsModel(MODELS, "box", ref("kimi-k3.1-pro"))).toBe(true);
+ expect(newChatAllowsModel(MODELS, "native", ref("boxonly-x"))).toBe(false);
+ expect(modeFallbackModel(MODELS, "box", ref("kimi-k3.1-pro"))).toEqual(ref("kimi-k3.1-pro"));
+ expect(modeFallbackModel(MODELS, "native", ref("boxonly-x"))).toEqual(ref("gpt-6-astra"));
+ expect(fixedModelNote(MODELS, ref("kimi-k3.1-pro"), ref("gpt-6-astra"))).toBe("This chat runs on Kimi K3.1 Pro. Start a new chat to use GPT 6 Astra.");
+ expect(chatModeNote(MODELS, "native", ref("boxonly-x"))).toBe("This chat runs on Box Only X, which isn't available outside the sandbox. Start a new chat.");
+});
diff --git a/apps/server/src/box/PARITY.sha256 b/apps/server/src/box/PARITY.sha256
index 74d9f447..ed2ee443 100644
--- a/apps/server/src/box/PARITY.sha256
+++ b/apps/server/src/box/PARITY.sha256
@@ -8,4 +8,4 @@ fd7531323e200f2133cdf66ed8608d04af3a38049cfeb01a0a285cbd72813c4d wsl.json
ec1c7507cd3919a1066c870e3f7018424bdca8641fbf34fec9c4eefd9def1d29 host-builds.json
fe040597bec7f113721071097906380c51198d0cc785747c3891b754e55f34a2 retention.mjs
e0478a8e95284a9f1713ee695dd5a2a7123991b2ab2d45297a09369cce037da7 retention.d.mts
-f56e2a03b587b9b62b8cf3a3accd509158ec8b17c0642504ecc42a3db1369ca9 required.json
+d32741f68dc8b5aa9b3cbdd5a24b02b150b059a2156c260ea47759213194dc11 required.json
diff --git a/apps/server/src/box/box-required-service.test.ts b/apps/server/src/box/box-required-service.test.ts
index 960a31a5..90f62026 100644
--- a/apps/server/src/box/box-required-service.test.ts
+++ b/apps/server/src/box/box-required-service.test.ts
@@ -150,6 +150,24 @@ describe("required sandbox: the desktop's projects", () => {
expect(JSON.parse(await readFile(join(home, DESKTOP_PROJECTS_FILE), "utf8")).native_chats).toEqual(["ses_req_old1"]);
});
+ test("a new chat on a model that runs only on this computer stays here, exempt from the required box (native_model)", async () => {
+ const stateDir = await temp("state");
+ const home = await temp("boxhome");
+ const root = await temp("project");
+ const workspace: BoxWorkspace = { id: "ws_nm", path: root, workspaceType: "local" };
+ rememberServerDefault(stateDir, { local_box: { default: "on", required: true } });
+ const boxes = service({ stateDir, workspaces: [workspace], env: { OMNIRUSH_BOX_HOME: home } });
+ const frozen: string[] = [];
+ boxes.ensure = async () => fakeRun(root, frozen);
+ expect(await boxes.beforePrompt("ses_kimi_new", workspace, { nativeModel: true })).toBeNull();
+ // A chat that already ran in the box keeps it (its model never changed).
+ await boxes.beforePrompt("ses_box_first", workspace);
+ await boxes.beforePrompt("ses_box_first", workspace, { nativeModel: true });
+ expect(frozen).toEqual(["ses_box_first turn-1", "ses_box_first turn-2"]);
+ expect(await boxes.planOutcome("ses_kimi_new", workspace)).toEqual({ native: true, source: "model", reason: "native_model", required: true, fallback: "native" });
+ expect(JSON.parse(await readFile(join(home, DESKTOP_PROJECTS_FILE), "utf8")).native_chats).toEqual(["ses_kimi_new"]);
+ });
+
test("the first prompt waits while the image downloads, then runs in the box", async () => {
const stateDir = await temp("state");
const root = await temp("project");
diff --git a/apps/server/src/box/required.json b/apps/server/src/box/required.json
index c3f7d4c3..dc14702c 100644
--- a/apps/server/src/box/required.json
+++ b/apps/server/src/box/required.json
@@ -11,12 +11,13 @@
"about": "What client.launch `box` says under required: {required: true, reason, fallback, capable}. In the box: capable true, no fallback. cannot_run: this machine can't run the box (no virtualization, setup not possible or not done yet, a box that failed to start): capable false, fallback native (counted in full). opted_out: it could, but the box was turned off (--no-sandbox / OMNIRUSH_BOX=0) or the setup declined: capable true, fallback = the server's required_fallback. kept: an old chat or a host-only project, on this machine as before: fallback native, capable not checked (absent). Any other reason on this machine reads as cannot_run.",
"cannot_run": ["cannot_run", "box_failed", "setup_needed"],
"opted_out": ["env_off", "setup_declined"],
- "kept": ["kept_old_chat", "host_only"]
+ "kept": ["kept_old_chat", "host_only", "native_model"]
},
"reasons": {
"required": "box",
"kept_old_chat": "kept_old_chat",
"host_only": "host_only",
+ "native_model": "native_model",
"env_off": "env_off",
"setup_needed": "setup_needed",
"cannot_run": "cannot_run",
@@ -136,6 +137,7 @@
"required_line": "This account runs new chats in the OmniRush sandbox, a Linux box set up for you, so sessions can be rebuilt.",
"opt_out_refused": "The sandbox is required for new chats on this account; chats started before stay as they were.",
"kept_old_chat": "This chat started on this machine before the sandbox was required, so it stays here.",
+ "native_model": "{model} runs on this machine, not in the sandbox, so this chat stays here.",
"host_only": "This project only builds on {label} ({things}), so its chats run on {machine}.",
"shadows": "In the sandbox, {dirs} are the sandbox's own Linux copies; your {label} copies are left as they are. Install dependencies inside as needed.",
"setup_needed": "Setting up the sandbox ({step})…",
diff --git a/apps/server/src/box/required.ts b/apps/server/src/box/required.ts
index c54e534c..f83f6c17 100644
--- a/apps/server/src/box/required.ts
+++ b/apps/server/src/box/required.ts
@@ -16,7 +16,7 @@ import { HOST_BUILD_RULES, hostBuilds, hostRules } from "./host-builds.js";
import rules from "./required.json" with { type: "json" };
export type RequiredFallback = "native" | "native_uncounted";
-export type RequiredReason = "box" | "kept_old_chat" | "host_only" | "env_off" | "setup_needed" | "cannot_run" | "setup_declined";
+export type RequiredReason = "box" | "kept_old_chat" | "native_model" | "host_only" | "env_off" | "setup_needed" | "cannot_run" | "setup_declined";
export type CannotRunWhy = keyof typeof rules.texts.why;
type HostOnlyPattern = { name?: string; suffix?: string; contains: string };
type HostOnlyRules = { dirs_suffix: string[]; files: string[]; file_patterns: HostOnlyPattern[] };
diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.ts
index 426cb1e6..26a7d5a6 100644
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@ -217,6 +217,8 @@ export class BoxService {
private readonly chatTurns = new Map<string, number>();
/** Chats (and their project's key) that ran on this machine before the server's default turned the box on: they stay here. */
private readonly nativeChats = new Map<string, string>();
+ /** Of nativeChats, the ones on a model that runs only on this computer (launch reason native_model). */
+ private readonly nativeModelChats = new Set<string>();
/** Chats sent to their project's box in this run (a failed checkpoint included). */
private readonly boxedChats = new Set<string>();
/** Chats whose box.plan event went out in this run. */
@@ -779,8 +781,16 @@ export class BoxService {
* label returned for its uploads. Null when the chat runs natively. Never
* throws; waits at most FREEZE_WAIT_MS.
*/
- async beforePrompt(sessionId: string, workspace: BoxWorkspace, { capture = true, turnsBefore = 0 }: { capture?: boolean; turnsBefore?: number } = {}): Promise<BoxCaptureInfo | null> {
+ async beforePrompt(sessionId: string, workspace: BoxWorkspace, { capture = true, turnsBefore = 0, nativeModel = false }: { capture?: boolean; turnsBefore?: number; nativeModel?: boolean } = {}): Promise<BoxCaptureInfo | null> {
if (!/^[A-Za-z0-9._:-]{8,128}$/.test(sessionId)) return null;
+ // A chat on a model that runs only on this computer (model-modes/: Kimi) runs here, exempt from
+ // the required sandbox, unless it already ran in the box (a chat's model never changes).
+ if (nativeModel && !this.nativeChats.has(sessionId) && !this.boxedChats.has(sessionId) && !this.turns.has(sessionId) && savedTurns(this.snapshotDir(sessionId)) === 0) {
+ this.nativeChats.set(sessionId, boxKey(boxRoot(workspace)));
+ this.nativeModelChats.add(sessionId);
+ await this.writeProjects();
+ this.log("info", "box: a chat on a model that runs only on this computer stays here", { sessionId });
+ }
// The chat's own turn number, counted with the box on or off: a chat that ran natively
// (reopened, or its box turned on mid-chat) has its first checkpoint (turn-1) before a later
// turn; the checkpoint names it as session_turn (CLI: the same).
@@ -874,7 +884,7 @@ export class BoxService {
// on this machine, the fallback in force: `native` where it can't (counted in full), the server's
// required_fallback where the box was turned off (OMNIRUSH_BOX=0) or the setup declined.
const native = (reason: string, extra: Partial<BoxPlanOutcome> = {}): BoxPlanOutcome => ({ native: true, source: mode.source, reason, ...(mode.required ? requiredLaunch(reason, { native: true, serverFallback: fallback }) : {}), ...extra });
- if (this.nativeChats.has(sessionId)) return native("kept_old_chat", { source: "chat" });
+ if (this.nativeChats.has(sessionId)) return this.nativeModelChats.has(sessionId) ? native("native_model", { source: "model" }) : native("kept_old_chat", { source: "chat" });
if (this.boxedChats.has(sessionId)) return { native: false, source: mode.source, reason: "box", ...(mode.required ? requiredLaunch("box", { native: false }) : {}) };
if (!mode.on) {
if (mode.required && mode.source === "env") return native("env_off");
diff --git a/apps/server/src/model-modes/model-modes.test.ts b/apps/server/src/model-modes/model-modes.test.ts
index 1d3b4f43..849a4e54 100644
--- a/apps/server/src/model-modes/model-modes.test.ts
+++ b/apps/server/src/model-modes/model-modes.test.ts
@@ -102,6 +102,19 @@ describe("model modes", () => {
expect(((await response.json()) as { error: { message: string } }).error.message).toBe("This model isn't available in sandbox projects.");
});
+ test("broker: one model per chat; titles (no tools), sub-agents and other chats pass", async () => {
+ const calls: Call[] = [];
+ const b = broker(calls, undefined, false);
+ const tools = [{ type: "function", name: "bash" }];
+ 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(((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(200);
+ expect((await b.handle(request({ model: "gpt-6-astra", tools }, { "x-omnirush-session-id": "ses_two" }), "responses")).status).toBe(200);
+ expect(calls.map((c) => c.model)).toEqual(["kimi-k3.1-pro", "gpt-6-astra", "gpt-6-astra"]);
+ });
+
test("broker: a sub-agent's picked model refused for the mode runs on the main model", async () => {
const calls: Call[] = [];
const response = await broker(calls, (call) => call.model === "kimi-k3.1-pro" ? Response.json(REFUSAL, { status: 400, headers: { "x-should-retry": "false" } }) : Response.json({ output: [] }), false)
diff --git a/apps/server/src/omnirush-gateway-broker.ts b/apps/server/src/omnirush-gateway-broker.ts
index 5e38aa9f..e45dabe6 100644
--- a/apps/server/src/omnirush-gateway-broker.ts
+++ b/apps/server/src/omnirush-gateway-broker.ts
@@ -16,6 +16,8 @@ import { RejectedAttachments, isRejectedAttachmentError, type Attachment } from
import { gatewayUrlAllowed, RELEASE_GATEWAY_ERROR } from "./release-guard.js";
import { BOX_HEADER, MODEL_NOT_IN_MODE, notInModeMessage, projectMode } from "./model-modes/model-modes.mjs";
+/** A main chat's request on another model than the one it started on (one model per chat). */
+const SESSION_MODEL_FIXED = "session_model_fixed";
/** A refused attachment is left out and the model request sent again, at most this often per request. */
const MAX_ATTACHMENT_RETRIES = 2;
const MAX_ATTACHMENT_ERROR_BYTES = 256 * 1024;
@@ -210,6 +212,7 @@ const GATEWAY_ERROR_COPY: Record<string, string> = {
update_required: "this version of OmniRush.ai is no longer supported. Update the app to keep using models; your sessions are kept.",
// A model outside the project's mode (model-modes/): the gateway's refusal, or the broker's own before sending.
[MODEL_NOT_IN_MODE]: notInModeMessage().replace(/^T/, "t"),
+ [SESSION_MODEL_FIXED]: "this chat keeps the model it started on. Start a new chat to use another model.",
};
/** Readable copy for a gateway error code, or null for a code it does not know. */
@@ -677,7 +680,7 @@ function readableErrorBody(text: string, grant: string | null): { error: Record<
if (!code) return null;
const message = (grant && code === "daily_grant_exhausted" ? `omnirush.ai: ${grant.charAt(0).toLowerCase()}${grant.slice(1)}` : null)
// The server names the version to install, or the kind of project the model runs in; keep its words.
- ?? (code === UPDATE_REQUIRED_CODE || code === MODEL_NOT_IN_MODE ? stringField(nested?.message) ?? stringField(payload.message) : null)
+ ?? (code === UPDATE_REQUIRED_CODE || code === MODEL_NOT_IN_MODE || code === SESSION_MODEL_FIXED ? stringField(nested?.message) ?? stringField(payload.message) : null)
?? gatewayErrorMessage(code, stringField(nested?.message))
?? (bareCode ? `omnirush.ai could not complete the model request (${code}).` : null);
if (!message) return null;
@@ -1252,6 +1255,8 @@ export class OmniRushGatewayBroker {
* question) still goes out as a box request. Oldest first, bounded.
*/
private readonly boxSessions = new Set<string>();
+ /** Each chat's model, from its first agent request (one model per chat; oldest first, bounded). */
+ private readonly sessionModels = new Map<string, string>();
private readonly onUpdateSignal?: (signal: GatewayUpdateSignal) => void;
private readonly reasoningSummaryFor: (model: string) => boolean | Promise<boolean>;
private readonly clientHeader: string | null;
@@ -1934,6 +1939,9 @@ export class OmniRushGatewayBroker {
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" } });
}
}
+ // One model per chat: a main chat's agent request on another model than its first is refused here.
+ const fixed = this.fixedModelRefusal(request, path, body);
+ if (fixed) return fixed;
const forwardedBody = path === "responses" && body !== undefined
? await withReasoningSummary(body, this.reasoningSummaryFor)
: body;
@@ -1990,6 +1998,35 @@ export class OmniRushGatewayBroker {
});
}
+ /**
+ * A main chat's agent request (it offers tools; titles and summaries do not)
+ * whose model is not the one the chat started on: a 400
+ * `session_model_fixed`, never sent. Sub-agent chats (they name their main
+ * chat) are left to the swarm's own rules.
+ */
+ private fixedModelRefusal(request: Request, path: string, body: ArrayBuffer | string | undefined): Response | null {
+ if (body === undefined || path !== "responses" || request.headers.get(PARENT_SESSION_HEADER)) return null;
+ const session = request.headers.get("x-omnirush-session-id");
+ if (!session) return null;
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(typeof body === "string" ? body : new TextDecoder().decode(body));
+ } catch {
+ return null;
+ }
+ if (!isRecord(parsed) || typeof parsed.model !== "string" || !Array.isArray(parsed.tools) || parsed.tools.length === 0) return null;
+ const model = parsed.model.replace(/^omnirush\//, "");
+ const first = this.sessionModels.get(session);
+ if (!first) {
+ this.sessionModels.set(session, model);
+ while (this.sessionModels.size > 2048) this.sessionModels.delete(this.sessionModels.keys().next().value!);
+ return null;
+ }
+ if (first === model) 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: `This chat runs on ${first}. Start a new chat to use ${model}.` } }, { status: 400, headers: { "x-should-retry": "false" } });
+ }
+
/** Whether a request comes from a box chat: marked so, or from a chat (or its main chat) marked earlier. */
private boxRequest(request: Request): boolean {
const sessions = [request.headers.get("x-omnirush-session-id"), request.headers.get(PARENT_SESSION_HEADER)].filter((id): id is string => Boolean(id));
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 98e1c36d..6f1694e9 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -2127,7 +2127,7 @@ export async function proxyOpencodeV2Request(input: {
const turnsBefore = capture && uploadedSessionId && engine ? await turnsBeforeCapture(capture, uploadedSessionId, engine) : 0;
// The Linux sandbox (box/): a prompt of a workspace whose box is on starts the box, and takes the turn's checkpoint when it is captured.
const boxInfo = promptDispatch && sessionId
- ? await boxServiceFor(input.config).beforePrompt(sessionId, input.workspace, { capture: Boolean(uploadedSessionId && engine), turnsBefore })
+ ? await boxServiceFor(input.config).beforePrompt(sessionId, input.workspace, { capture: Boolean(uploadedSessionId && engine), turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
: null;
if (capture && uploadedSessionId && engine) {
// The turn before's background processes finish writing (at most 10 s after it ended), its project
@@ -2566,7 +2566,7 @@ export async function proxyOpencodeRequest(input: {
? await turnsBeforeCapture(capture, uploadedSessionId, engineTarget(baseUrl, headers, search))
: 0;
const boxInfo = workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath)
- ? await boxServiceFor(input.config).beforePrompt(uploadedSessionId, workspace, { capture: captured && !steer, turnsBefore })
+ ? await boxServiceFor(input.config).beforePrompt(uploadedSessionId, workspace, { capture: captured && !steer, turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
: null;
if (capture && captured && uploadedSessionId && workspace && !steer) {
const promptDispatch = isUploadPromptDispatch(method, proxyPath);
@@ -7865,3 +7865,22 @@ function parseWorkspaceExportSensitiveMode(input: string | null): WorkspaceExpor
}
throw new ApiError(400, "invalid_workspace_export_sensitive_mode", `Invalid workspace export sensitive mode: ${trimmed}`);
}
+
+/**
+ * Whether a prompt request names an omnirush.ai model that runs only on this
+ * computer (its catalog `modes` without "box": Kimi). Such a chat is exempt
+ * from the required sandbox (box/service.ts beforePrompt).
+ */
+async function promptsNativeOnlyModel(config: ServerConfig, body: string | ArrayBuffer | undefined): Promise<boolean> {
+ if (body === undefined) return false;
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(typeof body === "string" ? body : new TextDecoder().decode(body));
+ } catch {
+ return false;
+ }
+ const model = isRecord(parsed) && isRecord(parsed.model) ? parsed.model : null;
+ if (!model || model.providerID !== "omnirush" || typeof model.modelID !== "string") return false;
+ const entry = (await readOmniRushModelCatalog(config)).find((candidate) => candidate.id === model.modelID);
+ return Boolean(entry?.modes) && !modelAllowedIn(entry, "box") && modelAllowedIn(entry, "native");
+}