Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: replan a box on a backend the server stops allowing

ogsamrat6b40df0871d6
diff --git a/apps/server/src/box/box.test.ts b/apps/server/src/box/box.test.ts
index 4be1368b..3aba9ea2 100644
--- a/apps/server/src/box/box.test.ts
+++ b/apps/server/src/box/box.test.ts
@@ -6,7 +6,7 @@ import { join } from "node:path";
import { boxKey, containerName, containerRoot, createArgs, credentialPath, filterChanges, helperPath, installShell, parseDiff, parseSize, rt, setToolsRoot, singleFileTar, wslPath } from "./box.js";
import { readBoxSettings } from "./desktop.js";
import { detectStack, imageFor } from "./images.js";
-import { engineConfig, gcInBackground, mapToBox, rememberServerDefault, resolveMode, serverDefault } from "./launch.js";
+import { engineConfig, gcInBackground, mapToBox, rememberServerDefault, resolveMode, serverDefault, type BoxRun } from "./launch.js";
import { DESKTOP_PROJECTS_FILE } from "./plugin-lib.js";
import { candidates, detectRuntime, explainFailure, probe, probeWsl, wslLauncher, type RunCommand } from "./runtime.js";
import { BoxService, type BoxWorkspace } from "./service.js";
@@ -262,6 +262,27 @@ describe("box service", () => {
expect(await none.engineBits()).toBeNull();
});
+ test("a box on a backend the server no longer allows is planned again", async () => {
+ const stateDir = await temp("state");
+ const root = await temp("project");
+ const workspace: BoxWorkspace = { id: "ws_a", path: root, workspaceType: "local" };
+ const boxes = service({ stateDir, workspaces: [workspace], settings: new Map(), env: { OMNIRUSH_BOX_HOME: await temp("boxhome") } });
+ const run: BoxRun = {
+ key: boxKey(root), container: "c", runtimeBin: "docker", runtimeArgs: [], backend: "docker", exec: null, root, native: false, box: null,
+ ready: async () => null, label: () => null, setTurn: () => {}, freeze: async () => null,
+ };
+ const projects = boxes["projects"];
+ projects.set(boxKey(root), { run, notice: null, planning: null, nextPlanAt: Date.now() + 60_000 });
+ rememberServerDefault(stateDir, { local_box: { default: "on", backends: ["docker", "podman"] } });
+ await boxes.serverBackendsChanged();
+ expect(projects.get(boxKey(root))?.run).toBe(run);
+ expect(await boxes.listedProjects()).toEqual([boxKey(root)]);
+ rememberServerDefault(stateDir, { local_box: { default: "on", backends: ["podman"] } });
+ await boxes.serverBackendsChanged();
+ expect(projects.get(boxKey(root))).toMatchObject({ run: null, nextPlanAt: 0 });
+ expect(await boxes.listedProjects()).toEqual([]);
+ });
+
test("a remote workspace never gets a box", async () => {
const stateDir = await temp("state");
const workspace: BoxWorkspace = { id: "ws_r", path: "/remote", workspaceType: "remote" };
diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.ts
index 8e26de8f..cc57b5a1 100644
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@ -187,6 +187,22 @@ export class BoxService {
return saved;
}
+ /**
+ * The server's backends allowlist changed (box-server.json): a project whose box runs on a
+ * backend it no longer allows is planned again (its chats go on natively until then).
+ */
+ async serverBackendsChanged(): Promise<void> {
+ const allow = serverBackends(this.options.stateDir);
+ this.alternatives = null;
+ for (const project of this.projects.values()) {
+ if (!project.run || !allow || allow.includes(project.run.backend)) continue;
+ project.run = null;
+ project.notice = null;
+ project.nextPlanAt = 0;
+ }
+ await this.writeProjects();
+ }
+
private async mode(workspace: BoxWorkspace) {
const settings = await this.options.readSettings(workspace.id).catch(() => ({ mode: null, offered: false }));
const server = this.serverDefault();
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 3adc7091..568b5abf 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -1154,6 +1154,7 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {
if (gatewayBroker.enabled) {
void gatewayBroker.sessionUploadCapabilities().then(async (capabilities) => {
if (!rememberServerDefault(runtimeStorageDir(config), capabilities)) return;
+ await boxes.serverBackendsChanged();
await applyBoxEngineConfig(config, "local_box_default");
await boxes.ensureAll();
}).catch(() => undefined);