Repository navigation
fix(cmd/flynn): cap a command's memory at half of RAM by default - #662
Merged
Merged
Conversation
On Windows a command the agent ran had no memory cap unless --max-memory was passed. The job object's process cap (4096) does not bound memory: a go shim on PATH that resolved back to itself started a few hundred heavy processes under a goal and committed all 95 GB of the machine, crashing WSL, long before reaching the process limit. With --max-memory unset, the agent's shell policy now caps each command at half the machine's physical memory, for flynn goal, the interactive session, flynn serve and the MCP server. An explicit --max-memory still wins, and where the RAM cannot be read the command runs uncapped as before. The default is set on the shell policy and not inside sandbox.Local, because the sandbox also runs local model servers, which can legitimately need more than half the machine. internal/hardware exports RAMBytes so the policy reads RAM without the GPU probes. A source test requires every governed.ShellPolicy built in cmd/flynn to set Limits, so a new entry point cannot start an uncapped shell. Signed-off-by: Ion Alpha <contact@ionalpha.io>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What
With
--max-memoryunset, every command the agent runs is now capped at half the machine's physical memory. This coversflynn goal, the interactive session,flynn serveand the MCP server. An explicit--max-memorystill wins, and where the RAM cannot be read the command runs uncapped as before.Why
On Windows a confined command had no memory cap by default. The job object caps processes at 4096, but that does not bound memory. While testing a release candidate, a goal ran
go runon a machine wheregoonPATHis a build-lease shim. Inside the sandbox the shim resolved back to itself and kept starting copies. A few hundred heavy processes committed 94.9 of 95.4 GB, Windows ran low on virtual memory and the WSL service crashed. The process cap was never reached.How to verify
go test ./cmd/flynn/ -run 'TestCommandLimits|TestEveryShellPolicySetsLimits|TestShellFlagsBuildThePolicy'TestCommandLimitsDefaultsToHalfOfRAMpins the arithmetic,TestCommandLimitsReadsThisMachinechecks the real RAM probe feeds it on each CI OS, andTestEveryShellPolicySetsLimitsfails if agoverned.ShellPolicybuilt incmd/flynnleavesLimitsunset.TestApplyJobLimitsResourceCapsinsandbox.Notes for reviewers
sandbox.Local. The sandbox also runs local model servers, which can legitimately need more than half the machine, and embedders calling the sandbox directly keep its documented zero-means-uncapped behaviour. No exported signature changes beyond the newhardware.RAMBytesin an internal package.ResourceLimits(documented; a per-run cgroup needs delegation an unprivileged agent may not have), so today the default takes effect on Windows.