Repository navigation
fork: agents are not throttled when a parent cgroup caps swap - #83
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The agents slice gets
MemoryHighwhenever/proc/meminforeports swap. A host can have swap and still cap it for the cgroups above the agents, for exampleMemorySwapMax=2Gonuser.slice. Once that cap fills, the throttle has nowhere to push pages: every agent stalls betweenMemoryHighandMemoryMax, 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.slicecapped at 2 GB of swap: one agent's pre-commit hook ranoxlint(5 GB) and twoknipprocesses (1 GB each) at once. The slice sat at itsMemoryHighwith 11.8 millionhighevents, memory pressurefullstayed above 50%, and every agent on the machine froze for minutes.Change
apps/server/src/fork/agentSwapCap.ts: when the host has swap, readmemory.swap.maxof every cgroup from the top down toapp-t3code-agents.slice. A byte limit on any of them counts as no swap, so the slice getsMemoryHigh=infinityand the runaway hitsMemoryMaxand the OOM kill.agentScope.tswraps its existing/proc/meminfocheck with it. The slice's control group comes fromsystemctl --user show, once per server. With no control group, the host check decides, as before.Verification
apps/server/src/fork/agentSwapCap.test.ts: lineage, the cap check, a host without swap, a missing control group, onesystemctl showper server, and the toggle off.src/process/agentScope.test.tsand the new test pass (27 tests). Typecheck ofapps/server,apps/web, andpackages/contractspasses.systemctl --user show app-t3code-agents.slice --property=ControlGroupgives the six-level lineage, and/user.slicehasmemory.swap.max2147483648, so the change picksMemoryHigh=infinity. Setting it by hand withsystemctl --user set-property --runtimeended the stall at once.