Multiplayer agent harness for work.
Only restart a reattached background job on a confirmed missing process (#385)
Regan Bell6cd3aaf78fa7
diff --git a/src/connectors/background-exec-broker.ts b/src/connectors/background-exec-broker.tsindex b01a2fd0f..ce7c44f8c 100644--- a/src/connectors/background-exec-broker.ts+++ b/src/connectors/background-exec-broker.ts@@ -1,7 +1,7 @@import type { ProcessSandbox, ProcessState, SandboxHandle } from "../sandbox/sandbox.ts";import type { ProcessRegistry, ProcessStatus } from "../processes/process-registry.ts";import { awaitProcessExit } from "../sandbox/await-process-exit.ts";-import { pollProcess } from "../sandbox/process-poll.ts";+import { pollProcess, processIsGone } from "../sandbox/process-poll.ts";import { redactCommand } from "../sandbox/exec-process-session.ts";import { CONFIG_DEFAULTS } from "../config.ts";@@ -108,7 +108,8 @@ export function createBackgroundBroker(deps: BackgroundExecBrokerDeps): Backgrouawait deps.registry.markStatus(existingProcessId, "exited");processId = null;}- } catch {+ } catch (error) {+ if (!processIsGone(error)) throw error;await deps.registry.delete(existingProcessId);processId = null;}diff --git a/test/background-exec-broker.test.ts b/test/background-exec-broker.test.tsindex 74b707fdf..6ad27156a 100644--- a/test/background-exec-broker.test.ts+++ b/test/background-exec-broker.test.ts@@ -20,6 +20,7 @@ function fakeSandbox(opts?: { seedOutput?: string }) {const starts: Array<{ command: string; opts?: StartProcessOptions }> = [];const signals: Array<{ id: string; signal: string }> = [];const writes: Array<{ id: string; data: string }> = [];+ const readErrors = new Map<string, unknown>();let n = 0;const sandbox: ProcessSandbox = {@@ -53,6 +54,11 @@ function fakeSandbox(opts?: { seedOutput?: string }) {return { processId };},async readProcess(_h, id, opts) {+ if (readErrors.has(id)) {+ const error = readErrors.get(id);+ readErrors.delete(id);+ throw error;+ }if (missing.has(id)) throw new Error(`no such process session: ${id}`);const p = procs.get(id);if (!p) throw new Error(`no such process session: ${id}`);@@ -104,6 +110,7 @@ function fakeSandbox(opts?: { seedOutput?: string }) {}},vanish: (id: string) => missing.add(id),+ failNextRead: (id: string, error: unknown) => readErrors.set(id, error),};}@@ -366,6 +373,17 @@ test("liveness probe: a row whose backend process is gone is deleted and a freshassert.equal(rows[0]!.processId, second.processId);});+test("liveness probe: a transient backend error preserves the running process and registry row", async () => {+ const { broker, registry, starts, failNextRead } = build();+ const first = await broker.start(handle, "long-build");+ const error = new Error("backend unavailable");+ failNextRead(first.processId, error);++ await assert.rejects(broker.start(handle, "long-build"), error);+ assert.equal(starts.length, 1);+ assert.equal((await registry.get(first.processId))?.status, "running");+});+test("TTL clamp: a requested lifetime above the max is clamped (mirrors PR C's ceiling clamp)", async () => {const ttlMaxMs = 60 * 60_000;const { broker, registry } = build({ ttlMs: 30 * 60_000, ttlMaxMs });