Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Server image: collect exited processes on hosts with no init, and name spawn EAGAIN
Aditya Umalec87b8ec0cab0
diff --git a/Dockerfile b/Dockerfileindex 028d0bc881..21b3f2f94e 100644--- a/Dockerfile+++ b/Dockerfile@@ -20,10 +20,11 @@# ...) and OpenMausBot's own state (~/.openmausbot) persist across container# restarts.#-# A plain `docker run` of either image wants `--init --shm-size=512m`, as the-# compose files set: the bots' browsers leave exited processes for an init to-# collect, and Chrome needs shared memory (docs/browser-packaging.md, "Process-# hygiene"). On Fly Machines (the Cloud home) Fly's own init is PID 1.+# The bots' browsers leave exited processes for an init to collect, and Chrome+# needs shared memory (docs/browser-packaging.md, "Process hygiene"). The+# server image starts under tini, so a host with no `--init` switch (Railway,+# for one) still collects them; a plain `docker run` wants `--shm-size=512m`.+# On Fly Machines (the Cloud home) Fly's own init is PID 1.FROM caddy:2.10.2 AS edge# Official Caddy carries a privileged-port file capability. The Cloud home's@@ -74,9 +75,10 @@ RUN arch=x64 && if [ "$TARGETARCH" = arm64 ]; then arch=arm64; fi \FROM node:24-bookworm-slim AS runtime# Install Chrome's Bookworm libraries directly: agent-browser --with-deps# invokes sudo even as root, and this image deliberately does not ship sudo.-# git + curl: agent CLIs shell out to git; curl backs the healthcheck+# git + curl: agent CLIs shell out to git; curl backs the healthcheck. tini: the+# server image's init, for hosts that add noneRUN apt-get update \- && apt-get install -y --no-install-recommends ca-certificates curl git \+ && apt-get install -y --no-install-recommends ca-certificates curl git tini \libxcb-shm0 libx11-xcb1 libx11-6 libxcb1 libxext6 libxrandr2 \libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libgtk-3-0 \libpangocairo-1.0-0 libpango-1.0-0 libatk1.0-0 libcairo-gobject2 \@@ -251,6 +253,9 @@ VOLUME ["/data"]USER mausHEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \CMD curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot || exit 1+# -s: under a runtime's own init (compose's `init: true`) tini is not PID 1,+# and as a subreaper it still collects what the server's children leave.+ENTRYPOINT ["/usr/bin/tini", "-s", "--"]# The launcher runs dist-server/index.js and starts it again when it asks to# (a copied workspace committing, server/restart.ts), so the container, and a# Caddy sharing its network, stays up through that restart.diff --git a/docs/browser-packaging.md b/docs/browser-packaging.mdindex abdbe880e2..099f17a408 100644--- a/docs/browser-packaging.md+++ b/docs/browser-packaging.md@@ -235,18 +235,20 @@ same rules hold on the desktop, a server and Cloud:environments, so there a Chrome whose daemon was killed is not found.**Containers.** Chrome's helper processes need something to collect them-once their parent exits, and Chrome needs shared memory. Both Docker compose-files and the Podman one set `init: true` and `shm_size: 512m`, as-OpenMausBot's desktop containers do (`--shm-size 512m`); a plain-`docker run` wants `--init --shm-size=512m`. agent-browser 0.37.0 itself-adds `--no-sandbox` and `--disable-dev-shm-usage` when it sees-`/.dockerenv` or `/run/.containerenv`, runs as root or under CI, or finds-docker, kubepods or lxc in `/proc/1/cgroup`. A runtime that shows none of-these (a Kubernetes pod on cgroup v2, for one) needs `/dev/shm` room of its-own (on Kubernetes, an `emptyDir` with `medium: Memory`). The image does-not set `AGENT_BROWSER_ARGS`: OpenMausBot hands its browsers a curated-environment that would not carry it. On Fly Machines (the Cloud home) Fly's-own init runs as PID 1.+once their parent exits, and Chrome needs shared memory. The server image+starts under `tini -s`, so a host with no init switch (Railway, for one)+still collects them. Both Docker compose files and the Podman one set+`init: true` and `shm_size: 512m`, as OpenMausBot's desktop containers do+(`--shm-size 512m`); a plain `docker run` wants `--shm-size=512m`.+agent-browser 0.37.0 itself adds `--no-sandbox` and+`--disable-dev-shm-usage` when it sees `/.dockerenv` or+`/run/.containerenv`, runs as root or under CI, or finds docker, kubepods or+lxc in `/proc/1/cgroup`. A runtime that shows none of these (a Kubernetes+pod on cgroup v2, for one) needs `/dev/shm` room of its own (on Kubernetes,+an `emptyDir` with `medium: Memory`). The image does not set+`AGENT_BROWSER_ARGS`: OpenMausBot hands its browsers a curated environment+that would not carry it. On Fly Machines (the Cloud home) Fly's own init+runs as PID 1.## Video recordingdiff --git a/server/cli-probe.test.ts b/server/cli-probe.test.tsindex cb44ea577a..d0e824f47f 100644--- a/server/cli-probe.test.ts+++ b/server/cli-probe.test.ts@@ -1,8 +1,19 @@-import { expect, it } from "vitest";+import { expect, it, vi } from "vitest";import { testCliBinary } from "./cli-probe.ts";import { OpenCodeDriver } from "./drivers/acp/opencode-go.ts";+const FULL_PROCESS_TABLE_CLI = "omb-eagain-cli-for-this-test";++vi.mock("./procs.ts", async (importOriginal) => {+ const actual = await importOriginal<typeof import("./procs.ts")>();+ const execCli: typeof actual.execCli = (cli, args, opts, cb) => {+ if (cli !== FULL_PROCESS_TABLE_CLI) return actual.execCli(cli, args, opts, cb);+ cb(Object.assign(new Error(`spawn ${cli} EAGAIN`), { code: "EAGAIN" }), "");+ };+ return { ...actual, execCli };+});+it("offers the install steps for a CLI that is missing, without the server-only download pins", async () => {const result = await testCliBinary("omb-missing-cli-for-this-test", OpenCodeDriver);expect(result.ok).toBe(false);@@ -10,3 +21,10 @@ it("offers the install steps for a CLI that is missing, without the server-onlyexpect(OpenCodeDriver.install?.standalone).toBeDefined();expect(result.install).not.toHaveProperty("standalone");});++it("offers no install for a CLI that could not start because the machine is out of processes", async () => {+ const result = await testCliBinary(FULL_PROCESS_TABLE_CLI, OpenCodeDriver);+ expect(result.ok).toBe(false);+ expect(result.message).toContain("limit of running processes");+ expect(result).not.toHaveProperty("install");+});diff --git a/server/cli-probe.ts b/server/cli-probe.tsindex 499227bab5..9275f93e91 100644--- a/server/cli-probe.ts+++ b/server/cli-probe.ts@@ -26,15 +26,15 @@ export async function testCliBinary(const e = err as NodeJS.ErrnoException & { killed?: boolean };// Node's err.code is an errno string only for spawn failures; a non-zero exit gives the status, a timeout null with killed.const exceededBuffer = e.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";- const isSpawnError = typeof e.code === "string" && !exceededBuffer;+ const spawnFailure = typeof e.code === "string" && !exceededBuffer ? describeSpawnFailure(e, cli) : undefined;const message = exceededBuffer? "CLI test produced more than 64 KiB of output"- : isSpawnError- ? describeSpawnFailure(e, cli).message+ : spawnFailure+ ? spawnFailure.message: e.killed? "CLI test timed out after 10s": `CLI exited with error ${String(e.code)}: ${(stderrOf(err) || "").slice(0, 200) || err.message.split("\n")[0]}`;- resolve({ ok: false, message, ...(driver?.install && isSpawnError ? { install: clientInstall(driver.install) } : {}) });+ resolve({ ok: false, message, ...(driver?.install && spawnFailure?.setup ? { install: clientInstall(driver.install) } : {}) });return;}const version = stdout.trim().split("\n")[0];diff --git a/server/procs.test.ts b/server/procs.test.tsindex f01ef6b496..0e6f8fdf95 100644--- a/server/procs.test.ts+++ b/server/procs.test.ts@@ -52,6 +52,16 @@ describe("Windows CLI argument safety", () => {});});+describe("spawn EAGAIN", () => {+ it("says the machine ran out of processes instead of the raw errno", () => {+ const error = Object.assign(new Error("spawn claude EAGAIN"), { code: "EAGAIN" });+ expect(describeSpawnFailure(error, "claude")).toEqual({+ message: "`claude` couldn't start: this machine has reached its limit of running processes. Run fewer bots at once, or restart the server if this continues",+ setup: false,+ });+ });+});+describe("spawn ENOENT", () => {const enoent = () => Object.assign(new Error("spawn codex ENOENT"), { code: "ENOENT" });diff --git a/server/procs.ts b/server/procs.tsindex 9034f797ab..e00bba4002 100644--- a/server/procs.ts+++ b/server/procs.ts@@ -438,6 +438,8 @@ export function describeSpawnFailure(err: NodeJS.ErrnoException, cli: string, cw}if (err.code === "EACCES" || err.code === "EPERM")return { message: `\`${cli}\` isn't executable — check its file permissions`, setup: true };+ if (err.code === "EAGAIN")+ return { message: `\`${cli}\` couldn't start: this machine has reached its limit of running processes. Run fewer bots at once, or restart the server if this continues`, setup: false };if (err.code === "ENAMETOOLONG")return {message: `\`${cli}\` received too much launch data for Windows; update this provider or pass its prompt through stdin/a file`,