Skip to content

Give each Podman session its own memory limit - #96

Merged
guimou merged 1 commit into
mainfrom
fix/per-session-memory-cap
Nov 26, 2026
Merged

guimou merged 1 commit into
mainfrom
fix/per-session-memory-cap

Conversation

@guimou

@guimou guimou commented Nov 26, 2026

Copy link
Copy Markdown
Owner

What

Every Podman session now gets its own hard memory limit (podman run --memory), inside the shared codebox.slice budget.

  • New variable CODEBOX_MEMORY_SESSION_MAX. Default: half of CODEBOX_MEMORY_MAX (half of CODEBOX_MEMORY_HIGH when that one is set explicitly), so it sits below MemoryHigh. infinity removes it.
  • A percentage is resolved against /proc/meminfo at launch, because podman run --memory takes none.
  • Applied only where the shared budget applies (same requirements); --no-memory-limit and CODEBOX_MEMORY_MAX=off skip both. The Apptainer backend is unchanged.
  • The launch summary shows it: Memory budget: codebox.slice (max 80%, high 72%, swap 2G; shared by all sessions; 40% per session).

This changes the default behavior: with the defaults, a session that could use the whole budget before is now limited to half of it (40% of RAM).

Why

On 2026-11-26 a test run left behind in the background of one ompbox session (vitest run | head -40) grew to 45G. The slice reached MemoryHigh (46080M), the kernel throttled it, and systemd-oomd (Fedora default: kill at 80% memory pressure for 20s on user slices) killed whole containers: first an idle session of another project (275M in use), 15 seconds later the runaway one.

The shared budget protects the desktop, but not the sessions from each other. With a per-session limit below MemoryHigh, the runaway process reaches its own limit first and the kernel OOM-kills it inside its container.

Verification

  • tests/render-test.sh: all scenarios pass. Golden files re-recorded: every Podman scenario gains a --memory= line. New scenarios: memory-session (explicit value), memory-session-off (infinity), !memory-invalid-session. The test fixes RAM at 64 GiB through CODEBOX_MEMINFO so the goldens do not depend on the machine.
  • shellcheck on the documented file list: clean.
  • Real Podman 5, rootless, in codebox.slice with --memory=512M: memory.max is 536870912, a 3G allocation is killed (oom_kill 1), the container's shell survives.
  • The incident replayed in a container with --memory=4G (frontend tests of the affected project piped into head -40): vitest workers are OOM-killed one after the other (8 kills in 45s), memory stays at the limit, the container survives, and systemd-oomd kills nothing. Observed for 45 seconds only.

Limits

  • The kernel kills the biggest process in the container, which can be the agent itself.
  • Two sessions running away together can still reach the shared budget.
  • A value set by hand above MemoryHigh is not refused; the docs say to keep it below.
  • Zero or a few bytes are passed to Podman as they are (podman create accepts them); not validated here.

Docs updated: docs/usage.md (new section "One session cannot take the others down"), docs/architecture.md, AGENTS.md, and the launcher help.

🤖 Generated with Claude Code

All sessions share one budget in codebox.slice, with nothing per session.
A runaway process in one session (a vitest run left behind by `| head`)
grew to 45G, the slice reached MemoryHigh, and systemd-oomd answered the
sustained pressure by killing whole containers: an idle session of
another project first, then the runaway one.

Each session now gets `podman run --memory`, from the new
CODEBOX_MEMORY_SESSION_MAX (default half of CODEBOX_MEMORY_MAX, so below
MemoryHigh; `infinity` for none). The runaway reaches its own limit first
and the kernel OOM-kills it inside its container. A percentage is
resolved against /proc/meminfo, as podman takes none.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@guimou
guimou merged commit 6a0805c into main Nov 26, 2026
1 check passed
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.

1 participant