Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

enable the kernel forkserver by default on linux (#300)

kt7ba6fc82bf33
diff --git a/packages/coding-agent/src/core/kernel/fork-server.ts b/packages/coding-agent/src/core/kernel/fork-server.ts
index 139c8aa64f..c917319979 100644
--- a/packages/coding-agent/src/core/kernel/fork-server.ts
+++ b/packages/coding-agent/src/core/kernel/fork-server.ts
@@ -39,9 +39,11 @@ export class ForkServerUnavailable extends Error {
}
}
-/** Fork is a Linux-only, in-process fan-out optimization. */
+// On by default on Linux (fork-without-exec is unsafe on macOS);
+// PRIME_AGENT_KERNEL_FORKSERVER=0 opts out.
export function isForkServerEnabled(): boolean {
- return process.platform === "linux" && process.env.PRIME_AGENT_KERNEL_FORKSERVER === "1";
+ if (process.platform !== "linux") return false;
+ return process.env.PRIME_AGENT_KERNEL_FORKSERVER !== "0";
}
// A forkserver template is defined solely by the interpreter — the imported
diff --git a/packages/coding-agent/test/args.test.ts b/packages/coding-agent/test/args.test.ts
index a502290cc7..12e0aa9f35 100644
--- a/packages/coding-agent/test/args.test.ts
+++ b/packages/coding-agent/test/args.test.ts
@@ -399,9 +399,7 @@ describe("parseArgs", () => {
test("a dash-leading prompt without -- still errors", () => {
const result = parseArgs(["- do the thing"]);
expect(result.messages).toEqual([]);
- expect(result.diagnostics).toEqual([
- { type: "error", message: "Unknown option: - do the thing" },
- ]);
+ expect(result.diagnostics).toEqual([{ type: "error", message: "Unknown option: - do the thing" }]);
});
test("does not parse flags after -- as options", () => {
diff --git a/packages/coding-agent/test/boot-gate.test.ts b/packages/coding-agent/test/boot-gate.test.ts
index 31d1c8b33c..1bb16a21d1 100644
--- a/packages/coding-agent/test/boot-gate.test.ts
+++ b/packages/coding-agent/test/boot-gate.test.ts
@@ -18,20 +18,18 @@ describe("resolveKernelBootConcurrency", () => {
});
it("honors a clean positive integer, clamped to the direct-spawn max", () => {
+ process.env[FORK_ENV] = "0"; // direct-spawn path (forkserver is default-on)
process.env[ENV] = "8";
expect(resolveKernelBootConcurrency()).toBe(8);
process.env[ENV] = "999999";
expect(resolveKernelBootConcurrency()).toBe(64);
});
- it("raises the ceiling when the forkserver is enabled (linux only)", () => {
+ it("raises the ceiling on the forkserver path (linux, default on)", () => {
if (process.platform !== "linux") return;
- process.env[FORK_ENV] = "1";
- // Auto default is well above the direct-spawn default but still bounded.
const auto = resolveKernelBootConcurrency();
expect(auto).toBeGreaterThanOrEqual(32);
expect(auto).toBeLessThanOrEqual(128);
- // A huge override is clamped to the fork backstop, not the direct-spawn cap.
process.env[ENV] = "999999";
expect(resolveKernelBootConcurrency()).toBe(128);
});
diff --git a/packages/coding-agent/test/ipython-provisioner.test.ts b/packages/coding-agent/test/ipython-provisioner.test.ts
index fa8d684b3b..ffb6cee6ed 100644
--- a/packages/coding-agent/test/ipython-provisioner.test.ts
+++ b/packages/coding-agent/test/ipython-provisioner.test.ts
@@ -2,12 +2,23 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, wr
import { tmpdir } from "node:os";
import { join } from "node:path";
import { cleanupSessionResources } from "@earendil-works/pi-ai";
-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { KernelManager } from "../src/core/kernel/index.js";
import { IpythonKernelProvisioner } from "../src/core/tools/ipython.js";
let tempDir = "";
+// These tests count spawns of a stub python; the default-on forkserver adds an
+// extra spawn + ready handshake the stub never answers, so pin direct-spawn.
+const savedForkFlag = process.env.PRIME_AGENT_KERNEL_FORKSERVER;
+beforeAll(() => {
+ process.env.PRIME_AGENT_KERNEL_FORKSERVER = "0";
+});
+afterAll(() => {
+ if (savedForkFlag === undefined) delete process.env.PRIME_AGENT_KERNEL_FORKSERVER;
+ else process.env.PRIME_AGENT_KERNEL_FORKSERVER = savedForkFlag;
+});
+
function writeFakePython(opts: { sleepSeconds?: number } = {}): { python: string; countRuns: () => number } {
const python = join(tempDir, "python");
const countFile = join(tempDir, "runs");
diff --git a/packages/coding-agent/test/kernel-fork-server.test.ts b/packages/coding-agent/test/kernel-fork-server.test.ts
index 8c3a0b0587..2fd472593c 100644
--- a/packages/coding-agent/test/kernel-fork-server.test.ts
+++ b/packages/coding-agent/test/kernel-fork-server.test.ts
@@ -8,15 +8,17 @@ describe("fork-server gating", () => {
delete process.env[FORK_ENV];
});
- it("is disabled unless the flag is set on linux", () => {
+ it("is on by default on linux, opt-out via the flag", () => {
delete process.env[FORK_ENV];
+ expect(isForkServerEnabled()).toBe(process.platform === "linux");
+ process.env[FORK_ENV] = "0";
expect(isForkServerEnabled()).toBe(false);
process.env[FORK_ENV] = "1";
expect(isForkServerEnabled()).toBe(process.platform === "linux");
});
- it("rejects with ForkServerUnavailable when disabled so callers fall back", async () => {
- delete process.env[FORK_ENV];
+ it("rejects with ForkServerUnavailable when opted out so callers fall back", async () => {
+ process.env[FORK_ENV] = "0";
await expect(forkKernel("python3", { connectionPath: "/tmp/nope/connection.json" })).rejects.toBeInstanceOf(
ForkServerUnavailable,
);
@@ -24,7 +26,6 @@ describe("fork-server gating", () => {
it("degrades to ForkServerUnavailable when the interpreter can't start", async () => {
if (process.platform !== "linux") return;
- process.env[FORK_ENV] = "1";
// The spawn errors immediately (ENOENT), so markDead fails the ready promise
// fast rather than waiting out the ready timeout.
await expect(
@@ -34,7 +35,6 @@ describe("fork-server gating", () => {
it("falls back to direct spawn for any PYTHON* startup-env override", async () => {
if (process.platform !== "linux") return;
- process.env[FORK_ENV] = "1";
// The guard treats the whole PYTHON* family as startup-affecting, so even a var
// not explicitly enumerated diverts to direct spawn (no var can be "missed").
for (const key of ["PYTHONPATH", "PYTHONUSERBASE", "PYTHONDONTWRITEBYTECODE"]) {
diff --git a/scripts/boot-bench.mjs b/scripts/boot-bench.mjs
index c71bc931ee..2479a87990 100644
--- a/scripts/boot-bench.mjs
+++ b/scripts/boot-bench.mjs
@@ -32,7 +32,8 @@ function arg(name, def) {
const mode = arg("mode", "gated");
const n = Number(arg("n", 50)) || 50;
-if (mode === "forkserver") process.env.PRIME_AGENT_KERNEL_FORKSERVER = "1";
+// Pin per-mode so the default-on forkserver doesn't leak into the direct-spawn modes.
+process.env.PRIME_AGENT_KERNEL_FORKSERVER = mode === "forkserver" ? "1" : "0";
const { KernelManager } = await import(kernelMod);
const { ensureKernelPython } = await import(bootstrapMod);