fix(server): agents on hosts without swap are OOM-killed instead of throttled for hours #39287
main fromrefs/pull/39287/head·merged by juliusmarminge View on GitHubOn Linux hosts without swap, T3 Code still set a finite MemoryHigh on the shared agents slice. Once agents together went past it, the kernel throttled every agent indefinitely (hours of full stall) and never OOM-killed the runaway. The server now checks /proc/meminfo and sets MemoryHigh=infinity when there is no swap, keeping MemoryMax, so the runaway is OOM-killed in its own scope and other agents keep working. Swap presence is checked again at each launch, like RAM already is.
Fixes pingdotgg/t3code#39195
Reproduction on main#
Commit b5be2ff8da (origin/main). 1) Real app: T3CODE_DEV_SEED=0 vp run dev in a fresh worktree on a 15.6 GiB Linux x64 host with a systemd 255 user manager. The server logged Agent scopes are on { slice: 'app-t3code-agents.slice', high: 10325311488, max: 12575821824, oomPolicy: true }, i.e. MemoryHigh = RAM-6GiB and MemoryMax = RAM-4GiB set via systemctl --user set-property --runtime, with no swap check anywhere in agentScope.ts. 2) The host has 2 GiB of swap, and the real agents slice is shared with live agents on this machine, so I reproduced the kernel consequence in an isolated transient scope (own slice) with MemorySwapMax=0 and the same high<workload<max shape, scaled down. A Python process held and touched anonymous memory. Case A (today's policy): MemoryHigh=256M, MemoryMax=384M, 320 MiB workload. It never finished allocating: after 317 s memory.current was stuck around 284 MB, memory.events showed high=51,559, max=0, oom_kill=0, and memory.pressure was full avg10=78.8 avg60=84.0 total=240 s of full stall. It ended only when I stopped the scope. Case B: MemoryHigh=infinity, MemoryMax=384M, same 320 MiB workload: completed its 20 s run, 0 high events, 0 stall. Case C: MemoryHigh=infinity, MemoryMax=384M, runaway 500 MiB: OOM-killed immediately (Result=oom-kill), contained to its own scope.
Evidence#
Evidence for #39195.
Ran both unmodified real servers with fresh data on Linux x64/systemd 255.4. Isolated meminfo reported 512 MiB RAM and zero swap; MemorySwapMax=0 enforced no swapping without changing host swap. On both sides, ran an 8 MiB sibling, observed a 320 MiB workload for 60 seconds, then observed a 500 MiB runaway for 30 seconds. Videos render recorded kernel-counter samples, one frame per sample.
| Before | After |
|---|---|
| 9246c3235e | f99c63ecdb |
![]() | ![]() |
| Before recording | After recording |
| App applied high=256 MiB/max=384 MiB. Both allocations stalled at 240 MiB; 10,519 high events, 80.284 seconds full stall, zero OOM kills. | App applied high=infinity/max=384 MiB. 320 MiB completed; zero new high events; runaway scope Result=oom-kill; sibling continued. |
Driver scripts and instructions · Recorded policy and counter samples
Not shown:
- The physical host retained its swap. No-swap behavior was enforced with MemorySwapMax=0, and the real servers saw zero SwapTotal through isolated bind-mounted meminfo.
- The reproduction used scaled memory limits and approximately 90 seconds of workload observation per commit; multi-GiB production loads and the reported 19-hour duration were not exercised.
- Workloads were isolated Python tools under the app-configured agents slice, not real provider turns. The sibling continued on both sides, so complete starvation of every sibling agent was not demonstrated.
Tests#
vp test run src/process/agentScope.test.ts: 16 passed. With main'sagentScope.tsthe new swap-removed assertion fails (1 failed, 15 passed)vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (2 files) all pass
Not in this change#
- A per-cgroup
memory.swap.max=0limit on a host that has swap still gets the finite MemoryHigh; only host-wide SwapTotal is checked, as the maintainer described. - Host owners still cannot permanently override the slice limits, because the server re-applies them with --runtime at every start.
Who did the work#
- Written by Claude Opus 5.5, in Claude Code
- Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
- Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5
Run by the t3code factory in T3 Code.
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-39195
- File: .coderabbit.config.ts
- Commit: cb67443
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
af9163e7-2e51-4a29-844b-9e33edcbc306
Commits-
Reviewing files that changed from the base of the PR and between f99c63ecdbc97c395e90b0bcc9d4dae346c04e14 and cb67443dcd81917f6f3cf0d234d89bf8245a4c92.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- Trigger review
No actionable comments were generated in the recent review.
Walkthrough
-
The agent slice memory limits now account for host swap availability. The server reads swap state when it applies limits and re-applies them when total RAM or swap availability changes.
Changes: Swap-aware agent memory limits
Layer / File(s) Summary Calculate and apply swap-aware limits
apps/server/src/process/agentScope.ts,apps/server/src/process/agentScope.test.tsWhen swap is unavailable, MemoryHighis set toinfinity;MemoryMaxretains its RAM-based calculation. Limit updates now check both total RAM and swap availability. The tests provide synthetic/proc/meminfodata and check the zero-swap limits.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- pingdotgg/t3code#22724: Adds an agent memory-limit setting that controls the same
MemoryHighandMemoryMaxproperties. - pingdotgg/t3code#30581: Reapplies agent slice memory limits when total RAM changes.
- pingdotgg/t3code#24717: Adds a host-managed policy for automatic agent slice memory-limit overrides.
Suggested labels:
bugfixSuggested reviewers:
omaralex24,maria-rcks,macroscopeapp - pingdotgg/t3code#22724: Adds an agent memory-limit setting that controls the same
Merge Risk:
Minimal · previous reviewf99c6-
Agents on hosts without swap can now be OOM-killed in their own scope rather than throttling the whole slice. No actionable merge-blocking risk was found.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: on Linux hosts without swap, agents are OOM-killed instead of throttled, which matches the agentScope.ts change that sets MemoryHigh=infinity when no swap is present. … Linked Issues check [ #39195] The core objective is met. On a host with no swap, the server now sets MemoryHigh=infinity and keeps MemoryMax. In apps/server/src/process/agentScope.ts, agentSliceMemoryLimits(totalBytes, ha…Out of Scope Changes check All changes are in apps/server/src/process/agentScope.ts and agentScope.test.ts. The agentScope.ts changes add the hasSwap parameter, the /proc/meminfo swap read, the swap-aware change detection in ap… Description check The description states the problem (finite MemoryHigh on the shared agents slice on Linux hosts without swap causes indefinite throttling instead of OOM-kill), the change (checks /proc/meminfo at each… Full details: Title check
-
Explanation
The title names the main change: on Linux hosts without swap, agents are OOM-killed instead of throttled, which matches the agentScope.ts change that sets MemoryHigh=infinity when no swap is present. It follows the conventional commit form and is specific to the server package.
Full details: Linked Issues check
-
Explanation
[
#39195] The core objective is met. On a host with no swap, the server now sets MemoryHigh=infinity and keeps MemoryMax. In apps/server/src/process/agentScope.ts, agentSliceMemoryLimits(totalBytes, hasSwap) returns high "infinity" when hasSwap is false. The swap check reads /proc/meminfo and matches /^SwapTotal:\s*0 kB$/m. It runs on each launch, in the same place as the RAM re-check, and reapplies the limits when either value changes. The startup log uses the same limits. The test file adds swap-aware fake memory and asserts MemoryHigh=infinity with MemoryMax unchanged when swap is zero. The issue's second suggested trigger, a slice-level memory.swap.max of 0, is not handled. The PR description and objectives state this narrowing explicitly, so it is a scope decision, not an omission. The PR does not reapply limits in a way that blocks host-owner override, which the issue lists as background, not as a requirement. The real-app before/after evidence is still pending. It is not a coding requirement, so it does not affect this result.
Full details: Out of Scope Changes check
-
Explanation
All changes are in apps/server/src/process/agentScope.ts and agentScope.test.ts. The agentScope.ts changes add the hasSwap parameter, the /proc/meminfo swap read, the swap-aware change detection in applyMemoryLimits, the startup log, and an updated code comment. The test changes add fake swap and meminfo data and a zero-swap assertion. Each change directly supports the
#39195objective. No unrelated files or behavior appear in the reviewed diff.
Full details: Description check
-
Explanation
The description states the problem (finite MemoryHigh on the shared agents slice on Linux hosts without swap causes indefinite throttling instead of OOM-kill), the change (checks /proc/meminfo at each launch and sets MemoryHigh=infinity when no swap while keeping MemoryMax), and a linked issue (
#39195). It includes a detailed reproduction on main, before/after evidence with metrics and recordings, and a test summary with pass counts. It also lists what was not verified and notes the authoring agents. It does not follow the template headings exactly (Problem, Change, Scope, Verification), and the Scope section does not clearly say why the change is a bug fix rather than a feature. Some evidence links point to external file hosts. The description is substantially complete and maps well onto the template's content, so it passes.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: factory/issue-39195
- File: .coderabbit.config.ts
- Commit: f99c63e
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
9461d856-f711-44fc-82d8-549b4d59bbe3
Commits-
Reviewing files that changed from the base of the PR and between 1852121afac633f7b4dd85e4965f679e66de21dd and f99c63ecdbc97c395e90b0bcc9d4dae346c04e14.
Files selected for processing: 2-
apps/server/src/process/agentScope.test.tsapps/server/src/process/agentScope.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
-
juliusmarminge merged thisf9e45e4
juliusmarminge closed this
Sign in to join this conversation.


Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
short turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsshort turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsBaseline:
b5481ad· PR result:cb67443· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.