Skip to content

Linux: an agent that exhausts memory gets bb's server or host daemon OOM-killed instead of itself #7037

Closed

Description

@scowalt

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:

  1. 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.
  2. The systemd unit that install-machine.sh writes for a host daemon has no OOMPolicy, 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 on main at 920804af635265055c876bb8fb43a303b93b6995.
  • 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)"
done

Actual: 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
done

Part 3, the unit's OOM policy:

systemctl --user show 'bb-host-daemon-*' -p OOMPolicy

Expected 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:

What you ruled out

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

  1. added theissue type on Nov 4, 2026
  2. added
    host
    partial-repro
    on Nov 4, 2026
  3. bb-slop-cop commented on Nov 4, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification applied: Bug · Priority High · Effort Medium · host.
    • Report: Reproduction and root cause.
    • Verdict: PARTIALLY REPRODUCED · confidence high for the observed policy gaps · reproduction label: partial-repro.
    • Root cause: Bridge workers retain the runtime's OOM adjustment, and generated systemd units omit an explicit OOM policy. Tests against unchanged production code in two clean trusted-main checkouts confirm equal adjustments and the missing policy. Native kernel OOM selection and live systemd service interruption remain unverified in this sandbox.
    • No new PR: Open PR Let the OOM killer take agent work before bb #7039 already links and closes this issue; no duplicate fix was created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hostpartial-repro

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions