Skip to content

fork: agents are not throttled when a parent cgroup caps swap - #83

Merged
ribeirogab merged 1 commit into
customfrom
fork/agent-slice-swap-cap
Nov 28, 2026
Merged

ribeirogab merged 1 commit into
customfrom
fork/agent-slice-swap-cap

Conversation

@ribeirogab

Copy link
Copy Markdown
Owner

Problem

The agents slice gets MemoryHigh whenever /proc/meminfo reports swap. A host can have swap and still cap it for the cgroups above the agents, for example MemorySwapMax=2G on user.slice. Once that cap fills, the throttle has nowhere to push pages: every agent stalls between MemoryHigh and MemoryMax, and the kernel never kills the runaway. This is the case the upstream comment already describes for hosts without swap.

Seen on a 16 GB host with 8 GB of swap and user.slice capped at 2 GB of swap: one agent's pre-commit hook ran oxlint (5 GB) and two knip processes (1 GB each) at once. The slice sat at its MemoryHigh with 11.8 million high events, memory pressure full stayed above 50%, and every agent on the machine froze for minutes.

Change

  • apps/server/src/fork/agentSwapCap.ts: when the host has swap, read memory.swap.max of every cgroup from the top down to app-t3code-agents.slice. A byte limit on any of them counts as no swap, so the slice gets MemoryHigh=infinity and the runaway hits MemoryMax and the OOM kill.
  • agentScope.ts wraps its existing /proc/meminfo check with it. The slice's control group comes from systemctl --user show, once per server. With no control group, the host check decides, as before.
  • New toggle Settings → Fork → Agents → Agent swap cap, on by default. Off, the server behaves like upstream.

Verification

  • apps/server/src/fork/agentSwapCap.test.ts: lineage, the cap check, a host without swap, a missing control group, one systemctl show per server, and the toggle off.
  • src/process/agentScope.test.ts and the new test pass (27 tests). Typecheck of apps/server, apps/web, and packages/contracts passes.
  • On the host above, systemctl --user show app-t3code-agents.slice --property=ControlGroup gives the six-level lineage, and /user.slice has memory.swap.max 2147483648, so the change picks MemoryHigh=infinity. Setting it by hand with systemctl --user set-property --runtime ended the stall at once.

@ribeirogab
ribeirogab merged commit 52084c7 into custom Nov 28, 2026
1 check passed
@ribeirogab
ribeirogab deleted the fork/agent-slice-swap-cap branch November 28, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant