Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

fix: resolve container OOM hangs from tsgo and --memory flag - #55

Merged
Peyton-Spencer merged 2 commits into
mainfrom
fix/container-memory-tsgo
Feb 15, 2026
Merged

fix: resolve container OOM hangs from tsgo and --memory flag#55
Peyton-Spencer merged 2 commits into
mainfrom
fix/container-memory-tsgo

Conversation

@Peyton-Spencer

@Peyton-Spencer Peyton-Spencer commented Feb 15, 2026

Copy link
Copy Markdown

Summary

  • Bump container memory to 4 GB — Apple Container's --memory flag treats bare numbers as bytes (not MB), so --memory 1024 meant 1024 bytes, silently hanging the VM. Use --memory 4G with proper suffix. Ref: apple/container#1202, apple/container#1208
  • Set GOMEMLIMIT=3GiB in entrypoint — tsgo (TypeScript native compiler) has no default memory ceiling. Go doesn't auto-detect container/cgroup memory limits, so tsgo allocates unbounded memory until the VM hangs. Ref: microsoft/typescript-go#2125

Test plan

  • Verify containers start with 4 GB memory shown in container list
  • Run bun typecheck (tsgo) on a medium-sized TypeScript project inside a container — should complete without OOM
  • Verify GOMEMLIMIT is set: container run -i --rm --entrypoint /bin/sh nanoclaw-agent:latest -c 'echo $GOMEMLIMIT'

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Added container memory limits (default 4G) to better control resource usage and improve stability.
    • Set Go runtime heap cap for background processes to ~75% of system memory to reduce out-of-memory risk and smooth performance.

Two issues caused containers to hang indefinitely:

1. Apple Container's `--memory` flag treats bare numbers as bytes, not
   megabytes. `--memory 1024` = 1024 bytes, causing the VM to never boot.
   Fix: use proper suffix (`--memory 4G`).
   Ref: apple/container#1202
   Ref: apple/container#1208

2. tsgo (TypeScript native compiler) has no default memory ceiling — Go
   doesn't auto-detect container memory limits, so tsgo allocates unbounded
   memory until the VM hangs under memory pressure.
   Fix: set GOMEMLIMIT=3GiB in entrypoint.
   Ref: microsoft/typescript-go#2125

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a runtime memory limit configuration exported from the app config, passes that limit to the container runtime, and sets a Go heap cap inside the container based on total system memory.

Changes

Cohort / File(s) Summary
Container entrypoint
container/entrypoint.sh
Computes total memory from /proc/meminfo and exports GOMEMLIMIT as ~75% of total (in MiB) to cap Go heap; placed after JS heap cap logic.
Backend runtime invocation
src/backends/local-backend.ts
Adds --memory argument to container run invocation using CONTAINER_MEMORY; imports the new config constant.
Configuration
src/config.ts
Adds export const CONTAINER_MEMORY: string sourced from process.env.CONTAINER_MEMORY with default '4G'.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I sniff the bytes, I count the RAM,
I tuck the Go heap in a cozy little dam.
Four gigs at the door, three gigs for the mind,
Containers hum softly, all neat and kind. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main changes: resolving OOM hangs by adding memory limits (4GB via --memory flag) and setting GOMEMLIMIT for tsgo.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/container-memory-tsgo

Comment @coderabbitai help to get the list of available commands and usage tips.

Default 4G, configurable in .env. GOMEMLIMIT auto-derives from
actual VM memory (75%) so it scales with any CONTAINER_MEMORY value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Peyton-Spencer
Peyton-Spencer merged commit 1f74883 into main Feb 15, 2026
1 of 3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant