Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat: per-model sandbox start from the server

ogsamrat5401bc3eab74
diff --git a/apps/app/src/app/lib/omnirush-server.ts b/apps/app/src/app/lib/omnirush-server.ts
index 68b77c62..d98116dc 100644
--- a/apps/app/src/app/lib/omnirush-server.ts
+++ b/apps/app/src/app/lib/omnirush-server.ts
@@ -540,6 +540,12 @@ export type OmniRushWorkspaceBox = {
setup?: OmniRushWorkspaceBoxSetup | null;
/** Asked for one chat: it started on this computer before the sandbox was required and stays here. */
chatKept?: boolean;
+ /** How a new chat on each model starts (the server's local_box.model_start). Older servers: absent or null. */
+ modelStart?: Record<string, { start: "native" | "box"; switchable: boolean }> | null;
+ /** The local_box policy revision new chats pin. Older servers: absent. */
+ revision?: string | null;
+ /** Asked for one chat: its pin (where it runs, the revision it started under); null before its first prompt. */
+ chatPin?: { box: boolean; revision: string | null } | null;
/** Servers in the sandbox open at the same port on this computer's 127.0.0.1 (Docker/Podman). Older servers: absent. */
ports?: Array<{ port: number; url: string; line: string }>;
};
diff --git a/apps/app/src/react-app/domains/session/chat/new-task-composer.tsx b/apps/app/src/react-app/domains/session/chat/new-task-composer.tsx
index f38ea00e..ac8ec9bd 100644
--- a/apps/app/src/react-app/domains/session/chat/new-task-composer.tsx
+++ b/apps/app/src/react-app/domains/session/chat/new-task-composer.tsx
@@ -436,7 +436,7 @@ export function NewTaskComposer(props: NewTaskComposerProps) {
<ReactSessionComposer
runModeControl={<WorkspaceRunModeMenu client={workspaceClient} workspaceId={workspaceId} busy={props.busy} />}
fullPermissionsControl={<FullPermissionsToggle client={workspaceClient} workspaceId={workspaceId} />}
- sandboxControl={<SandboxStatusChip client={workspaceClient} workspaceId={workspaceId} onOpenSettings={() => context?.onOpenSettingsSection?.("sandbox")} />}
+ sandboxControl={<SandboxStatusChip client={workspaceClient} workspaceId={workspaceId} model={context?.selectedModel?.providerID === "omnirush" ? context.selectedModel.modelID : null} onOpenSettings={() => context?.onOpenSettingsSection?.("sandbox")} />}
subagentModelControl={<SubagentModelMenu client={workspaceClient} chatModel={context?.selectedModel?.providerID === "omnirush" ? context.selectedModel.modelID : null} />}
voiceClient={workspaceClient}
voiceWorkspaceId={workspaceId}
diff --git a/apps/app/src/react-app/domains/session/surface/composer/sandbox-status-chip.tsx b/apps/app/src/react-app/domains/session/surface/composer/sandbox-status-chip.tsx
index 2ebcc6a1..b3f4d582 100644
--- a/apps/app/src/react-app/domains/session/surface/composer/sandbox-status-chip.tsx
+++ b/apps/app/src/react-app/domains/session/surface/composer/sandbox-status-chip.tsx
@@ -2,12 +2,17 @@
import { useState } from "react";
import { Box, X } from "lucide-react";
+import { toast } from "@/components/ui/sonner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { linuxSandboxView, useLinuxSandbox, type LinuxSandboxClient, type LinuxSandboxView } from "@/react-app/domains/settings/linux-sandbox";
type Props = {
client: LinuxSandboxClient | null;
workspaceId: string | null;
+ /** The open chat (null: a new chat); a started chat keeps where it runs. */
+ sessionId?: string | null;
+ /** The chat's model (omnirush.ai id): its start decides whether the sandbox can be switched for it. */
+ model?: string | null;
/** Opens Settings > General at the sandbox card. */
onOpenSettings?: () => void;
};
@@ -28,14 +33,22 @@ const DOT: Record<LinuxSandboxView["tone"], string> = {
*/
export function SandboxStatusChip(props: Props) {
if (!props.client || !props.workspaceId) return null;
- return <SandboxChip key={props.workspaceId} client={props.client} workspaceId={props.workspaceId} onOpenSettings={props.onOpenSettings} />;
+ return <SandboxChip key={props.workspaceId} client={props.client} workspaceId={props.workspaceId} sessionId={props.sessionId ?? null} model={props.model ?? null} onOpenSettings={props.onOpenSettings} />;
}
-function SandboxChip(props: { client: LinuxSandboxClient; workspaceId: string; onOpenSettings?: () => void }) {
- const sandbox = useLinuxSandbox(props.client, props.workspaceId, { fresh: false });
+/** "Turning the sandbox on applies to new chats" note for a chat that already started (it keeps where it runs). */
+export const PINNED_CHAT_TOGGLE_NOTE = "New chats in this project use the sandbox. This chat keeps running where it started.";
+
+function SandboxChip(props: { client: LinuxSandboxClient; workspaceId: string; sessionId: string | null; model: string | null; onOpenSettings?: () => void }) {
+ const sandbox = useLinuxSandbox(props.client, props.workspaceId, { fresh: false, sessionId: props.sessionId });
const [offerDismissed, setOfferDismissed] = useState(false);
const box = sandbox.box;
if (!box) return null;
+ // The server's start for this model (local_box.model_start): a model that cannot be switched (box-only,
+ // native-only) shows no sandbox toggle at all; a started chat keeps its pin.
+ const start = props.model ? box.modelStart?.[props.model] ?? null : null;
+ if (start && !start.switchable) return null;
+ const pinned = Boolean(box.chatPin);
const chip = "flex h-9 max-h-9 shrink-0 items-center gap-1.5 rounded-md px-2.5 text-sm text-gray-10 transition-colors hover:bg-gray-3 hover:text-gray-12";
if (!box.on && sandbox.pending !== "on") {
@@ -69,7 +82,7 @@ function SandboxChip(props: { client: LinuxSandboxClient; workspaceId: string; o
<Tooltip>
<TooltipTrigger
render={
- <button type="button" className={`${chip} h-8 max-h-8 pr-1.5`} onClick={() => void sandbox.setEnabled(true)} data-testid="sandbox-offer-accept" />
+ <button type="button" className={`${chip} h-8 max-h-8 pr-1.5`} onClick={() => { void sandbox.setEnabled(true); if (pinned) toast(PINNED_CHAT_TOGGLE_NOTE); }} data-testid="sandbox-offer-accept" />
}
>
<Box className="size-4" aria-hidden />
diff --git a/apps/app/src/react-app/domains/session/surface/session-surface.tsx b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
index 34d96f5b..06dc9d9d 100644
--- a/apps/app/src/react-app/domains/session/surface/session-surface.tsx
+++ b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
@@ -3679,7 +3679,7 @@ export function SessionSurface(props: SessionSurfaceProps) {
<ReactSessionComposer
runModeControl={<WorkspaceRunModeMenu client={props.client} workspaceId={props.workspaceId} busy={chatStreaming || preparingCloudTools || Boolean(props.activePermission || props.activeQuestion)} />}
fullPermissionsControl={<FullPermissionsToggle client={props.client} workspaceId={props.workspaceId} />}
- sandboxControl={<SandboxStatusChip client={props.client} workspaceId={props.workspaceId} onOpenSettings={() => props.onOpenSettingsSection?.("sandbox")} />}
+ sandboxControl={<SandboxStatusChip client={props.client} workspaceId={props.workspaceId} sessionId={props.sessionId ?? null} model={props.selectedModel?.providerID === "omnirush" ? props.selectedModel.modelID : null} onOpenSettings={() => props.onOpenSettingsSection?.("sandbox")} />}
subagentModelControl={<SubagentModelMenu client={props.client} chatModel={props.selectedModel?.providerID === "omnirush" ? props.selectedModel.modelID : null} />}
voiceClient={props.client}
voiceWorkspaceId={props.workspaceId}
diff --git a/apps/app/tests/sandbox-chip-model-start.test.tsx b/apps/app/tests/sandbox-chip-model-start.test.tsx
new file mode 100644
index 00000000..d7cbbddf
--- /dev/null
+++ b/apps/app/tests/sandbox-chip-model-start.test.tsx
@@ -0,0 +1,68 @@
+/** @jsxImportSource react */
+import { afterEach, expect, mock, test } from "bun:test";
+import { GlobalRegistrator } from "@happy-dom/global-registrator";
+import { act, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+
+const toasts: string[] = [];
+mock.module("@/components/ui/sonner", () => ({ toast: (message: string) => toasts.push(message) }));
+
+if (typeof globalThis.window === "undefined" || typeof globalThis.document === "undefined") {
+ GlobalRegistrator.register({ url: "http://localhost/" });
+}
+Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });
+
+const { SandboxStatusChip, PINNED_CHAT_TOGGLE_NOTE } = await import("../src/react-app/domains/session/surface/composer/sandbox-status-chip");
+
+// Backend #505 at level "offer": the box is off until the person turns it on; per-model starts.
+function fakeClient(chatPin: { box: boolean; revision: string | null } | null = null) {
+ const modes: Array<string | null> = [];
+ const box = {
+ mode: null, serverDefault: "offer", on: false, source: "server", offer: true, error: null, state: "off",
+ modelStart: { "gpt-6-astra": { start: "native", switchable: true }, "kimi-k3.1-pro": { start: "native", switchable: false } },
+ revision: "lb1:5050a1b2c3d4", chatPin,
+ };
+ const client = {
+ getWorkspaceBox: async () => box,
+ setWorkspaceBox: async (_id: string, mode: "on" | "off" | null) => { modes.push(mode); return { ...box, on: mode === "on" }; },
+ setWorkspaceBoxBackend: async () => box,
+ resetWorkspaceBox: async () => box,
+ retryWorkspaceBox: async () => box,
+ };
+ return { client: client as never, modes };
+}
+
+const mounted: { root: Root; container: HTMLElement }[] = [];
+async function mount(ui: ReactNode) {
+ const container = document.createElement("div");
+ document.body.append(container);
+ const root = createRoot(container);
+ mounted.push({ root, container });
+ await act(async () => root.render(ui));
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });
+ return container;
+}
+afterEach(async () => {
+ for (const { root, container } of mounted.splice(0)) {
+ await act(async () => root.unmount());
+ container.remove();
+ }
+ toasts.length = 0;
+});
+
+test("a model the server says cannot be switched shows no sandbox toggle; a switchable one shows the offer (off by default)", async () => {
+ const kimi = await mount(<SandboxStatusChip client={fakeClient().client} workspaceId="ws" model="kimi-k3.1-pro" />);
+ expect(kimi.querySelector('[data-testid="sandbox-offer-accept"]')).toBeNull();
+ expect(kimi.textContent).toBe("");
+ const astra = await mount(<SandboxStatusChip client={fakeClient().client} workspaceId="ws" model="gpt-6-astra" />);
+ expect(astra.querySelector('[data-testid="sandbox-offer-accept"]')?.textContent).toContain("Use sandbox");
+});
+
+test("turning the sandbox on in a started chat applies to new chats; this chat keeps where it started", async () => {
+ const { client, modes } = fakeClient({ box: false, revision: "lb1:5050a1b2c3d4" });
+ const container = await mount(<SandboxStatusChip client={client} workspaceId="ws" sessionId="ses_started" model="gpt-6-astra" />);
+ await act(async () => { container.querySelector<HTMLElement>('[data-testid="sandbox-offer-accept"]')!.click(); });
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });
+ expect(modes).toEqual(["on"]);
+ expect(toasts).toEqual([PINNED_CHAT_TOGGLE_NOTE]);
+});
diff --git a/apps/server/src/box/box-required-service.test.ts b/apps/server/src/box/box-required-service.test.ts
index 90f62026..baa77b4d 100644
--- a/apps/server/src/box/box-required-service.test.ts
+++ b/apps/server/src/box/box-required-service.test.ts
@@ -168,6 +168,41 @@ describe("required sandbox: the desktop's projects", () => {
expect(JSON.parse(await readFile(join(home, DESKTOP_PROJECTS_FILE), "utf8")).native_chats).toEqual(["ses_kimi_new"]);
});
+ test("offer level (backend #505): a chat pins where it started and its revision; a box chat is refused when its project's box goes off; a native chat stays native when it goes on", async () => {
+ const stateDir = await temp("state");
+ const home = await temp("boxhome");
+ const root = await temp("project");
+ const workspace: BoxWorkspace = { id: "ws_pin", path: root, workspaceType: "local" };
+ const LB = { default: "offer", model_start: { "gpt-6-astra": { start: "native", switchable: true }, "kimi-k3.1-pro": { start: "native", switchable: false } }, revision: "lb1:5050a1b2c3d4" };
+ rememberServerDefault(stateDir, { local_box: LB });
+ const settings: Settings = new Map();
+ const boxes = service({ stateDir, workspaces: [workspace], settings, env: { OMNIRUSH_BOX_HOME: home } });
+ const frozen: string[] = [];
+ boxes.ensure = async () => ((await boxes.status(workspace)).on ? fakeRun(root, frozen) : null);
+ // Offer: the project's box is off until the person turns it on.
+ expect(await boxes.beforePrompt("ses_native1", workspace)).toBeNull();
+ expect(boxes.chatPin("ses_native1")).toEqual({ box: false, revision: "lb1:5050a1b2c3d4" });
+ settings.set("ws_pin", { mode: "on", offered: true });
+ await boxes.beforePrompt("ses_box1", workspace);
+ expect(boxes.chatPin("ses_box1")).toEqual({ box: true, revision: "lb1:5050a1b2c3d4" });
+ // Turned on since: the native chat stays native (no checkpoint, kept_old_chat).
+ await boxes.beforePrompt("ses_native1", workspace, { turnsBefore: 1 });
+ expect(frozen).toEqual(["ses_box1 turn-1"]);
+ expect(await boxes.planOutcome("ses_native1", workspace)).toMatchObject({ native: true, reason: "kept_old_chat" });
+ // Turned off since: the box chat is refused, never moved here.
+ settings.set("ws_pin", { mode: "off", offered: true });
+ expect(await boxes.pinnedBoxGone("ses_box1", workspace)).toBe(true);
+ expect(await boxes.pinnedBoxGone("ses_native1", workspace)).toBe(false);
+ // The status names the server's starts, the revision and the chat's pin.
+ const status = await boxes.status(workspace, { sessionId: "ses_box1" });
+ expect(status.modelStart?.["kimi-k3.1-pro"]).toEqual({ start: "native", switchable: false });
+ expect(status.revision).toBe("lb1:5050a1b2c3d4");
+ expect(status.chatPin).toEqual({ box: true, revision: "lb1:5050a1b2c3d4" });
+ // A new service (app restart) reads the pins back.
+ const again = service({ stateDir, workspaces: [workspace], settings, env: { OMNIRUSH_BOX_HOME: home } });
+ expect(again.chatPin("ses_box1")?.box).toBe(true);
+ });
+
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/box.test.ts b/apps/server/src/box/box.test.ts
index 0b1a7786..2c1834b1 100644
--- a/apps/server/src/box/box.test.ts
+++ b/apps/server/src/box/box.test.ts
@@ -346,7 +346,8 @@ describe("box service", () => {
boxes.ensure = async () => (on ? run : null);
return boxes;
};
- // Two turns with the box off, a steer (not captured), then the box turned on mid-chat: turn-1 comes before turn 3.
+ // Two turns with the box off, a steer (not captured), then the box turned on mid-chat: one pin per
+ // chat (2026-10-24), it stays on this machine and takes no checkpoint.
let boxes = start();
await boxes.beforePrompt("ses_turns_a1", workspace);
await boxes.beforePrompt("ses_turns_a1", workspace);
@@ -354,12 +355,12 @@ describe("box service", () => {
on = true;
await boxes.beforePrompt("ses_turns_a1", workspace);
await boxes.beforePrompt("ses_turns_a1", workspace);
- expect(frozen.splice(0)).toEqual(["ses_turns_a1 turn-1 3", "ses_turns_a1 turn-2 4"]);
- // Reopened after a restart with 4 native turns: before turns 5 and 6.
+ expect(frozen.splice(0)).toEqual([]);
+ // Reopened after a restart with 4 native turns: it stays there too.
boxes = start();
await boxes.beforePrompt("ses_turns_b1", workspace, { turnsBefore: 4 });
await boxes.beforePrompt("ses_turns_b1", workspace);
- expect(frozen.splice(0)).toEqual(["ses_turns_b1 turn-1 5", "ses_turns_b1 turn-2 6"]);
+ expect(frozen.splice(0)).toEqual([]);
// Saved checkpoints go on numbering the files; the chat's turn comes from the engine's count.
await mkdir(join(stateDir, "sandbox", "snapshots", "ses_turns_c1"), { recursive: true });
await writeFile(join(boxes.snapshotsDir, "ses_turns_c1", "turn-7.json"), "{}");
@@ -367,7 +368,7 @@ describe("box service", () => {
expect(frozen.splice(0)).toEqual(["ses_turns_c1 turn-8 3"]);
});
- test("a reopened chat that ran on this machine stays there when only the server's default turned the box on", async () => {
+ test("a reopened chat that ran on this machine stays there, whoever turned the box on", async () => {
const stateDir = await temp("state");
const home = await temp("boxhome");
const root = await temp("project");
@@ -398,15 +399,16 @@ describe("box service", () => {
await boxes.beforePrompt("ses_native_b1", workspace, { turnsBefore: 3 });
expect(frozen.splice(0)).toEqual(["ses_native_n1 turn-1", "ses_native_b1 turn-2"]);
expect(await listed()).toEqual(["ses_native_r1"]);
- // The user turns the project on: the chat moves to the box.
+ // The user turns the project on: one pin per chat (2026-10-24), the chat stays on this machine;
+ // new chats go in the box.
boxes.ensure = async () => run;
await boxes.setMode(workspace, "on");
- expect(await listed()).toEqual([]);
await boxes.beforePrompt("ses_native_r1", workspace);
- expect(frozen.splice(0)).toEqual(["ses_native_r1 turn-1"]);
- // Turned on by the user before it was reopened: it moves at once.
+ expect(frozen.splice(0)).toEqual([]);
+ expect(await listed()).toEqual(["ses_native_r1"]);
+ // Reopened after the user turned it on: it stays there too.
await boxes.beforePrompt("ses_native_r2", workspace, { turnsBefore: 4 });
- expect(frozen.splice(0)).toEqual(["ses_native_r2 turn-1"]);
+ expect(frozen.splice(0)).toEqual([]);
});
test("the server's default turned on while the app runs: chats that ran on this machine stay there, new ones go in the box", async () => {
diff --git a/apps/server/src/box/launch.ts b/apps/server/src/box/launch.ts
index 30865a68..73e2e893 100644
--- a/apps/server/src/box/launch.ts
+++ b/apps/server/src/box/launch.ts
@@ -89,10 +89,20 @@ export function serverRequired(stateDir: string): { required: boolean; fallback:
* meaning (required false; prefetch) are no change, so boxes are not planned
* again for them.
*/
+/** The server's local_box as last seen (model_start, revision, ...), or null. */
+export function serverLocalBox(stateDir: string): { model_start?: unknown; revision?: unknown } | null {
+ try {
+ const value: unknown = JSON.parse(readFileSync(path.join(stateDir, "box-server.json"), "utf8"));
+ return value && typeof value === "object" ? value : null;
+ } catch {
+ return null;
+ }
+}
+
export function rememberServerDefault(stateDir: string, capabilities: { local_box?: unknown } | null | undefined): boolean {
const block = capabilities?.local_box;
if (!block || typeof block !== "object") return false;
- const fields: { default?: unknown; max_turn_bytes?: unknown; backends?: unknown; required?: unknown; required_fallback?: unknown; setup?: unknown } = block;
+ const fields: { default?: unknown; max_turn_bytes?: unknown; backends?: unknown; required?: unknown; required_fallback?: unknown; setup?: unknown; model_start?: unknown; revision?: unknown } = block;
const value = isMode(fields.default) ? fields.default : "off";
const backends = Array.isArray(fields.backends) ? fields.backends.filter((b): b is string => typeof b === "string").slice(0, 32) : null;
const required = fields.required === true;
@@ -105,7 +115,11 @@ export function rememberServerDefault(stateDir: string, capabilities: { local_bo
// The required keys are written only when the server requires the sandbox, so the file is
// exactly what it was before them otherwise (the CLI's requiredBlock does the same).
const extra = required ? { required, required_fallback: fallback, prefetch: setup.prefetch === true } : {};
- writeFileSync(path.join(stateDir, "box-server.json"), JSON.stringify({ default: value, max_turn_bytes: fields.max_turn_bytes ?? null, backends, ...extra, at: Date.now() }), { mode: 0o600 });
+ // How a new chat on each model starts (model_start, with the policy's revision), as the server said (model-modes/ serverModelStart).
+ const starts = fields.model_start && typeof fields.model_start === "object" && !Array.isArray(fields.model_start)
+ ? { model_start: Object.fromEntries(Object.entries(fields.model_start).slice(0, 64)), ...(typeof fields.revision === "string" ? { revision: fields.revision.slice(0, 32) } : {}) }
+ : {};
+ writeFileSync(path.join(stateDir, "box-server.json"), JSON.stringify({ default: value, max_turn_bytes: fields.max_turn_bytes ?? null, backends, ...extra, ...starts, at: Date.now() }), { mode: 0o600 });
} catch { /* best effort */ }
return before !== JSON.stringify([value, backends, required, required ? fallback : null]);
}
diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.ts
index 26a7d5a6..7ad3cfde 100644
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@ -21,7 +21,7 @@
*
* Not to be confused with the OpenWork worker sandbox (`sandboxBackend`).
*/
-import { existsSync } from "node:fs";
+import { existsSync, readFileSync } from "node:fs";
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import { join } from "node:path";
@@ -33,7 +33,8 @@ import type { BoxEndpoint } from "./client.js";
import { hostBuilds, hostBuildsNotice, hostBuildThings, hostRules } from "./host-builds.js";
import { detectStack, imageFor, type BoxImage } from "./images.js";
import { portLine } from "./ports.js";
-import { askedBackend, boxRun, planBox, pullActivityAt, pullLog, pullMarker, pulling, pullInBackground, setupWait, resolveMode, saveBackend, serverBackends, serverDefault, serverRequired, shimsDir, type BoxRun, type ProjectBoxMode, type ServerBoxDefault } from "./launch.js";
+import { writeFileAtomic } from "../atomic-write.js";
+import { askedBackend, boxRun, planBox, pullActivityAt, pullLog, pullMarker, pulling, pullInBackground, setupWait, resolveMode, saveBackend, serverBackends, serverDefault, serverLocalBox, serverRequired, shimsDir, type BoxRun, type ProjectBoxMode, type ServerBoxDefault } from "./launch.js";
import { desktopText, hostOnlyProject, requiredLaunch, shadowsApply, shadowsNotice, type RequiredFallback } from "./required.js";
import { cachedWindowsChecks, classifySetup, linuxAllow, resumeWinSetup, saveSetupState, setupState, windowsInstall, windowsRestart, windowsUpdate, type BoxSetup } from "./setup.js";
import type { BoxInstallLogPaths } from "./install-log.js";
@@ -62,6 +63,12 @@ export type BoxCaptureInfo = {
export type BoxWorkspace = { id: string; path: string; directory?: string; workspaceType: string };
export type BoxStatus = {
+ /** The server's start for a new chat on each model (local_box.model_start); null from an older server. */
+ modelStart: Record<string, { start: "native" | "box"; switchable: boolean }> | null;
+ /** The local_box policy revision new chats pin. */
+ revision: string | null;
+ /** This chat's pin (asked for one chat): where it runs and the revision it started under; null before its first prompt. */
+ chatPin: { box: boolean; revision: string | null } | null;
/** The project's own choice (null: the server's default). */
mode: ProjectBoxMode;
serverDefault: ServerBoxDefault;
@@ -221,6 +228,13 @@ export class BoxService {
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>();
+ /**
+ * Each chat's pin, from its first prompt: whether it runs in the box and the
+ * local_box policy revision it started under (model_start). A started chat
+ * never moves: a box chat whose project's box is turned off is refused
+ * (pinnedBoxGone), a chat that ran here stays here. Kept in chat-pins.json.
+ */
+ private pins: Map<string, { box: boolean; revision: string | null }> | null = null;
/** Chats whose box.plan event went out in this run. */
private readonly outcomeSent = new Set<string>();
private readonly home: string;
@@ -582,7 +596,12 @@ export class BoxService {
const needed = required === true;
const requiredText = needed ? { line: desktopText("required_line"), optOut: desktopText("opt_out_refused"), keptOldChat: desktopText("kept_old_chat") } : null;
const chatKept = Boolean(sessionId && this.nativeChats.has(sessionId));
- const base = { mode: settings.mode, serverDefault: server, on, source, offer, error: null, hostBuilds: gate, boxNotice: null, required: needed, requiredText, hostOnly, setup: null, chatKept, ports: [] as BoxStatus["ports"] };
+ // How a new chat on each model starts (the server's model_start, with its revision), and this chat's pin.
+ const localBox = serverLocalBox(this.options.stateDir);
+ const modelStart = localBox?.model_start && typeof localBox.model_start === "object" ? (localBox.model_start as BoxStatus["modelStart"]) : null;
+ const revision = typeof localBox?.revision === "string" ? localBox.revision : null;
+ const chatPin = sessionId ? this.chatPin(sessionId) : null;
+ const base = { mode: settings.mode, serverDefault: server, on, source, offer, error: null, hostBuilds: gate, boxNotice: null, required: needed, requiredText, hostOnly, setup: null, chatKept: chatKept || chatPin?.box === false, ports: [] as BoxStatus["ports"], modelStart, revision, chatPin };
const backendSetting = { ...askedBackend({ env: this.env, stateDir: this.options.stateDir }), choices: backendChoices() };
const setting = { value: backendSetting.backend, source: backendSetting.source, choices: backendSetting.choices };
if (workspace.workspaceType !== "local") return { ...base, on: false, offer: false, state: "off", runtime: null, backend: null, backendSetting: setting, image: null, progress: null, container: null, platform: this.platform, notice: "The sandbox is for folders on this computer." };
@@ -807,17 +826,25 @@ export class BoxService {
this.log("info", "box: a chat that ran on this machine stays there", { sessionId, turnsBefore, required: true });
}
const run = required && !this.nativeChats.has(sessionId) ? await this.waitForBox(workspace) : await this.ensure(workspace).catch(() => null);
- if (!run || run.native) return null;
+ if (!run || run.native) {
+ if (capture) await this.pin(sessionId, false);
+ return null;
+ }
// A chat with turns but no checkpoint ran on this machine (reopened, or started in this run before the
// server's default reached the app, or while the image downloaded): when only the server's default
// turned the box on, it goes on here (new chats get the box); a project turned on by its user moves it.
- if (capture && turnsSoFar > 0 && !this.nativeChats.has(sessionId) && !this.boxedChats.has(sessionId) && !this.turns.has(sessionId) && savedTurns(this.snapshotDir(sessionId)) === 0 && ["server", "buildathon", "required"].includes((await this.mode(workspace)).source)) {
+ // One pin per chat (2026-10-24): it stays here whoever turned the box on since.
+ if (capture && turnsSoFar > 0 && !this.nativeChats.has(sessionId) && !this.boxedChats.has(sessionId) && !this.turns.has(sessionId) && savedTurns(this.snapshotDir(sessionId)) === 0 && !this.chatPin(sessionId)?.box) {
this.nativeChats.set(sessionId, run.key);
await this.writeProjects();
this.log("info", "box: a chat that ran on this machine stays there", { sessionId, turnsBefore });
}
- if (this.nativeChats.has(sessionId) || !capture) return null;
+ if (this.nativeChats.has(sessionId) || !capture) {
+ if (capture) await this.pin(sessionId, false);
+ return null;
+ }
this.boxedChats.add(sessionId);
+ await this.pin(sessionId, true);
const turn = (this.turns.get(sessionId) ?? savedTurns(this.snapshotDir(sessionId))) + 1;
const started = Date.now();
try {
@@ -874,6 +901,48 @@ export class BoxService {
}
/** The chat's box.plan outcome, once per chat and app run (null after that, or for a folder not on this computer). */
+ private pinFile(): string {
+ return join(this.options.stateDir, "chat-pins.json");
+ }
+
+ private loadPins(): Map<string, { box: boolean; revision: string | null }> {
+ if (this.pins) return this.pins;
+ this.pins = new Map();
+ try {
+ const value: unknown = JSON.parse(readFileSync(this.pinFile(), "utf8"));
+ if (value && typeof value === "object") {
+ for (const [id, pin] of Object.entries(value)) {
+ if (pin && typeof pin === "object" && typeof (pin as { box?: unknown }).box === "boolean") {
+ const revision = (pin as { revision?: unknown }).revision;
+ this.pins.set(id, { box: (pin as { box: boolean }).box, revision: typeof revision === "string" ? revision : null });
+ }
+ }
+ }
+ } catch { /* none yet */ }
+ return this.pins;
+ }
+
+ /** A chat's pin ({ box, revision }), or null before its first prompt. */
+ chatPin(sessionId: string): { box: boolean; revision: string | null } | null {
+ return this.loadPins().get(sessionId) ?? null;
+ }
+
+ private async pin(sessionId: string, box: boolean): Promise<void> {
+ const pins = this.loadPins();
+ if (pins.has(sessionId)) return;
+ const revision = serverLocalBox(this.options.stateDir)?.revision;
+ pins.set(sessionId, { box, revision: typeof revision === "string" ? revision : null });
+ while (pins.size > 4000) pins.delete(pins.keys().next().value!);
+ await writeFileAtomic(this.pinFile(), `${JSON.stringify(Object.fromEntries(pins))}\n`).catch(() => undefined);
+ }
+
+ /** Whether a chat pinned to the box would run on this computer now (its project's box turned off): its prompt is refused. */
+ async pinnedBoxGone(sessionId: string, workspace: BoxWorkspace): Promise<boolean> {
+ if (workspace.workspaceType !== "local" || !this.chatPin(sessionId)?.box) return false;
+ const mode = await this.mode(workspace).catch(() => null);
+ return Boolean(mode && !mode.on);
+ }
+
async planOutcome(sessionId: string, workspace: BoxWorkspace): Promise<BoxPlanOutcome | null> {
if (workspace.workspaceType !== "local" || this.outcomeSent.has(sessionId)) return null;
this.outcomeSent.add(sessionId);
diff --git a/apps/server/src/model-modes/PARITY.sha256 b/apps/server/src/model-modes/PARITY.sha256
index 9e1743c2..47ae2f65 100644
--- a/apps/server/src/model-modes/PARITY.sha256
+++ b/apps/server/src/model-modes/PARITY.sha256
@@ -1,4 +1,4 @@
# Per-model modes (native / box) and the box header: the same files in omnirush-cli (src/model-modes/) and omnirush-gui (apps/server/src/model-modes/).
# A change to one must be ported to the other and this list updated in both.
-a3b32b5e5abff4fb47c2a4c49dea6059cf9c626e39777a8ee98eab94096f833c model-modes.mjs
-84254f298a54a1e248791f26c22eef5cf975730401fa7ef2838f21c6ccbc0f25 model-modes.d.mts
+609bbc9cb508b4f79295e0b2f1f4707bd1facbee83835d5db7eac02fa088f43b model-modes.mjs
+ef8a96d1e71ea3f5f3ab7a96796d042c009d90cc2896e7132b8dfc4486540699 model-modes.d.mts
diff --git a/apps/server/src/model-modes/model-modes.d.mts b/apps/server/src/model-modes/model-modes.d.mts
index fa449841..becff60e 100644
--- a/apps/server/src/model-modes/model-modes.d.mts
+++ b/apps/server/src/model-modes/model-modes.d.mts
@@ -15,3 +15,5 @@ export function modelForMode<T extends ModeCatalogEntry>(catalog: readonly T[] |
export function modeSwitchNote(from: string, to: string, mode: ModelMode): string;
export function notInModeMessage(mode?: ModelMode | null): string;
export function modeHeaders(box: unknown): Record<string, string>;
+export type ServerModelStart = { start: ModelMode; switchable: boolean; revision: string | null };
+export function serverModelStart(localBox: unknown, modelId: string | null | undefined): ServerModelStart | null;
diff --git a/apps/server/src/model-modes/model-modes.mjs b/apps/server/src/model-modes/model-modes.mjs
index 2c957b15..79e5d03d 100644
--- a/apps/server/src/model-modes/model-modes.mjs
+++ b/apps/server/src/model-modes/model-modes.mjs
@@ -75,3 +75,20 @@ export function notInModeMessage(mode = null) {
export function modeHeaders(box) {
return box ? { [BOX_HEADER]: "1" } : {};
}
+
+/**
+ * How a new chat on `modelId` starts, as the server resolved it
+ * (GET /collect/capabilities local_box.model_start, with the policy's
+ * `revision`): { start: "native" | "box", switchable, revision }, or null
+ * when the server does not say (an older server, a model it does not list):
+ * the caller then decides from the model's modes and the level. A chat pins
+ * what it started with (its model, where it ran, the revision) and never
+ * moves; a different choice is a new chat.
+ */
+export function serverModelStart(localBox, modelId) {
+ const table = localBox && typeof localBox === "object" ? localBox.model_start : null;
+ const entry = table && typeof table === "object" && typeof modelId === "string" ? table[modelId] : null;
+ if (!entry || typeof entry !== "object" || (entry.start !== "native" && entry.start !== "box")) return null;
+ const revision = typeof localBox.revision === "string" && /^lb1:[0-9a-f]{12}$/.test(localBox.revision) ? localBox.revision : null;
+ return { start: entry.start, switchable: entry.switchable === true, revision };
+}
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 8f9bf438..2581a765 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -209,7 +209,8 @@ import { omnirushMcpPolicyPluginPath } from "./omnirush-extensions-plugin-path.j
import { isOmniRushUiMcpRegistryEntry } from "./omnirush-ui-mcp-command.js";
import { describeIgnored, type McpAllowEntry } from "./mcp-allow/mcp-allow.mjs";
import { omnirushModelWantsReasoningSummary, readOmniRushModelCatalog } from "./omnirush-model-catalog.js";
-import { modelAllowedIn, modelModes, projectMode } from "./model-modes/model-modes.mjs";
+import { modelAllowedIn, modelModes, projectMode, serverModelStart } from "./model-modes/model-modes.mjs";
+import { serverLocalBox } from "./box/launch.js";
import {
SUBAGENT_MODEL_FALLBACK_TRACE,
readSubagentModelSetting,
@@ -2127,6 +2128,8 @@ export async function proxyOpencodeV2Request(input: {
// A reopened chat's turns before this prompt: its turn numbers (uploads and box checkpoints) carry on from them.
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.
+ // One pin per chat: a chat that runs in the box is not moved to this computer when its project's box is off.
+ if (promptDispatch && sessionId && await boxServiceFor(input.config).pinnedBoxGone(sessionId, input.workspace)) throw new ApiError(409, "chat_pinned_box", PINNED_BOX_MESSAGE);
const boxInfo = promptDispatch && sessionId
? await boxServiceFor(input.config).beforePrompt(sessionId, input.workspace, { capture: Boolean(uploadedSessionId && engine), turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
: null;
@@ -2566,6 +2569,7 @@ export async function proxyOpencodeRequest(input: {
const turnsBefore = capture && captured && uploadedSessionId && workspace && !steer && isUploadPromptDispatch(method, proxyPath)
? await turnsBeforeCapture(capture, uploadedSessionId, engineTarget(baseUrl, headers, search))
: 0;
+ if (workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath) && await boxServiceFor(input.config).pinnedBoxGone(uploadedSessionId, workspace)) throw new ApiError(409, "chat_pinned_box", PINNED_BOX_MESSAGE);
const boxInfo = workspace && uploadedSessionId && isUploadPromptDispatch(method, proxyPath)
? await boxServiceFor(input.config).beforePrompt(uploadedSessionId, workspace, { capture: captured && !steer, turnsBefore, nativeModel: await promptsNativeOnlyModel(input.config, body) })
: null;
@@ -7868,10 +7872,14 @@ function parseWorkspaceExportSensitiveMode(input: string | null): WorkspaceExpor
throw new ApiError(400, "invalid_workspace_export_sensitive_mode", `Invalid workspace export sensitive mode: ${trimmed}`);
}
+const PINNED_BOX_MESSAGE = "This chat runs in the sandbox. Turn the sandbox back on for this project, or start a new chat.";
+
/**
- * 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).
+ * Whether a prompt request names an omnirush.ai model whose new chats start on
+ * this computer and cannot be switched: the server's local_box.model_start
+ * when it says (start "native", not switchable), else the catalog `modes`
+ * without "box" (Kimi). Such a chat is exempt from the box
+ * (box/service.ts beforePrompt).
*/
async function promptsNativeOnlyModel(config: ServerConfig, body: string | ArrayBuffer | undefined): Promise<boolean> {
if (body === undefined) return false;
@@ -7883,6 +7891,8 @@ async function promptsNativeOnlyModel(config: ServerConfig, body: string | Array
}
const model = isRecord(parsed) && isRecord(parsed.model) ? parsed.model : null;
if (!model || model.providerID !== "omnirush" || typeof model.modelID !== "string") return false;
+ const start = serverModelStart(serverLocalBox(runtimeStorageDir(config)), model.modelID);
+ if (start) return start.start === "native" && !start.switchable;
const entry = (await readOmniRushModelCatalog(config)).find((candidate) => candidate.id === model.modelID);
return Boolean(entry?.modes) && !modelAllowedIn(entry, "box") && modelAllowedIn(entry, "native");
}