Skip to content

Inject GOMEMLIMIT into guest VM to prevent Go tool OOM kills#124

Merged
jhrozek merged 1 commit intomainfrom
jaosorior/inject-gomemlimit
Apr 17, 2026
Merged

Inject GOMEMLIMIT into guest VM to prevent Go tool OOM kills#124
jhrozek merged 1 commit intomainfrom
jaosorior/inject-gomemlimit

Conversation

@JAORMX
Copy link
Copy Markdown
Contributor

@JAORMX JAORMX commented Apr 16, 2026

Summary

  • Go tools spawned by agents (e.g. 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 fires
  • Adds GoMemLimitPercent to the agent definition (same pattern as the existing NodeHeapPercent / NODE_OPTIONS cap) and injects GOMEMLIMIT into /etc/sandbox-env
  • Sets 70% for all built-in agents — with a 10 GB VM this yields GOMEMLIMIT=7168MiB, leaving headroom for Node.js and system overhead

Context

Observed golangci-lint (3.6 GB RSS) getting OOM-killed inside a 10 GB VM, which left the SSH session frozen. The kernel's oom_score_adj fired because no Go GC soft limit was in place.

Test plan

  • task fmt — clean
  • task lint — 0 issues
  • task test — all passing

🤖 Generated with Claude Code

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>
@JAORMX JAORMX requested a review from jhrozek April 16, 2026 12:36
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jhrozek jhrozek merged commit 7217a0a into main Apr 17, 2026
8 checks passed
@jhrozek jhrozek deleted the jaosorior/inject-gomemlimit branch April 17, 2026 10:00
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.

2 participants