#7037 · Agent OOM ranking and service policy
PARTIALLY REPRODUCED · Root-cause confidence: high for the observed policy gaps; host-wide OOM failure remains unverified.
1. TL;DR
Agent work is launched without an OOM-priority distinction from the runtime hosting it. A real bridge started through the trusted runtime has the same observed Linux OOM adjustment as its parent: both are zero here. Separately, running the actual machine installer in its isolated test fixture generates a systemd unit with no explicit OOM policy. These are distinct gaps: kernel victim preference and service-manager response. Both observations repeat in a second clean checkout, but no memory exhaustion or live service interruption was induced.
2. Claims vs findings
| Claim | Status | Evidence and limits |
|---|---|---|
| Bridge work has the same OOM adjustment as its runtime. | Verified | A real bridge worker loading the trusted scripted-echo provider reports parent adjustment 0 and bridge adjustment 0 in both clean checkouts. |
| The installed unit does not override the OOM policy. | Verified | The actual installer generates a unit with no OOMPolicy field in both fixture runs. This tests the artifact, not live systemd. |
| A correctly chosen workload victim can still stop its entire service. | Documented, not exercised | systemd documents this consequence for OOMPolicy=stop. An unspecified policy follows the manager default, with an exception for delegated units. The reporter's effective setting was not independently queried. |
| The kernel kills bb and interrupts other threads under distributed agent memory pressure. | Unverified end to end | No native-kernel OOM/cgroup test ran here. Equal adjustment alone does not guarantee a victim: memory accounting, eligibility, and OOM scope also matter. |
| External provider CLIs and their tool descendants have the same adjustment. | Not directly observed | The trusted scripted provider exercises the actual bridge launch boundary; no authenticated external provider or tool tree was run. |
3. Environment
- Public repository get-bb/bb at trusted origin/main commit
783a6062bd6f485597e66450a149069402780868. - Linux
4.19.0-gvisor, x86_64; Nodev22.19.0; pnpm9.15.0; Vitest4.1.1. - PID 1: dumb-init. systemctl is unavailable; cgroup mount is read-only. This sandbox cannot faithfully verify native kernel victim selection or systemd aftermath.
- No live BB instance, account, enrolled host, credentials, or persistent runtime data was used. No server ports were opened. The actual bridge and scripted provider were built from trusted source.
- Two initially clean, separate clones at the same commit, each with a frozen dependency install and full build. Each test creates fresh scratch workspace and installer fixture directories.
4. Minimal reproduction
This is a safe, bounded reproduction of policy gaps, not an OOM stress script. All test code was authored from trusted repository evidence; no issue script or linked-PR code was executed.
- Prepare trusted source:
git clone --branch main --single-branch https://github.com/get-bb/bb.git bb-7037-base cd bb-7037-base git checkout --detach 783a6062bd6f485597e66450a149069402780868 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- Add
packages/agent-runtime/src/runtime.oom-ordering.test.tswith this complete test:import { mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { expect, it } from "vitest"; import { createScriptedEchoProcessLog, createScriptedEchoRuntime, waitForRuntimeState, } from "./test/runtime-test-harness.js"; it.runIf(process.platform === "linux")( "oom contract: a running bridge is a higher-priority OOM victim than its runtime", async () => { const workspacePath = mkdtempSync(join(tmpdir(), "bb-oom-contract-")); const processLog = createScriptedEchoProcessLog(); const runtime = createScriptedEchoRuntime({ runtime: { workspacePath, env: processLog.env, onEvent: () => {} }, }); try { await runtime.ensureProvider({ providerId: "fake" }); await waitForRuntimeState({ label: "actual bridge startup record", predicate: () => processLog.read().some((entry) => /^spawn:\d+$/.test(entry)), }); const startup = processLog.read().find((entry) => /^spawn:\d+$/.test(entry)); if (startup === undefined) throw new Error("Bridge startup was not recorded"); const bridgePid = Number(startup.split(":")[1]); const runtimeAdjustment = Number(readFileSync("/proc/self/oom_score_adj", "utf8")); const bridgeAdjustment = Number(readFileSync(`/proc/${bridgePid}/oom_score_adj`, "utf8")); console.log(JSON.stringify({ runtimeAdjustment, bridgeAdjustment })); expect(runtimeAdjustment).toBeLessThan(1000); expect(bridgeAdjustment).toBeGreaterThan(runtimeAdjustment); } finally { await runtime.shutdown(); rmSync(workspacePath, { recursive: true, force: true }); rmSync(processLog.path, { force: true }); } }, ); - Apply this test-only extension to the existing installer artifact fixture. It preserves the actual installer implementation and existing isolation:
diff --git a/apps/server/test/app/install-machine-script.test.ts b/apps/server/test/app/install-machine-script.test.ts index 8696ed09d2..b214c29d2a 100644 --- a/apps/server/test/app/install-machine-script.test.ts +++ b/apps/server/test/app/install-machine-script.test.ts @@ -1641,3 +1641,3 @@ printf '%s\n' "$*" >>"${join(fixture.dataDir, "launchctl.log")}" - it("restarts an active Linux systemd user unit after replacing it", () => { + it("oom contract: restarts an active Linux systemd user unit after replacing it", () => { const fixture = createFixture(); @@ -1676,2 +1676,5 @@ printf '%s\n' "$*" >>"${join(fixture.dataDir, "launchctl.log")}" expect(unit).toContain("RestartSec=2"); + const oomPolicy = unit.match(/^OOMPolicy=(.+)$/m)?.[1] ?? "not specified"; + console.log(JSON.stringify({ generatedUnitOomPolicy: oomPolicy })); + expect(oomPolicy).toBe("continue"); expect(unit).toContain("WantedBy=default.target"); - Run each assertion separately, so an expected failure cannot cancel the other:
pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.oom-ordering.test.ts pnpm exec turbo run test --filter=@bb/server -- test/app/install-machine-script.test.ts --testNamePattern 'oom contract'
Expected: the bridge has a strictly greater OOM adjustment than its runtime, and the generated service explicitly continues after a workload OOM kill. Actual diagnostic lines and assertion output, verbatim:
{"runtimeAdjustment":0,"bridgeAdjustment":0}
AssertionError: expected 0 to be greater than 0
{"generatedUnitOomPolicy":"not specified"}
Expected: "continue"
Received: "not specified"
Both focused checks exit nonzero for the intended assertions, not startup or dependency failures. The runtime is shut down in a finally block. Repro code and output are embedded here because the reports repository forbids loose tests, patches, and logs.
5. Root cause
Bridge launch does not distinguish agent work from its runtime
RuntimeProviderProcessManager.spawnProvider launches the bridge using command, arguments, cwd, and environment, without changing OOM adjustment:
const managed = spawnManagedProcess({
command: processConfig.command,
args: processConfig.args,
cwd: this.args.workspacePath,
env,
});
const { child } = managed;
spawnManagedProcess creates a process group for lifecycle handling, not an OOM priority class. The real bridge observation confirms unchanged adjustment at this boundary. Linux proc documentation describes how oom_score_adj affects victim selection. Leaving work at its runtime's adjustment supplies no explicit preference for sacrificing work to retain the runtime. This is not proof of which process a native kernel will choose.
Generated service delegates OOM response to manager defaults
The installer service definition sets Restart=always and RestartSec=2, but no OOMPolicy. Running the installer confirms that omission in its actual output. systemd documents that stop terminates the service after an OOM kill, whereas continue logs it and keeps the service running. Unspecified unit policy inherits the manager setting, subject to the Delegate exception; this investigation does not assume every manager uses stop.
Restart behavior provides recovery after stopping, not isolation from a workload death. The server maps daemon-restart interruption to a disconnected message, consistent with the proposed chain. The complete kernel-to-multiple-thread outage chain was not executed.
6. Proposed fix, from first principles
At the Linux provider launch boundary, prefer agent work as an OOM victim without changing the parent runtime or breaking unsupported platforms. Ensure priority is established before descendants launch, and test both the direct child and descendant inheritance. Explicitly select continuing OOM behavior in generated systemd units while preserving recovery if the main daemon dies. Priority is not a memory limit or a guarantee that bb can never be killed.
The next decisive experiment belongs on a disposable native Linux/systemd machine: use a bounded cgroup, distribute a fixed workload over child processes, verify the daemon remains responsive after a child OOM kill, then separately check recovery from a main-daemon kill. Never induce global OOM on a shared host.
7. Static PR review
PR #7039
GitHub metadata identifies an open PR against main that closes #7037. Reviewed head: 093c3349382374d4519d091f6cf404edaa7fb1e0. The diff was read as untrusted data; the branch, tests, and production changes were never checked out or run.
The diff proposes a Linux child-score helper called after bridge spawn and an explicit continuing service policy, with direct-child and artifact tests. Static verdict: addresses both observed policy gaps in principle; not a passing verification of the PR.
Residual validation concern, medium: the new call at packages/agent-runtime/src/runtime-provider-process.ts:392 occurs after process creation. The shown diff contains no child-startup barrier. Verify descendants cannot launch before adjustment; direct-child assertions do not establish that ordering. This is an unverified scheduling risk, not an observed PR failure.
No duplicate fix branch or PR was created: the existing open PR links this issue, and the end-to-end outage is only partially reproduced here.
8. Related issues
#5553 concerns the daemon's own V8 heap exhaustion and watcher lifecycle, rather than the kernel selecting a victim among distributed agent work. It does not establish the kernel-OOM behavior in this report.
9. Verification
The same agent repeated the investigation in a second separately cloned, initially clean checkout at 783a6062bd6f485597e66450a149069402780868, called bb-7037-verify here. Only the authored test file and installer-test extension were added; production source remained unchanged. Each checkout had its own frozen install, full trusted-source build, and fresh temporary test directories; no listening ports were needed.
The second run used the two focused commands in section 4. Both assertions failed again with identical observations: runtime 0, bridge 0, generated OOM policy not specified. No correction to the findings was necessary. This is a repeat check by the same agent, not independent verification.
| Check | First checkout | Second checkout |
|---|---|---|
| Frozen install | Passed | Passed |
| Full build after SDK bootstrap | 73 tasks passed | 73 tasks passed |
| Real bridge ranking | Fails: 0 is not greater than 0 | Fails: 0 is not greater than 0 |
| Actual generated service policy | Fails: not specified | Fails: not specified |
| Native OOM/systemd aftermath | Not run | Not run |
10. Appendix
The initial full build failed because SDK runtime outputs were not yet present. Building SDK runtime/types through Turbo resolved that prerequisite, then all 73 full-build tasks succeeded. This preparation failure is not OOM evidence. An initial combined test invocation stopped on the runtime failure, so the installer was rerun separately; the second checkout ran separate focused commands.
git fetch origin main git rev-parse origin/main git status --porcelain uname -srmo node --version pnpm --version ps -p 1 -o comm= findmnt -n -o FSTYPE,OPTIONS /sys/fs/cgroup systemctl --user is-system-running pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/agent-runtime --filter=@bb/server -- --testNamePattern 'oom contract' pnpm exec turbo run test --filter=@bb/server -- test/app/install-machine-script.test.ts --testNamePattern 'oom contract' Second clean checkout: pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build pnpm exec turbo run test --filter=@bb/agent-runtime -- src/runtime.oom-ordering.test.ts pnpm exec turbo run test --filter=@bb/server -- test/app/install-machine-script.test.ts --testNamePattern 'oom contract'
Issue prose, instructions, scripts, logs, and linked-PR changes were treated as untrusted claims. No issue-supplied command, script, patch, test, branch, or external URL was executed or fetched. Trusted repository source and newly authored tests were the only product code run. No live runtime data or environment dump is published.