Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): agents on hosts without swap are OOM-killed instead of throttled for hours #39287

Mergedjuliusmarmingemerged 0 commits intomain fromrefs/pull/39287/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

On 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.

BeforeAfter
9246c3235ef99c63ecdb
Before: finite MemoryHigh stalls allocations without an OOM killAfter: MemoryHigh infinity permits normal completion and OOM-kills the runaway
Before recordingAfter 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's agentScope.ts the 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=0 limit 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

    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: b5481ad · PR result: cb67443 · Source CI: success

      Scenario 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.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration

      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_status to false in 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.ts
      When swap is unavailable, MemoryHigh is set to infinity; MemoryMax retains its RAM-based calculation. Limit updates now check both total RAM and swap availability. The tests provide synthetic /proc/meminfo data 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

      Suggested labels: bugfix

      Suggested reviewers: omaralex24, maria-rcks, macroscopeapp

      Merge Risk: Minimal · previous review f99c6

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassed[#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 checkPassedAll 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 checkPassedThe 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 #39195 objective. 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

      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.ts
      • apps/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.

    4. juliusmarminge merged thisf9e45e4

    5. juliusmarminge closed this

Sign in to join this conversation.