Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: farm mode (stock) offline policy only for asked farm runs, not event stock mode

ogsamrat5e37e323fa51
diff --git a/apps/desktop/electron/events-desktop.test.mjs b/apps/desktop/electron/events-desktop.test.mjs
index 5d832d07..28fd86a1 100644
--- a/apps/desktop/electron/events-desktop.test.mjs
+++ b/apps/desktop/electron/events-desktop.test.mjs
@@ -105,3 +105,23 @@ test("window: display values, the restart note, nothing for a plain stock run or
// Offline (no answer this time): the kept one.
assert.equal(accountEvents({ connected: true }, { dir, started: { stock: true, event: true }, now: NOW }).events.active[0].name, "BIOS V2");
});
+
+test("start: the farm-run marker (the offline box) only for stock mode the launch asked for, never an event's", () => {
+ const dir = tmp();
+ accountEvents(status(ME), { dir, started: { stock: false }, now: NOW });
+ // An event turns stock mode on: no marker, and a stray one from the launch env is dropped.
+ const event = { OMNIRUSH_FARM_RUN: "1" };
+ applyEventStock(dir, event, NOW);
+ assert.equal(event.OMNIRUSH_FARM, "1");
+ assert.equal(event.OMNIRUSH_FARM_RUN, undefined);
+ // Asked at launch (with or without an event): a farm run.
+ const asked = { OMNIRUSH_FARM: "1" };
+ applyEventStock(dir, asked, NOW);
+ assert.equal(asked.OMNIRUSH_FARM_RUN, "1");
+ const alone = { OMNIRUSH_FARM: "1" };
+ applyEventStock(tmp(), alone, NOW);
+ assert.equal(alone.OMNIRUSH_FARM_RUN, "1");
+ // A relaunch of an event-only start: still no farm run.
+ applyEventStock(dir, event, NOW);
+ assert.equal(event.OMNIRUSH_FARM_RUN, undefined);
+});
diff --git a/apps/desktop/electron/events/app-events.mjs b/apps/desktop/electron/events/app-events.mjs
index c5510134..99654a85 100644
--- a/apps/desktop/electron/events/app-events.mjs
+++ b/apps/desktop/electron/events/app-events.mjs
@@ -11,6 +11,11 @@ import { dateLabel, endsLabel, eventBadge, eventsRecord, parseEvents } from "./e
const FILE = "events.json";
const STOCK_ENV = "OMNIRUSH_FARM";
+/**
+ * A farm run: stock mode the launch asked for (OMNIRUSH_FARM in the launch env), never one an event turned on.
+ * Only farm runs get the offline box, its prompt line and the refusals (the server's stock-mode.mjs farmRun).
+ */
+export const FARM_RUN_ENV = "OMNIRUSH_FARM_RUN";
/** Set at start when an event turned the mode on: the window's stock-mode notice stays quiet then. */
export const EVENT_MODE_ENV = "OMNIRUSH_STOCK_REASON";
@@ -44,6 +49,9 @@ export function applyEventStock(dir, env = process.env, now = Date.now()) {
if (env[EVENT_MODE_ENV] === "event") delete env[STOCK_ENV];
delete env[EVENT_MODE_ENV];
const asked = stockMode(env);
+ // Set for an asked run only (a relaunch's or a stray one is dropped otherwise).
+ if (asked) env[FARM_RUN_ENV] = "1";
+ else delete env[FARM_RUN_ENV];
const event = Boolean(parseEvents(readEventsRecord(dir), now).stock);
if (event) {
env[EVENT_MODE_ENV] = asked ? "event-asked" : "event";
diff --git a/apps/server/src/box/backends/bwrap.ts b/apps/server/src/box/backends/bwrap.ts
index 435c091d..101ae7d7 100644
--- a/apps/server/src/box/backends/bwrap.ts
+++ b/apps/server/src/box/backends/bwrap.ts
@@ -24,7 +24,7 @@ import path from "node:path";
import { GOARCH, RUN_DIR, SHIMS_DIR, containerName, containerRoot, helperPath, newToken, readJson, writeJson, type BoxInstallLog, type BoxRuntime } from "../common.js";
import { REQUIRED_RULES, shadowId, type ShadowPlan } from "../required.js";
-import { stockMode } from "../../stock-mode/stock-mode.mjs";
+import { farmRun } from "../../stock-mode/stock-mode.mjs";
import { runCommand, type RunCommand, type RunOptions } from "../run.js";
import type { RuntimeResult } from "../runtime.js";
import { YOUNG_IMAGE_MS, removableImage, removeTree, staleEntries } from "../retention.mjs";
@@ -160,11 +160,11 @@ async function pull(runtime: BoxRuntime, image: { pull: string }, { run = runCom
}
/**
- * The box's egress: "farm" in farm runs (OMNIRUSH_FARM): boxd gives the agent's commands no internet
+ * The box's egress: "farm" in farm runs (an asked OMNIRUSH_FARM, stock-mode.mjs farmRun; not an event's stock mode): boxd gives the agent's commands no internet
* but the package registries (box/go/cmd/boxd/egress.go). null: the box's network as is. CLI: the same.
*/
export function boxEgress(env: Env = process.env): "farm" | null {
- return stockMode(env) ? "farm" : null;
+ return farmRun(env) ? "farm" : null;
}
/** boxd's environment in a box (what `docker create -e` gives the containers). */
diff --git a/apps/server/src/box/box-backends.test.ts b/apps/server/src/box/box-backends.test.ts
index 85785d4c..34cdccfc 100644
--- a/apps/server/src/box/box-backends.test.ts
+++ b/apps/server/src/box/box-backends.test.ts
@@ -97,7 +97,7 @@ function linuxRun(bwrapAnswer: unknown, { podman = true }: { podman?: boolean }
describe("box backends: Linux", () => {
test("farm runs: only backends that keep the box offline; Podman/Docker are skipped, never a silent fallback", async () => {
const home = tmp();
- const env = { PATH: "/usr/bin", OMNIRUSH_BOX_BIN_DIR: helperBin(), OMNIRUSH_FARM: "1" };
+ const env = { PATH: "/usr/bin", OMNIRUSH_BOX_BIN_DIR: helperBin(), OMNIRUSH_FARM: "1", OMNIRUSH_FARM_RUN: "1" };
const farm = await detectBackend({ boxHome: home, platform: "linux", home, env, exists: set(boxrunPath({ env }), "/usr/bin/podman"), run: linuxRun(BWRAP_AA).run, fresh: true, all: true, wsl: false });
expect(farm.ok).toBe(false);
expect(farm.alternatives?.find((a) => a.backend === "podman")?.reason).toBe("cannot keep a farm session offline");
@@ -110,7 +110,9 @@ describe("box backends: Linux", () => {
const runtime = { name: "wslc", backend: "wslc", bin: "wslc.exe" };
const base = { key: "k", name: "omnirush-box-k", root: home, croot: home, runtime, home, runFolder: home, run: linuxRun(BWRAP_OK).run, log: () => {}, platform: "win32" as const };
expect(new Box({ ...base, env: {} }).execFallback()).toBe(true);
- expect(new Box({ ...base, env: { OMNIRUSH_FARM: "1" } }).execFallback()).toBe(false);
+ expect(new Box({ ...base, env: { OMNIRUSH_FARM: "1", OMNIRUSH_FARM_RUN: "1" } }).execFallback()).toBe(false);
+ // A hackathon event's stock mode (no farm-run marker) keeps the fallback, as before.
+ expect(new Box({ ...base, env: { OMNIRUSH_FARM: "1" } }).execFallback()).toBe(true);
});
test("bubblewrap first when its probe starts a namespace", async () => {
@@ -212,7 +214,10 @@ describe("box backends: Linux", () => {
test("farm egress: only farm runs give boxd BOXD_EGRESS (bwrap, WSL distro, wslc); other runs keep their exact args", () => {
expect(boxEgress({})).toBeNull();
expect(boxEgress({ OMNIRUSH_FARM: "0" })).toBeNull();
- expect(boxEgress({ OMNIRUSH_FARM: "1" })).toBe("farm");
+ expect(boxEgress({ OMNIRUSH_FARM: "1", OMNIRUSH_FARM_RUN: "1" })).toBe("farm");
+ // A hackathon event's stock mode (OMNIRUSH_FARM without the farm-run marker): the network as is.
+ expect(boxEgress({ OMNIRUSH_FARM: "1" })).toBeNull();
+ expect(boxEgress({ OMNIRUSH_FARM_RUN: "1" })).toBeNull();
const base = { box: "/b", store: "/s", image: "i", boxd: "/d", portFile: "/p", root: "/r", croot: "/r", runFolder: "/f", token: "t" };
const plain = upArgs(base);
expect(upArgs({ ...base, egress: null })).toEqual(plain);
diff --git a/apps/server/src/box/box-required-service.test.ts b/apps/server/src/box/box-required-service.test.ts
index ead08946..847a96b9 100644
--- a/apps/server/src/box/box-required-service.test.ts
+++ b/apps/server/src/box/box-required-service.test.ts
@@ -394,26 +394,42 @@ describe("required sandbox: a stopped send", () => {
});
describe("farm runs (stock mode): the box or no prompt", () => {
- test("box off, host-only project, no backend, a remote workspace: refused with one line; other runs never", async () => {
+ test("box off, host-only project, no backend, a remote workspace: refused with one line; other runs (and events) never", async () => {
const state = await temp("farm-state");
rememberServerDefault(state, { local_box: { default: "on", required: true } });
const root = await temp("farm-proj");
const local: BoxWorkspace = { id: "w1", path: root, workspaceType: "local" };
const line = (why: string) => `farm mode runs only in the sandbox (it keeps the session offline); this machine has no usable sandbox (${why})`;
- const farm = { ...NO_RUNTIME, OMNIRUSH_FARM: "1" };
- expect(await service({ stateDir: state, workspaces: [local], env: { ...farm, OMNIRUSH_BOX: "0" } }).farmRefusal(local)).toBe(line("box off: OMNIRUSH_BOX=0"));
+ const farm = { ...NO_RUNTIME, OMNIRUSH_FARM: "1", OMNIRUSH_FARM_RUN: "1" };
+ expect(await service({ stateDir: state, workspaces: [local], env: { ...farm, OMNIRUSH_BOX: "0" } }).farmRefusal(local)).toEqual({ line: line("box off: OMNIRUSH_BOX=0") });
const none = await service({ stateDir: state, workspaces: [local], env: { ...farm, OMNIRUSH_FARM: "true" } }).farmRefusal(local);
- expect(none).toStartWith(line("no backend that keeps it offline").slice(0, -1));
+ expect(none?.line).toStartWith(line("no backend that keeps it offline").slice(0, -1));
+ expect(none?.retryAfter).toBeUndefined();
const win = await temp("farm-win");
await writeFile(join(win, "app.vcxproj"), "<Project/>");
const winWs: BoxWorkspace = { id: "w2", path: win, workspaceType: "local" };
- expect(await service({ stateDir: state, workspaces: [winWs], env: farm, platform: "win32" }).farmRefusal(winWs)).toBe(line("host-only project"));
+ expect(await service({ stateDir: state, workspaces: [winWs], env: farm, platform: "win32" }).farmRefusal(winWs)).toEqual({ line: line("host-only project") });
const remote: BoxWorkspace = { id: "w3", path: "/remote", workspaceType: "remote" };
- expect(await service({ stateDir: state, workspaces: [remote], env: farm }).farmRefusal(remote)).toBe(line("not a local project"));
- // Not a farm run: nothing refused, whatever the box can do here.
- for (const env of [{ ...NO_RUNTIME, OMNIRUSH_BOX: "0" }, NO_RUNTIME, { ...NO_RUNTIME, OMNIRUSH_FARM: "0" }]) {
+ expect(await service({ stateDir: state, workspaces: [remote], env: farm }).farmRefusal(remote)).toEqual({ line: line("not a local project") });
+ // Not a farm run, or a hackathon event's stock mode (OMNIRUSH_FARM without the farm-run marker): nothing refused.
+ for (const env of [{ ...NO_RUNTIME, OMNIRUSH_BOX: "0" }, NO_RUNTIME, { ...NO_RUNTIME, OMNIRUSH_FARM: "0" }, { ...NO_RUNTIME, OMNIRUSH_FARM: "1", OMNIRUSH_BOX: "0" }, { ...NO_RUNTIME, OMNIRUSH_FARM: "1" }]) {
expect(await service({ stateDir: state, workspaces: [local, remote], env }).farmRefusal(local)).toBeNull();
expect(await service({ stateDir: state, workspaces: [local, remote], env }).farmRefusal(remote)).toBeNull();
}
});
+
+ test("the image still downloading: refused for now, retryable, with when to try again", async () => {
+ const state = await temp("farm-dl-state");
+ rememberServerDefault(state, { local_box: { default: "on", required: true } });
+ const root = await temp("farm-dl-proj");
+ const local: BoxWorkspace = { id: "w1", path: root, workspaceType: "local" };
+ const boxes = service({ stateDir: state, workspaces: [local], env: { ...NO_RUNTIME, OMNIRUSH_FARM: "1", OMNIRUSH_FARM_RUN: "1" } });
+ // As ensure() leaves a project whose image is downloading (planned again REPLAN_MS later).
+ (boxes as unknown as { ensure: () => Promise<null> }).ensure = async () => null;
+ (boxes as unknown as { projects: Map<string, unknown> }).projects.set(boxKey(root), { run: null, notice: null, planning: null, nextPlanAt: Date.now() + 15_000, waitingImage: true, why: { reason: "downloading" } });
+ const refused = await boxes.farmRefusal(local);
+ expect(refused?.line).toContain("the sandbox image is still downloading");
+ expect(refused?.retryAfter).toBeGreaterThanOrEqual(14);
+ expect(refused?.retryAfter).toBeLessThanOrEqual(15);
+ });
});
diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.ts
index a5d9158d..b88a818d 100644
--- a/apps/server/src/box/service.ts
+++ b/apps/server/src/box/service.ts
@@ -39,7 +39,7 @@ import { desktopText, hostOnlyProject, requiredLaunch, shadowsApply, shadowsNoti
import { cachedWindowsChecks, classifySetup, linuxAllow, resumeWinSetup, saveSetupState, setupState, windowsInstall, windowsRestart, windowsUpdate, type BoxSetup } from "./setup.js";
import type { BoxInstallLogPaths } from "./install-log.js";
import { DESKTOP_PROJECTS_FILE } from "./plugin-lib.js";
-import { stockMode } from "../stock-mode/stock-mode.mjs";
+import { farmRun } from "../stock-mode/stock-mode.mjs";
import { BUILDATHON_OFFER_NOTICE, buildathonBoxFor, buildathonProjectsFile, LESS_REPRO_NOTICE } from "../buildathon-repro.js";
import { layerSizes, pullProgress, type PullProgress } from "./pull-progress.js";
import { detectRuntime, type BackendAlternative, type DetectOptions, type RuntimeInfo, type RuntimeResult } from "./runtime.js";
@@ -1020,12 +1020,21 @@ export class BoxService {
* box was turned off since, and is refused only when the box truly cannot run.
*/
/**
- * Farm runs (stock mode) run only in the box, which keeps them offline (boxd egress.go): a prompt of a
- * workspace that cannot use it is refused (the line to refuse with), before any model call or upload.
+ * Farm runs (stock mode asked for at launch, stock-mode.mjs farmRun) run only in the box, which keeps them
+ * offline (boxd egress.go): a prompt of a workspace that cannot use it is refused, before any model call or
+ * upload, with the line and, while the image is still downloading, when to try again (`retryAfter`, seconds).
* Null: not a farm run, or the box is there. CLI: src/box/launch.js farmRefusal / farmGate.
*/
- async farmRefusal(workspace: BoxWorkspace): Promise<string | null> {
- if (!stockMode(this.env)) return null;
+ async farmRefusal(workspace: BoxWorkspace): Promise<FarmRefusal | null> {
+ const line = await this.farmRefusalLine(workspace);
+ if (!line) return null;
+ const project = this.projects.get(boxKey(boxRoot(workspace)));
+ if (project?.why?.reason !== "downloading") return { line };
+ return { line, retryAfter: Math.max(1, Math.ceil(((project.nextPlanAt || 0) - Date.now()) / 1000)) || Math.ceil(REPLAN_MS / 1000) };
+ }
+
+ private async farmRefusalLine(workspace: BoxWorkspace): Promise<string | null> {
+ if (!farmRun(this.env)) return null;
if (workspace.workspaceType !== "local") return farmLine("not a local project");
const mode = await this.mode(workspace).catch(() => null);
if (mode && !mode.on) {
@@ -1123,6 +1132,9 @@ export class BoxService {
}
}
+/** A farm prompt's refusal: the line, and when to try again (seconds) for a passing reason only (the image downloading). */
+export type FarmRefusal = { line: string; retryAfter?: number };
+
/** The one line a farm run that cannot use the box is refused with. CLI: src/box/launch.js farmLine. */
export function farmLine(why: string): string {
return `farm mode runs only in the sandbox (it keeps the session offline); this machine has no usable sandbox (${why})`;
diff --git a/apps/server/src/managed-opencode-v2.ts b/apps/server/src/managed-opencode-v2.ts
index 7688a9c3..030dd9a8 100644
--- a/apps/server/src/managed-opencode-v2.ts
+++ b/apps/server/src/managed-opencode-v2.ts
@@ -14,7 +14,7 @@ import { writeFileAtomic } from "./atomic-write.js";
import { currentProviderLockPolicy, noteEngineStarted, providerAllowed } from "./provider-lock.js";
import { APP_PROVIDER_IDS, providerLockEnv } from "./provider-lock/provider-lock.mjs";
import { gateEnv } from "./engine-gates/engine-gates.mjs";
-import { STOCK_ENV, STOCK_PROVIDER, STOCK_SHELL_ENV, stockMode, stockProviders } from "./stock-mode/stock-mode.mjs";
+import { FARM_RUN_ENV, STOCK_ENV, STOCK_PROVIDER, STOCK_SHELL_ENV, stockMode, stockProviders } from "./stock-mode/stock-mode.mjs";
import { releaseEngineBinary } from "./release-guard.js";
export interface OpencodeV2ModelSpec {
@@ -201,7 +201,7 @@ export async function createManagedOpencodeV2Server(
"LANG", "LC_ALL", "LC_CTYPE", "TZ", "TERM", "CI",
"XDG_CACHE_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_RUNTIME_DIR",
"SystemRoot", "SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT", "USERPROFILE", "APPDATA", "LOCALAPPDATA",
- "NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR", STOCK_ENV, STOCK_SHELL_ENV,
+ "NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR", STOCK_ENV, STOCK_SHELL_ENV, FARM_RUN_ENV,
]) {
const value = options.env?.[key] ?? process.env[key];
if (value !== undefined) inherited[key] = value;
diff --git a/apps/server/src/opencode-plugins/omnirush-box-next.test.ts b/apps/server/src/opencode-plugins/omnirush-box-next.test.ts
index a2520e55..479a6f90 100644
--- a/apps/server/src/opencode-plugins/omnirush-box-next.test.ts
+++ b/apps/server/src/opencode-plugins/omnirush-box-next.test.ts
@@ -70,7 +70,15 @@ test("farm runs: the prompt gets the offline line only (no box note); other runs
const { root } = project(true);
const hooks = await engine(root);
const saved = process.env.OMNIRUSH_FARM;
+ const savedRun = process.env.OMNIRUSH_FARM_RUN;
try {
+ // A hackathon event's stock mode (no farm-run marker): stock, as before: no box note, no offline line.
+ process.env.OMNIRUSH_FARM = "1";
+ delete process.env.OMNIRUSH_FARM_RUN;
+ const event = { sessionID: "ses_e", system: ["Platform: darwin"] as unknown[] };
+ await hooks.get("context")!(event);
+ expect(event.system).toEqual(["Platform: linux"]);
+ process.env.OMNIRUSH_FARM_RUN = "1";
for (const on of ["1", "true", "on", "yes"]) {
process.env.OMNIRUSH_FARM = on;
const farm = { sessionID: "ses_f", system: ["Platform: darwin"] as unknown[] };
@@ -89,6 +97,8 @@ test("farm runs: the prompt gets the offline line only (no box note); other runs
} finally {
if (saved === undefined) delete process.env.OMNIRUSH_FARM;
else process.env.OMNIRUSH_FARM = saved;
+ if (savedRun === undefined) delete process.env.OMNIRUSH_FARM_RUN;
+ else process.env.OMNIRUSH_FARM_RUN = savedRun;
}
});
diff --git a/apps/server/src/opencode-plugins/omnirush-box.ts b/apps/server/src/opencode-plugins/omnirush-box.ts
index a3622f31..80cb8eac 100644
--- a/apps/server/src/opencode-plugins/omnirush-box.ts
+++ b/apps/server/src/opencode-plugins/omnirush-box.ts
@@ -25,7 +25,7 @@ import path from "node:path";
import { BOX_HEADER } from "../model-modes/model-modes.mjs";
import { BOX_NOTE, OFFLINE_NOTE, desktopProjects, engineDirs, FILE_TOOLS, keyOf, record, toolPaths, within } from "../box/plugin-lib.js";
-import { stockMode } from "../stock-mode/stock-mode.mjs";
+import { farmRun, stockMode } from "../stock-mode/stock-mode.mjs";
/** The engine client's one call used here: a chat's parent (a sub-agent's chat has one). */
type SessionReader = { session: { get: (options: { path: { id: string } }) => Promise<{ data?: { parentID?: string } | null } | undefined> } };
@@ -92,9 +92,9 @@ export const OmniRushBox = async ({ directory, client }: { directory?: string; c
}
// Stock mode (stock-mode.mjs, the CLI's opencode-box-plugin.js): the system prompt stays stock apart from its environment lines,
// and the one line that says the box is offline (farm runs' boxes are: boxd egress.go).
- // stockMode, as the box's egress (bwrap.ts boxEgress) reads it: the two never disagree.
if (stockMode(process.env)) {
- output.system.push(OFFLINE_NOTE);
+ // Only a farm run's box is offline (farmRun, as bwrap.ts boxEgress reads it); an event's stock mode keeps the network and no line.
+ if (farmRun(process.env)) output.system.push(OFFLINE_NOTE);
return;
}
output.system.push(BOX_NOTE(root, Number(rec.uid) || 0, typeof rec.croot === "string" ? rec.croot : root, rec.shadows_note));
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 634cee7f..955ad1cc 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -2259,7 +2259,7 @@ export async function proxyOpencodeV2Request(input: {
const farmRefused = promptDispatch ? await boxServiceFor(input.config).farmRefusal(input.workspace) : null;
if (farmRefused) {
await input.request.arrayBuffer().catch(() => undefined);
- return jsonResponse({ error: "farm_needs_sandbox", message: `omnirush: ${farmRefused}` }, 409);
+ return jsonResponse({ error: "farm_needs_sandbox", message: `omnirush: ${farmRefused.line}`, ...(farmRefused.retryAfter ? { retryable: true, retry_after: farmRefused.retryAfter } : {}) }, 409);
}
const collectible = input.workspace.workspaceType !== "remote";
if (promptDispatch && collectible) {
@@ -2803,7 +2803,7 @@ export async function proxyOpencodeRequest(input: {
const farmRefused = workspace && isUploadPromptDispatch(method, proxyPath) ? await boxServiceFor(input.config).farmRefusal(workspace) : null;
if (farmRefused) {
await input.request.arrayBuffer().catch(() => undefined);
- return jsonResponse({ error: "farm_needs_sandbox", message: `omnirush: ${farmRefused}` }, 409);
+ return jsonResponse({ error: "farm_needs_sandbox", message: `omnirush: ${farmRefused.line}`, ...(farmRefused.retryAfter ? { retryable: true, retry_after: farmRefused.retryAfter } : {}) }, 409);
}
if (workspace && workspace.workspaceType !== "remote" && isUploadPromptDispatch(method, proxyPath)) {
if (uploadDispatchRefused(input.config, workspace)) {
diff --git a/apps/server/src/session-uploader.server.e2e.test.ts b/apps/server/src/session-uploader.server.e2e.test.ts
index 8777a387..70a60358 100644
--- a/apps/server/src/session-uploader.server.e2e.test.ts
+++ b/apps/server/src/session-uploader.server.e2e.test.ts
@@ -885,7 +885,7 @@ describe("collection gaps: the v2 mount and local workflow steps", () => {
expect(v2.prompts).toHaveLength(1);
}, 30_000);
- test("a farm run (stock mode) whose box is off: the v2 prompt is refused with one line, nothing reaches the engine", async () => {
+ test("a farm run (asked stock mode) whose box is off: the v2 prompt is refused with one line, nothing reaches the engine; an event's stock mode goes through", async () => {
const { root, stateDir } = await createWorkspace();
const engine = startMockEngine(provider);
const v2 = startMockV2Engine(provider);
@@ -893,21 +893,28 @@ describe("collection gaps: the v2 mount and local workflow steps", () => {
await startOmniRush(config);
preserveGateEnv();
setGateEnv("1", "1");
- const saved = { farm: process.env.OMNIRUSH_FARM, box: process.env.OMNIRUSH_BOX };
+ const saved = { farm: process.env.OMNIRUSH_FARM, run: process.env.OMNIRUSH_FARM_RUN, box: process.env.OMNIRUSH_BOX };
try {
process.env.OMNIRUSH_FARM = "1";
process.env.OMNIRUSH_BOX = "0";
+ // A hackathon event's stock mode (no farm-run marker): the prompt goes through, as on 2.7.9.
+ delete process.env.OMNIRUSH_FARM_RUN;
+ expect((await promptV2(config, v2.connection)).status).toBe(200);
+ expect(v2.prompts).toHaveLength(1);
+ v2.prompts.length = 0;
+ process.env.OMNIRUSH_FARM_RUN = "1";
+ const before = v2.received.length;
const response = await promptV2(config, v2.connection);
expect(response.status).toBe(409);
expect(await response.json()).toEqual({ error: "farm_needs_sandbox", message: "omnirush: farm mode runs only in the sandbox (it keeps the session offline); this machine has no usable sandbox (box off: OMNIRUSH_BOX=0)" });
- expect(v2.received).toEqual([]);
+ expect(v2.received).toHaveLength(before);
expect(v2.prompts).toEqual([]);
// The same machine, not a farm run: the prompt goes through.
delete process.env.OMNIRUSH_FARM;
expect((await promptV2(config, v2.connection)).status).toBe(200);
expect(v2.prompts).toEqual([{ text: "Do the task" }]);
} finally {
- for (const [key, value] of [["OMNIRUSH_FARM", saved.farm], ["OMNIRUSH_BOX", saved.box]] as const) {
+ for (const [key, value] of [["OMNIRUSH_FARM", saved.farm], ["OMNIRUSH_FARM_RUN", saved.run], ["OMNIRUSH_BOX", saved.box]] as const) {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
diff --git a/apps/server/src/stock-mode/stock-mode.d.mts b/apps/server/src/stock-mode/stock-mode.d.mts
index 48b64d52..4848f8e9 100644
--- a/apps/server/src/stock-mode/stock-mode.d.mts
+++ b/apps/server/src/stock-mode/stock-mode.d.mts
@@ -7,3 +7,5 @@ export declare function applyStockSwitches(env?: Record<string, string | undefin
export declare function stockProviders<T extends { id: string; models: { id: string; config?: Record<string, unknown> }[] }>(specs: T[]): T[];
export declare const STOCK_SHELL_ENV: "OMNIRUSH_STOCK_SHELL_ENV";
export declare function stockShellEnv<T extends Record<string, string | undefined>>(env: T, engineEnv?: Record<string, string | undefined>): T;
+export declare const FARM_RUN_ENV: "OMNIRUSH_FARM_RUN";
+export declare function farmRun(env?: Record<string, string | undefined>): boolean;
diff --git a/apps/server/src/stock-mode/stock-mode.mjs b/apps/server/src/stock-mode/stock-mode.mjs
index 28edf6c3..ca830b41 100644
--- a/apps/server/src/stock-mode/stock-mode.mjs
+++ b/apps/server/src/stock-mode/stock-mode.mjs
@@ -32,6 +32,17 @@ export const STOCK_SWITCHES = Object.freeze({
OMNIRUSH_INSTALL_LOG: "0",
});
+/**
+ * A farm run: stock mode the launch asked for, never one a hackathon event turned on (the desktop's
+ * events/app-events.mjs applyEventStock sets FARM_RUN_ENV for an asked run only; the CLI's src/stock.js
+ * farmRun is the same). Only farm runs get the offline box, its prompt line and the refusals.
+ */
+export const FARM_RUN_ENV = "OMNIRUSH_FARM_RUN";
+
+export function farmRun(env = process.env) {
+ return env?.[FARM_RUN_ENV] === "1" && stockMode(env);
+}
+
/** Sets the stock switches in `env` when it asks for stock mode; returns whether it does. */
export function applyStockSwitches(env = process.env) {
if (!stockMode(env)) return false;