Inject GOMEMLIMIT into guest VM to prevent Go tool OOM kills#124
Merged
Inject GOMEMLIMIT into guest VM to prevent Go tool OOM kills#124
Conversation
Go tools spawned by agents (e.g. golangci-lint) do not auto-detect VM memory limits because the guest has no cgroup boundary. Without GOMEMLIMIT the GC grows the heap unbounded until the OOM killer fires, which freezes the terminal session. Add GoMemLimitPercent to the agent definition (mirroring the existing NodeHeapPercent pattern) and set it to 70% for all built-in agents. With a 10 GB VM this yields GOMEMLIMIT=7168MiB, giving the Go GC a soft ceiling while leaving headroom for Node.js and system overhead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jhrozek
approved these changes
Apr 17, 2026
Contributor
jhrozek
left a comment
There was a problem hiding this comment.
it would be cool to be able to set env vars like this through sub-agents. But great, this is probably why I've been seeing occasionaly OOMs as well.
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.
Summary
golangci-lint) don't auto-detect VM memory limits — the guest runs its own kernel with no cgroup boundary, so the Go GC has no soft ceiling and grows unbounded until the OOM killer firesGoMemLimitPercentto the agent definition (same pattern as the existingNodeHeapPercent/NODE_OPTIONScap) and injectsGOMEMLIMITinto/etc/sandbox-envGOMEMLIMIT=7168MiB, leaving headroom for Node.js and system overheadContext
Observed
golangci-lint(3.6 GB RSS) getting OOM-killed inside a 10 GB VM, which left the SSH session frozen. The kernel'soom_score_adjfired because no Go GC soft limit was in place.Test plan
task fmt— cleantask lint— 0 issuestask test— all passing🤖 Generated with Claude Code