feat(lifecycle): reap a session's Docker containers on terminal state (the container leg of #2523)
Problem
AO keys several resources to a worker session and tears some of them down on terminal state — but Docker containers a worker starts are not one of them. A worker that needs a database (or any service) commonly runs docker run … in its task, reaches a terminal lifecycle state, and the container survives indefinitely. ao session kill / cleanup removes the row and (tries to) reclaim the worktree, but never touches containers the worker launched.
This is the container leg of the same "tear down what the worker owns on session end" story that #2523 covers for orphan processes and #2608 / #2646 cover for worktrees. Those exist; the container case has no issue and no mechanism.
Why it bites (real incident, one 16GB macOS machine, ao 0.9.x, tmux runtime)
Across 2026-07-12/13, workers on a multi-project factory each improvised their own docker run postgres (per-branch <id>-pg, <id>-pgmq, ad-hoc postgres:16 / 16-alpine / pgmq images). Nothing tied a container's lifecycle to the session ending, so they accreted: 43 postgres containers running concurrently ballooned the Docker VM until the host hit "out of application memory" (swap ~20–28GB) and every other worker slowed to a crawl. A manual sweep removed 59 stale containers + volumes (~59GB). A typical worker DB is ~165MB of data — the cost is the processes, each with its own shared buffers/page cache, not the data.
We now compensate downstream with (a) a machine-level launchd reaper that GCs worker containers by name/ao.branch label when the keyed PR closes, and (b) a shared-substrate "one container, one DB per branch" tool so 43 postgres processes become 1. Both are scar tissue for a lifecycle AO is the right owner of — we'd delete them the moment AO reaps a session's containers on terminal state.
Proposal
Mirror #2523's orphan-process reaper for containers:
- Auto-label every container a worker starts with the session id (
ao.session=<id>/ao.branch=<branch>) — e.g. by injecting--labelwhen the worker shells out, or documenting the label convention so teardown can key on it. - Reap on terminal state /
ao session kill:docker rm -fthe containers carrying the session's label, with an explicit opt-out for deliberately-shared substrate containers (a shared postgres, a registry) so a spared resource is a config choice, not an accident. Bias toward sparing on any ambiguity — a wrongly-reaped container can cost a live worker its database. - Nice-to-have: surface per-session container count / footprint alongside the RSS surfacing proposed in #2523, so a leak is visible before the Docker VM pages out.
Sibling to #2523 (processes) and #2608 / #2646 (worktrees) — same trigger, remaining resource class. Happy to test on our fleet.
🤖 Filed with Claude Code on behalf of @Tonedeath
Thanks for contributing to Agent Orchestrator.
This issue is being picked up by the current external contributor on-call pair:
- @neversettle17-101
- @somewherelostt
If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @neversettle17-101 and @somewherelostt here. You can also join the AO Discord if you want faster context, want to ask questions live, or just want to follow what the community is building.
You are also welcome to join the AO Discord community.
We do daily Discord calls at 10 PM IST, except Saturday.
Join the session here: https://discord.gg/H6ZDcUXmq
Come by if you want to see what is being built, ask questions, or just hang around with the community.
starting this one