Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: failed box start reports its fallback

ogsamratc05391086655
diff --git a/apps/server/src/box/box-required-service.test.ts b/apps/server/src/box/box-required-service.test.ts
index 7a40fbbd..60da7f62 100644
--- a/apps/server/src/box/box-required-service.test.ts
+++ b/apps/server/src/box/box-required-service.test.ts
@@ -94,6 +94,17 @@ describe("required sandbox: the desktop's projects", () => {
expect(await boxes.planOutcome("ses_req_none1", workspace)).toMatchObject({ native: true, source: "required", reason: "cannot_run", required: true, fallback: "native" });
});
+ test("a box that fails to start under required reports the fallback in force", async () => {
+ const stateDir = await temp("state");
+ const root = await temp("project");
+ const workspace: BoxWorkspace = { id: "ws_fail", path: root, workspaceType: "local" };
+ rememberServerDefault(stateDir, { local_box: { default: "on", required: true, required_fallback: "native_uncounted" } });
+ const boxes = service({ stateDir, workspaces: [workspace], env: { OMNIRUSH_BOX_HOME: await temp("boxhome"), ...NO_RUNTIME } });
+ const projects: Map<string, unknown> = Reflect.get(boxes, "projects");
+ projects.set(boxKey(root), { run: { ...fakeRun(root, []), native: true }, notice: null, planning: null, nextPlanAt: Date.now() + 60_000, waitingImage: false });
+ expect(await boxes.planOutcome("ses_req_fail1", workspace)).toEqual({ native: true, source: "required", reason: "box_failed", required: true, fallback: "native_uncounted" });
+ });
+
test("a new chat goes in the box; a reopened native chat stays here without waiting (kept_old_chat)", async () => {
const stateDir = await temp("state");
const home = await temp("boxhome");
@@ -106,7 +117,7 @@ describe("required sandbox: the desktop's projects", () => {
expect(await boxes.beforePrompt("ses_req_old1", workspace, { turnsBefore: 3 })).toBeNull();
await boxes.beforePrompt("ses_req_new1", workspace);
expect(frozen).toEqual(["ses_req_new1 turn-1"]);
- expect(await boxes.planOutcome("ses_req_old1", workspace)).toEqual({ native: true, source: "chat", reason: "kept_old_chat", required: true, fallback: "native" });
+ expect(await boxes.planOutcome("ses_req_old1", workspace)).toEqual({ native: true, source: "chat", reason: "kept_old_chat", required: true });
expect(await boxes.planOutcome("ses_req_new1", workspace)).toEqual({ native: false, source: "required", reason: "box", required: true });
expect(JSON.parse(await readFile(join(home, DESKTOP_PROJECTS_FILE), "utf8")).native_chats).toEqual(["ses_req_old1"]);
});
@@ -142,7 +153,7 @@ describe("required sandbox: the desktop's projects", () => {
rememberServerDefault(stateDir, { local_box: { default: "on", required: true } });
const workspace: BoxWorkspace = { id: "ws_env", path: root, workspaceType: "local" };
const off = service({ stateDir, workspaces: [workspace], env: { OMNIRUSH_BOX_HOME: await temp("boxhome"), OMNIRUSH_BOX: "0" } });
- expect(await off.planOutcome("ses_req_env1", workspace)).toEqual({ native: true, source: "env", reason: "env_off", required: true, fallback: "native" });
+ expect(await off.planOutcome("ses_req_env1", workspace)).toEqual({ native: true, source: "env", reason: "env_off", required: true });
const mac = await temp("macproject");
await mkdir(join(mac, "App.xcodeproj"));
@@ -151,7 +162,7 @@ describe("required sandbox: the desktop's projects", () => {
const status = await boxes.status(macWs);
expect(status).toMatchObject({ on: false, source: "host-only", required: true, hostOnly: { things: ["App.xcodeproj"] } });
expect(status.notice).toContain("only builds on Mac (App.xcodeproj)");
- expect(await boxes.planOutcome("ses_req_mac1", macWs)).toEqual({ native: true, source: "host-only", reason: "host_only", required: true, fallback: "native" });
+ expect(await boxes.planOutcome("ses_req_mac1", macWs)).toEqual({ native: true, source: "host-only", reason: "host_only", required: true });
// A Mac-built node_modules: required puts the chat in the box anyway (no host-builds gate).
const built = await temp("builtproject");
diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.ts
index d0685cb1..589ca132 100644
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@ -860,9 +860,11 @@ export class BoxService {
const mode = await this.mode(workspace).catch(() => null);
if (!mode) return { native: true, source: null, reason: "plan_failed" };
const { fallback } = this.required();
- // Required: every outcome says so; a chat that runs here names the fallback the server set.
+ // Required: every outcome says so; a chat that runs here by the fallback rule (the box cannot run, setup
+ // needed or declined, a box that failed to start) names the fallback the server set (as the CLI's launch event).
const required = mode.required ? { required: true as const } : {};
- const native = (reason: string, extra: Partial<BoxPlanOutcome> = {}): BoxPlanOutcome => ({ native: true, source: mode.source, reason, ...required, ...(mode.required ? { fallback } : {}), ...extra });
+ const byFallback = new Set(["cannot_run", "setup_needed", "setup_declined", "box_failed"]);
+ const native = (reason: string, extra: Partial<BoxPlanOutcome> = {}): BoxPlanOutcome => ({ native: true, source: mode.source, reason, ...required, ...(mode.required && byFallback.has(reason) ? { fallback } : {}), ...extra });
if (this.nativeChats.has(sessionId)) return native("kept_old_chat", { source: "chat" });
if (this.boxedChats.has(sessionId)) return { native: false, source: mode.source, reason: "box", ...required };
if (!mode.on) {