Repository navigation
Description
Summary
When a Linux machine runs out of memory because of something an agent ran, the kernel kills bb's server or host daemon instead of the agent's command. Every thread on the machine then stops with "Thread interrupted because the host daemon disconnected". I expected the kernel to kill the runaway agent command and bb to keep serving the other threads.
Two things cause it:
- Provider bridge workers, the agent CLI under them, and every tool command the agent runs inherit the host daemon's
oom_score_adj. The OOM killer therefore ranks bb's own processes and agent work equally and kills the largest single process. When the memory is spread over many processes (parallel test workers, a process-spawning loop), the largest one is bb's server. - The systemd unit that
install-machine.shwrites for a host daemon has noOOMPolicy, so it uses systemd's default,OOMPolicy=stop. When the kernel kills any process in the unit, including the correct victim, systemd stops the whole service.
Versions and environment
[email protected]from npm (npm i -g), run as a systemd user service. The code is unchanged onmainat920804af635265055c876bb8fb43a303b93b6995.- Ubuntu 24.04, Linux 6.8, 16 GB RAM, no swap. Node 24.20.0.
- Providers: Pi, Claude Code.
Steps to reproduce
Part 1, agent work has the same OOM rank as bb. On any Linux machine running a bb host daemon, start a thread with any provider, then run:
for p in $(pgrep -f host-daemon/dist/daemon-bundle.mjs) $(pgrep -f bb-provider-bridge-worker); do
printf '%s %s\n' "$(cat /proc/$p/oom_score_adj)" "$(tr '\0' ' ' < /proc/$p/cmdline | cut -c1-90)"
doneActual: every line has the same value (200 under a systemd user service). The agent CLI and its tool commands, which are children of the bridge worker, have it too.
Part 2, what the kernel does with that rank. This standalone script needs no bb. A "server" holding 500 MB spawns a "provider" that keeps starting 60 MB processes, in a 1.2 GB cgroup with OOMPolicy=continue so that only the kernel's choice is measured:
D=$(mktemp -d)
cat > $D/server.js <<'JS'
const { spawn } = require("node:child_process"); const fs = require("node:fs");
const hold = Buffer.alloc(500 * 1024 * 1024, 1);
const child = spawn(process.execPath, [__dirname + "/provider.js"], { stdio: "ignore", detached: true });
if (process.env.RAISE === "1") {
const own = Number(fs.readFileSync("/proc/self/oom_score_adj", "utf8"));
fs.writeFileSync(`/proc/${child.pid}/oom_score_adj`, String(Math.min(1000, own + 500)));
}
setInterval(() => hold[0], 500);
JS
cat > $D/provider.js <<'JS'
const { spawn } = require("node:child_process");
setInterval(() => spawn(process.execPath, ["-e", "const b=Buffer.alloc(60*1024*1024,1);setInterval(()=>b[0],1000)"], { stdio: "ignore" }), 150);
JS
for raise in 0 1; do
u=oomrepro-$raise
systemd-run --user --quiet --unit=$u -p OOMPolicy=continue -p MemoryMax=1200M -p MemorySwapMax=0 -p RuntimeMaxSec=40 -E RAISE=$raise "$(command -v node)" $D/server.js
sleep 15
echo "RAISE=$raise: unit $(systemctl --user is-active $u), oom kills $(awk '/^oom_kill /{print $2}' /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/app.slice/$u.service/memory.events 2>/dev/null)"
systemctl --user stop $u 2>/dev/null; systemctl --user reset-failed $u 2>/dev/null
donePart 3, the unit's OOM policy:
systemctl --user show 'bb-host-daemon-*' -p OOMPolicyExpected vs actual
Part 2, the script above run twice, verbatim:
RAISE=0: unit failed, oom kills
RAISE=1: unit active, oom kills 88
RAISE=0: unit failed, oom kills
RAISE=1: unit active, oom kills 89
With equal scores the kernel kills the 500 MB "server", the unit's main process, so the unit fails and its cgroup, along with the kill count, is gone. With the provider subtree raised by 500, the kernel killed only provider children (88–89 kills in 15 s) and the server kept running.
Part 3 actual: OOMPolicy=stop. Running the Part 2 script without -p OOMPolicy=continue stops the unit in both runs, because systemd stops the service after the first kill even when the kernel chose a provider child.
Expected: a host daemon's agent work is a likelier OOM victim than bb's own processes, and an OOM kill of agent work doesn't stop the service.
Evidence
From my server: one agent thread ran a command that kept starting Node processes, an old copy of #6435 that #6436 fixes for current releases. Each copy was about 33 MB. The kernel killed bb's server four times in 50 minutes, and each time every thread on the machine was interrupted:
kernel: Out of memory: Killed process 1871185 (MainThread) total-vm:20606228kB, anon-rss:535912kB, ... oom_score_adj:200
kernel: oom-kill:...,global_oom,task_memcg=/user.slice/user-1000.slice/[email protected]/app.slice/<bb unit>.service,task=MainThread,...
systemd[1085]: <bb unit>.service: A process of this unit has been killed by the OOM killer.
systemd[1085]: <bb unit>.service: Failed with result 'oom-kill'.
The kernel's task dump at the last kill showed 380 MainThread processes from the agent's command at about 33 MB each (12.5 GB in total), all at oom_score_adj 200 like the server. The server was the largest single process, so it was the victim.
Code:
- Provider bridge workers are spawned with no change to their OOM rank:
runtime-provider-process.ts#L384-L390 - The host-daemon unit leaves
OOMPolicyat its default:install-machine.sh#L1172-L1177
What you ruled out
- Not Script automations that call bb spawn bb endlessly until the server runs out of memory #6435. That issue is one way agent work can exhaust memory, and Stop bb-app's CLI entry from re-launching itself through BB_CLI #6436 fixed it for current releases. This issue is about which process the kernel kills whatever the cause, such as a parallel test run or a large build.
- Not covered by Keep a supervised host daemon running when a memory killer stops it #6159. That PR makes a killed daemon come back and names bb's processes so a userspace killer like earlyoom can spare them. It does not change the kernel OOM killer's choice or the unit's
OOMPolicy. Its diff has nooom_score_adjorOOMPolicylines. - Not a cgroup limit on the bb unit:
MemoryMax,MemoryHighandManagedOOMMemoryPressurewere unset andsystemd-oomdwas inactive. The kills wereglobal_oom. - macOS and Windows: not affected in this form.
oom_score_adjandOOMPolicyare Linux and systemd only.
Suggested priority and effort
Hits any Linux machine where agents run memory-heavy work. When it triggers, every thread on the machine is interrupted, not only the one that caused it. Small fix: raise the bridge worker's oom_score_adj after spawning it, and add OOMPolicy=continue to the generated unit.
AGENT GENERATED. Found while investigating repeated "host daemon disconnected" interruptions on my own server, with kernel logs, the systemd journal and bb's event log.
Activity
bb-slop-cop commentedon Nov 4, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilothost.partial-repro.Let the OOM killer take agent work before bb (get-bb#7039)