Skip to content

fix(docker): --init for zombie reaping + sleep infinity for idle-based lifetime - #6910

Closed
malaiwah wants to merge 1 commit into
NousResearch:mainfrom
malaiwah:upstream-fix/docker-init-zombie-reaping
Closed

fix(docker): --init for zombie reaping + sleep infinity for idle-based lifetime#6910
malaiwah wants to merge 1 commit into
NousResearch:mainfrom
malaiwah:upstream-fix/docker-init-zombie-reaping

Conversation

@malaiwah

Copy link
Copy Markdown
Contributor

Fixes #6908.

Problem

Sandbox containers spawned by the Docker backend have two issues:

  1. Zombie accumulation. PID 1 is sleep 2h, which doesn't call wait(). Every background process (terminal(background=true)) that exits becomes a zombie. The process tool reports them as "running" because zombie PIDs still exist in the process table.

  2. Fixed 2-hour lifetime. Arbitrary and sometimes too short for long agent sessions. The idle reaper (_cleanup_inactive_envs, gated by terminal.lifetime_seconds) already handles cleanup based on last activity — the container doesn't need its own death timer.

Fix

Two one-line changes:

Line Before After
docker run flags (none) --init — tini (Docker) / catatonit (Podman) as PID 1, reaps zombies
Entrypoint sleep 2h sleep infinity — no fixed lifetime, idle reaper handles it

Both Docker and Podman support --init natively. sleep infinity is POSIX (GNU coreutils). The idle reaper's terminal.lifetime_seconds (default 300s) controls when inactive containers are cleaned up.

Verification

Tested on Podman 5.x (Alpine LXC):

  • podman run --rm --init <image> sh -c "sleep 10 & wait" — no zombies
  • Background processes reap correctly; process(action="list") reflects actual state
  • Container lives indefinitely until idle reaper fires or task ends

…d lifetime

Two issues with sandbox container spawning:

1. PID 1 was `sleep 2h` which doesn't call wait() — every background
   process that exited became a zombie (<defunct>), and the process
   tool reported them as "running" because zombie PIDs still exist in
   the process table. Fix: add --init to docker run, which uses
   tini (Docker) or catatonit (Podman) as PID 1 to reap children
   automatically. Both runtimes support --init natively.

2. The fixed 2-hour lifetime was arbitrary and sometimes too short
   for long agent sessions. Fix: replace 'sleep 2h' with
   'sleep infinity'. The idle reaper (_cleanup_inactive_envs, gated
   by terminal.lifetime_seconds, default 300s) already handles
   cleanup based on last activity timestamp — there's no need for
   the container itself to have a fixed death timer.

Fixes NousResearch#6908.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7407. Cherry-picked with authorship preserved. Clean fix — thanks!

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.

Background processes accumulate zombies; process tool reports dead processes as running

2 participants