Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: find sandbox helpers before the first plan and skip needless engine reloads

ogsamrat0a5d38c77b02
diff --git a/apps/server/src/cli.ts b/apps/server/src/cli.ts
index e3ac43ca..03bec94c 100644
--- a/apps/server/src/cli.ts
+++ b/apps/server/src/cli.ts
@@ -68,6 +68,8 @@ if (!config.readOnly) {
// to an OS-assigned port on EADDRINUSE, and the engine's spawn-time env
// (OMNIRUSH_SERVER_URL) must point at the port that actually bound, not the
// requested one.
+// The Linux sandbox's helpers ship beside the engine (sidecars/box/): known before the server plans any box.
+if (process.env.OMNIRUSH_OPENCODE_BIN?.trim()) setToolsRoot(dirname(process.env.OMNIRUSH_OPENCODE_BIN.trim()));
const server = await startServer(config);
config.port = server.port;
const serverUrl = `http://${config.host === "0.0.0.0" ? "127.0.0.1" : config.host}:${server.port}`;
@@ -82,8 +84,6 @@ if (!config.opencodeBaseUrl && process.env.OMNIRUSH_MANAGE_OPENCODE === "1") {
// Server-managed config file: the engine re-reads it from disk on every
// instance rebuild, and keepOmniRushRuntimeConfigFileFresh synchronizes it
// on every runtime-DB write — so disposes always pick up current state.
- // The Linux sandbox's helpers ship beside the engine (sidecars/box/); the config names its shell.
- if (process.env.OMNIRUSH_OPENCODE_BIN?.trim()) setToolsRoot(dirname(process.env.OMNIRUSH_OPENCODE_BIN.trim()));
const { path: runtimeConfigPath } = await writeOmniRushRuntimeConfigFile(config);
keepOmniRushRuntimeConfigFileFresh(config);
const managedOpencodeCwd = process.env.OMNIRUSH_MANAGED_OPENCODE_CWD?.trim() || workspace.path;
diff --git a/apps/server/src/embedded.ts b/apps/server/src/embedded.ts
index 8e0f231a..0487d0e3 100644
--- a/apps/server/src/embedded.ts
+++ b/apps/server/src/embedded.ts
@@ -223,6 +223,9 @@ export async function startEmbeddedServer(options: EmbeddedServerOptions): Promi
// requested one. Proxy requests that land in the short window before the
// engine is ready fail with opencode_unconfigured and clients retry; the
// desktop only learns the server URL after this function returns.
+ // The Linux sandbox's helpers ship beside the engine (sidecars/box/): known before the server plans any box.
+ const engineBin = options.opencodeBin || process.env.OMNIRUSH_OPENCODE_BIN;
+ if (engineBin?.trim()) setToolsRoot(dirname(engineBin.trim()));
server = await duringStartup(() => startServer(config));
config.port = server.port;
const serverUrl = `http://${config.host === "0.0.0.0" ? "127.0.0.1" : config.host}:${server.port}`;
@@ -243,9 +246,6 @@ export async function startEmbeddedServer(options: EmbeddedServerOptions): Promi
// Server-managed config file: the engine re-reads it from disk on every
// instance rebuild, and keepOmniRushRuntimeConfigFileFresh synchronizes it
// on every runtime-DB write — so disposes always pick up current state.
- // The Linux sandbox's helpers ship beside the engine (sidecars/box/); the config names its shell.
- const engineBin = options.opencodeBin || process.env.OMNIRUSH_OPENCODE_BIN;
- if (engineBin?.trim()) setToolsRoot(dirname(engineBin.trim()));
const { path: runtimeConfigPath } = await writeOmniRushRuntimeConfigFile(config);
stopRuntimeConfigFileRefresh = keepOmniRushRuntimeConfigFileFresh(config);
const cwd = options.opencodeCwd
@@ -254,7 +254,7 @@ export async function startEmbeddedServer(options: EmbeddedServerOptions): Promi
await duringStartup(() => mkdir(cwd, { recursive: true }));
const opencodeModelsEnv = await duringStartup(() => resolveOpencodeModelsEnv());
- const opencodeBin = engineBin;
+ const opencodeBin = options.opencodeBin || process.env.OMNIRUSH_OPENCODE_BIN;
// Shared by the first spawn and by any later rollover standby, so a
// replacement engine is identical apart from its port.
const engineEnv: Record<string, string | undefined> = {
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index b4d44a3e..2d03d795 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -3778,9 +3778,11 @@ function createRoutes(
throw new ApiError(400, "invalid_payload", "mode must be \"on\", \"off\" or null and the only field");
}
if (workspace.workspaceType !== "local") throw new ApiError(400, "box_unsupported", "The sandbox is for folders on this computer");
- const status = await boxServiceFor(config).setMode(workspace, mode);
- // The engine gets the box shell and plugin when the first workspace turns its box on.
- const engine = await applyBoxEngineConfig(config, "local_box");
+ const boxes = boxServiceFor(config);
+ const before = JSON.stringify(await boxes.engineBits());
+ const status = await boxes.setMode(workspace, mode);
+ // The engine gets the box shell and plugin when the first workspace turns its box on (and loses them with the last).
+ const engine = JSON.stringify(await boxes.engineBits()) === before ? { status: "unchanged" as const } : await applyBoxEngineConfig(config, "local_box");
return jsonResponse({ ...status, engine });
});