Skip to content

[Bug]: Kernel OOM killer kills agents instead of the jobs they detach with systemd-run --user (score 800 vs 200) #45841

Done

Description

@josephv123

Area

packages/shared/src/AgentScope.ts (agent OOM score), apps/server/src/cloud/serviceProtection.ts (t3 service protect)

Steps to reproduce

  1. Linux with a systemd user manager. t3 service protect makes it more likely, but it isn't required.
  2. From an agent thread, start a long job detached through the user manager, as agents often do for evals and data builds: systemd-run --user python big_job.py.
  3. Compare scores from the agent's shell:
    cat /proc/self/oom_score_adj                                         # 800 (agent and its tools)
    systemd-run --user --wait --pipe cat /proc/self/oom_score_adj        # 200 (detached job)
    
  4. Let the detached job use most of RAM until the kernel's global OOM (out-of-memory) killer runs.

Smaller repro in a capped cgroup instead of a real global OOM. A 60 MB stand-in "agent" at 800 sits beside a hog that runs into MemoryMax=256M:

cat > demo.sh <<'X'
sh -c 'echo 800 >/proc/self/oom_score_adj; exec python3 -c "b=bytearray(60<<20); import time; time.sleep(20)"' &
sleep 1; python3 -c 'b=bytearray(400<<20)'
X
systemd-run --user --wait -p MemoryMax=256M -p MemorySwapMax=0 -p OOMPolicy=continue -p OOMScoreAdjust=200 sh demo.sh
systemd-run --user --wait -p MemoryMax=256M -p MemorySwapMax=0 -p OOMPolicy=continue -p OOMScoreAdjust=900 sh demo.sh

With the hog at 200, the kernel kills the 60 MB bystander (score 800) first, then the hog. With the hog at 900, only the hog is killed.

Expected behavior

The job that is using the memory gets killed. Agents should be the first victims only ahead of the T3 server and the user's session, not ahead of the jobs they start.

Actual behavior

Every agent and its tools run at oom_score_adj 800. A job an agent hands to the user manager (systemd-run --user, systemctl --user start) doesn't inherit that. It gets the manager's DefaultOOMScoreAdjust, which t3 service protect sets to 200 itself. The job also leaves the agents slice, so the slice's MemoryHigh/MemoryMax don't apply to it.

The kernel's score is roughly memory used plus oom_score_adj / 1000 × (RAM + swap). With 13 GB RAM and 17 GB of swap, the 600-point gap is worth about 18 GB. So the kernel kills every agent, even an idle one, before any detached job that uses less than that.

On the box below this happened for real. A python job in run-p4069936-i8252105.service (score 200) grew to about 1.3 GB resident plus 8.4 GB in swap. The kernel then killed ten claude processes at score 800 one after another. Their resident memory was 25–155 MB each. It killed the python job last. Each claude kill also stopped that agent's whole scope (OOMPolicy=stop), so subagents went down too and their threads failed with "Killed: out of memory".

Impact

When a detached job leaks or simply grows too big, the agents die and the job survives, over and over. On a shared box that means every running thread, not just the one that started the job. Agents are told to detach long jobs so the jobs survive turn ends and server restarts, so this isn't rare.

Version or commit

Nightly 0.1.14-nightly.20261130.5465. AGENT_OOM_SCORE_ADJ = 800 and DefaultOOMScoreAdjust=200 are unchanged on main at 05bd8e5.

Environment

Ubuntu 26.04 Server, systemd 259, kernel 7.0, 13 GB RAM plus 17 GB swap (zram and a file). t3 service protect applied, so the server is at -900. systemd-oomd is not installed (Ubuntu Server doesn't ship it). Claude Code agents.

Logs or stack traces

kernel: oom-kill:...,global_oom,task_memcg=/user.slice/user-1000.slice/[email protected]/app.slice/app-t3code.slice/app-t3code-agents.slice/app-t3code-agents-7a9722fa0109.slice/t3code-claude-215beb17.scope,task=claude,pid=3996667,uid=1000
kernel: Out of memory: Killed process 3996667 (claude) ... anon-rss:51488kB ... oom_score_adj:800
...   (8 more claude kills, anon-rss 25-155 MB, all oom_score_adj:800)
kernel: Out of memory: Killed process 4099441 (claude) ... anon-rss:127648kB ... oom_score_adj:800

task dump at the first kill (pid, rss pages, swap pages, oom_score_adj):
  4069946  python  rss 341278  swap 2198245  adj 200   <- ~9.7 GB, the cause
  4045418  python  rss 474437  swap 1008038  adj 200

systemd[6979]: run-p4069936-i8252105.service: Failed with result 'oom-kill'.   (only after all ten agents)

Workaround

Give detached jobs a score above the agents:

  • per job: systemd-run --user -p OOMScoreAdjust=900 -p MemoryMax=…
  • for unnamed jobs: a user drop-in at ~/.config/systemd/user/run-.service.d/oom.conf with [Service] OOMScoreAdjust=900. systemd's prefix drop-ins apply to transient run-*.service units, which I checked on systemd 259. Jobs started with --unit=<name> still need the -p flag.

Possible fixes

These are for maintainers to choose from. I haven't sent a PR.

  1. Lower the agent score so size matters again. For example 300 instead of 800. It stays above user services (200) and the unprotected server (100, from the unit file), and far above the protected server (-900). The margin over a detached job drops from about 60% of RAM+swap to about 10%, so a hog much bigger than an agent dies first. A real leak inside the agent's own scope is still the biggest process there, so the original [Bug]: systemd-oomd kills the entire T3 Code scope when an agent-spawned child workload exhausts memory (Linux) #5248 case is unaffected. This is a one-line change, plus the ACP copy in AcpSessionRuntime.ts.
  2. Have t3 service protect write the run-.service.d drop-in above (OOMScoreAdjust=900) next to its DefaultOOMScoreAdjust=200. This only covers default-named systemd-run jobs.

Note on #41079 / #41080 (which remove the 800 raise): agents would then inherit the server's score. After t3 service protect, that's -900, so agents and their tools would become nearly unkillable and the kernel would pick the user's other services first.

Related: #5248 (why agents got their own scopes), #37876 (OOMPolicy=stop takes down the whole agent when one process in its scope is killed), #41079.

Filed by

Claude Opus 5.5 in Claude Code via T3 Code.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions