fix(server): agents that may not use the host's swap are no longer throttled for hours #43663
main fromrefs/pull/43663/head·opened View on GitHubProblem#
On a Linux host that has swap but forbids the agents from using it (memory.swap.max is 0 on a cgroup above them), T3 Code still gives the agents slice a finite MemoryHigh. The agents cannot swap, so reclaim at MemoryHigh throttles every agent for hours and MemoryMax never kills the runaway: the stall from #39195, on a host whose SwapTotal is not 0. Boat VMs ship this way (a 2 GiB swapfile and MemorySwapMax=0 on user.slice). Report: #43662.
Change#
When /proc/meminfo shows swap, the agents-slice policy also reads memory.swap.max on app-t3code-agents.slice and each cgroup above it. A 0 anywhere counts as no swap, so the slice gets the existing no-swap policy: MemoryHigh=infinity with the same MemoryMax. The slice's cgroup path comes from systemctl --user show once the slice is active (the startup probe activates it) and is kept after that. Like the SwapTotal check from #39287, this runs at server start and at each agent launch.
Scope#
Fixes #43662. It is the case #39287 lists under "Not in this change" ("A per-cgroup memory.swap.max=0 limit on a host that has swap still gets the finite MemoryHigh"), which #39195 asked for. It does not cover exhausted swap (#39976) or host-managed limits (#24717).
Verification#
Ran the real server (vp run dev:server with a fresh --home-dir, one at a time) on a Boat VM: Ubuntu 24.04.4, kernel 6.8, systemd 255 user manager, 16 GiB RAM, 2 GiB swap, MemorySwapMax=0 on user.slice as Boat ships it. Base main at b99dab9495, then the same tree with this change. With each server running, two memory jobs ran in scopes under app-t3code-agents.slice (systemd-run --user --scope --slice=app-t3code-agents.slice --property=OOMPolicy=stop): one that fits under MemoryMax (11 GiB) and a runaway past it (14 GiB). Kernel counters were sampled every 5 s.
Before (main) | After (this change) | |
|---|---|---|
Server log Agent scopes are on | high: 10326347776, max: 12576599040 | high: 'infinity', max: 12576599040 |
Slice memory.high | 10326347776 | max |
11 GiB job (under MemoryMax) | Held at 9.8 to 10.0 GiB for 90 s, then stopped by the script: +25,693 high events, 75.8 s of full memory stall | Finished in 8.0 s, 0 high events, no stall |
| 14 GiB runaway | Held at about 10 GiB for 90 s, never killed (oom_kill 0), stopped by the script | OOM-killed in its own scope within 10 s: Result=oom-kill, oom_kill 1 |
Full run log
== host
6.8.0-117-generic
systemd 255 (255.4-1ubuntu8.16)
MemTotal: 16375780 kB
SwapTotal: 2097148 kB
user.slice MemorySwapMax=0
/sys/fs/cgroup/user.slice/memory.swap.max=0
======== before: b99dab9495 fix(mobile): fixed-time scheduled tasks keep their time on DST days (#43610) ()
server log: [17:23:41.757] INFO (#33): Agent scopes are on {
slice /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/app-t3code.slice/app-t3code-agents.slice
memory.high=10326347776 memory.max=12576595968 memory.swap.max=max
-- job before-fits: allocate 11 GiB, watch up to 90s
t= 5s state=active slice_mem= 4.22GiB high_events=+0 full_stall=+0.0s last=" 4.8s allocated 4 GiB"
t= 10s state=active slice_mem= 9.77GiB high_events=+2590 full_stall=+1.5s last=" 7.7s allocated 9 GiB"
t= 15s state=active slice_mem= 9.82GiB high_events=+6313 full_stall=+5.3s last=" 7.7s allocated 9 GiB"
t= 20s state=active slice_mem= 9.85GiB high_events=+8778 full_stall=+10.3s last=" 7.7s allocated 9 GiB"
t= 25s state=active slice_mem= 9.86GiB high_events=+10920 full_stall=+15.3s last=" 7.7s allocated 9 GiB"
t= 30s state=active slice_mem= 9.88GiB high_events=+12824 full_stall=+19.6s last=" 7.7s allocated 9 GiB"
t= 35s state=active slice_mem= 9.90GiB high_events=+14422 full_stall=+23.6s last=" 7.7s allocated 9 GiB"
t= 40s state=active slice_mem= 9.91GiB high_events=+15850 full_stall=+28.1s last=" 7.7s allocated 9 GiB"
t= 45s state=active slice_mem= 9.92GiB high_events=+17261 full_stall=+33.1s last=" 7.7s allocated 9 GiB"
t= 50s state=active slice_mem= 9.93GiB high_events=+18502 full_stall=+38.1s last=" 7.7s allocated 9 GiB"
t= 55s state=active slice_mem= 9.95GiB high_events=+19607 full_stall=+43.1s last=" 7.7s allocated 9 GiB"
t= 60s state=active slice_mem= 9.96GiB high_events=+20644 full_stall=+48.1s last=" 7.7s allocated 9 GiB"
t= 65s state=active slice_mem= 9.97GiB high_events=+21613 full_stall=+53.1s last=" 7.7s allocated 9 GiB"
t= 70s state=active slice_mem= 9.99GiB high_events=+22514 full_stall=+58.1s last=" 7.7s allocated 9 GiB"
t= 75s state=active slice_mem=10.00GiB high_events=+23364 full_stall=+61.9s last=" 7.7s allocated 9 GiB"
t= 80s state=active slice_mem=10.00GiB high_events=+24180 full_stall=+65.9s last=" 7.7s allocated 9 GiB"
t= 85s state=active slice_mem=10.01GiB high_events=+24945 full_stall=+70.8s last=" 7.7s allocated 9 GiB"
t= 90s state=active slice_mem=10.02GiB high_events=+25693 full_stall=+75.8s last=" 7.7s allocated 9 GiB"
still running after 90s: stopping it
scope Result=success oom_kill=0
output tail: 7.2s allocated 8 GiB 7.7s allocated 9 GiB
-- job before-runaway: allocate 14 GiB, watch up to 90s
t= 5s state=active slice_mem= 9.76GiB high_events=+1519 full_stall=+0.7s last=" 3.8s allocated 9 GiB"
t= 10s state=active slice_mem= 9.81GiB high_events=+5685 full_stall=+4.9s last=" 3.8s allocated 9 GiB"
t= 15s state=active slice_mem= 9.85GiB high_events=+8303 full_stall=+9.2s last=" 3.8s allocated 9 GiB"
t= 20s state=active slice_mem= 9.88GiB high_events=+10326 full_stall=+13.5s last=" 3.8s allocated 9 GiB"
t= 25s state=active slice_mem= 9.90GiB high_events=+11992 full_stall=+17.6s last=" 3.8s allocated 9 GiB"
t= 30s state=active slice_mem= 9.92GiB high_events=+13454 full_stall=+22.6s last=" 3.8s allocated 9 GiB"
t= 35s state=active slice_mem= 9.93GiB high_events=+14678 full_stall=+25.9s last=" 3.8s allocated 9 GiB"
t= 40s state=active slice_mem= 9.95GiB high_events=+15800 full_stall=+30.4s last=" 3.8s allocated 9 GiB"
t= 45s state=active slice_mem= 9.96GiB high_events=+16837 full_stall=+35.4s last=" 3.8s allocated 9 GiB"
t= 50s state=active slice_mem= 9.97GiB high_events=+17806 full_stall=+38.8s last=" 3.8s allocated 9 GiB"
t= 55s state=active slice_mem= 9.98GiB high_events=+18724 full_stall=+43.8s last=" 3.8s allocated 9 GiB"
t= 60s state=active slice_mem= 9.99GiB high_events=+19591 full_stall=+48.0s last=" 3.8s allocated 9 GiB"
t= 65s state=active slice_mem=10.00GiB high_events=+20407 full_stall=+53.1s last=" 3.8s allocated 9 GiB"
t= 70s state=active slice_mem=10.01GiB high_events=+21206 full_stall=+57.1s last=" 3.8s allocated 9 GiB"
t= 75s state=active slice_mem=10.01GiB high_events=+21971 full_stall=+62.2s last=" 3.8s allocated 9 GiB"
t= 80s state=active slice_mem=10.01GiB high_events=+22736 full_stall=+67.2s last=" 3.8s allocated 9 GiB"
t= 85s state=active slice_mem=10.02GiB high_events=+23484 full_stall=+71.5s last=" 3.8s allocated 9 GiB"
t= 90s state=active slice_mem=10.03GiB high_events=+24198 full_stall=+75.7s last=" 87.0s allocated 10 GiB"
still running after 90s: stopping it
scope Result=success oom_kill=0
output tail: 3.8s allocated 9 GiB 87.0s allocated 10 GiB
Terminated
======== after: b99dab9495 fix(mobile): fixed-time scheduled tasks keep their time on DST days (#43610) ( 2 files changed, 50 insertions(+))
server log: [17:26:58.665] INFO (#33): Agent scopes are on {
slice /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/app-t3code.slice/app-t3code-agents.slice
memory.high=max memory.max=12576595968 memory.swap.max=max
-- job after-fits: allocate 11 GiB, watch up to 90s
t= 5s state=active slice_mem= 7.12GiB high_events=+0 full_stall=+0.0s last=" 4.9s allocated 7 GiB"
t= 10s state=active slice_mem=11.03GiB high_events=+0 full_stall=+0.0s last=" 8.0s DONE 11 GiB"
t= 15s state=inactive slice_mem= 0.00GiB high_events=+0 full_stall=+0.0s last=" 8.0s DONE 11 GiB"
scope Result=success oom_kill=0
output tail: 8.0s allocated 11 GiB 8.0s DONE 11 GiB
-- job after-runaway: allocate 14 GiB, watch up to 90s
t= 5s state=active slice_mem= 8.58GiB high_events=+0 full_stall=+0.0s last=" 4.5s allocated 8 GiB"
18398 Killed systemd-run --user --scope --quiet --unit="$unit" --slice=$slice --property=OOMPolicy=stop python3 /home/user/alloc.py "$gib" > "$out/$unit.out" 2>&1
t= 10s state=failed slice_mem= 0.00GiB high_events=+0 full_stall=+0.0s last=" 7.1s allocated 11 GiB"
scope Result=oom-kill oom_kill=1
output tail: 6.0s allocated 10 GiB 7.1s allocated 11 GiB
Terminated
PROOF_DONE
Tests and checks, on the same VM:
vp test run apps/server/src/process/agentScope.test.ts: 19 passed. The new test, "treats swap a parent cgroup forbids as no swap", fails againstmain(1 failed, 18 passed).vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (2 files, 21 passed) all pass.
Not shown:
- The jobs are a Python allocator, not real provider turns. The stalls we hit in real use were a
tsc --noEmitheld at 4.2 GiB under a 3.97 GiBMemoryHighfor two hours on an 8 GiB Boat VM. - Only the Boat layout was run:
memory.swap.max0 onuser.slice. The ancestor walk that catches a 0 lower in the tree, at the slice itself, is covered by the unit test only.
Who did the work#
Reviewed with sol-loop: 1 round with gpt-6.2-sol on xhigh. Sol verdict: approved
Written by Claude Opus 5.5, in Claude Code inside T3 Code. Reviewed by GPT-6.2 Sol, in Codex.
- 1
- 2
Pushed777b3da
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
Sign in to join this conversation.
Evidence#
Real server and real Pi/Claude Haiku turns on Linux with 15.62 GiB RAM, 2 GiB host swap and ancestor
memory.swap.max=0. Fresh databases and the same synthetic project on both commits. Ask each agent to execute the same 11 GiB and 14 GiB anonymous-memory workloads; record app command state and kernel counters. Recordings contain sampled CLI/cgroup telemetry, not browser screenshots.memory.high, rising throttle events, no OOM kill.memory.high=max; allocation completes in 3.6 seconds, exit 0, provider turn completes.oom_kill=1within five seconds of command start; T3 reportsKilled: out of memory.The kernel hard limit remains
12576595968bytes on both sides. All four recordings were visually inspected.Reproduction instructions, turn driver, recorder, allocator workload, supporting transcripts and sanitized logs.
The workload is a synthetic allocator executed inside real provider turns, rather than a repository compiler.
Not shown: