You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Subagent Docker containers not auto-removed after completion, causing maxConcurrent slot exhaustion #46254
Subagent Docker containers are not automatically cleaned up after task completion, causing them to accumulate until maxConcurrent limit is reached and blocking new subagent spawns.
Observed Behavior
Subagent containers continue running after the task is complete
docker ps shows multiple openclaw-sbx-agent-main-subagent-* containers with status Up X hours
Once maxConcurrent (default 8) slots are filled, new sessions_spawn calls hang or fail
Manual docker kill + rm is required to restore functionality
Expected Behavior
Subagent containers should be automatically removed after the task completes (regardless of success/failure).
Environment
OpenClaw version: 2026.3.13
OS: Linux 6.12.73+deb13-amd64
Config: subagents.maxConcurrent: 8 (default)
Evidence
$ docker ps --filter name=subagent --format table {{.Names}}\t{{.Status}}
NAMES STATUS
openclaw-sbx-agent-main-subagent-d3c961bf-898-a7ed2519 Up 3 hours
openclaw-sbx-agent-main-subagent-f3abcd8c-036-592be4bb Up 3 hours
openclaw-sbx-agent-main-subagent-4b22e7a5-985-1cd1e3bd Up 4 hours
openclaw-sbx-agent-main-subagent-e7c48412-d91-d0d8516c Up 5 hours
openclaw-sbx-agent-main-subagent-97497c4e-422-f78092f0 Up 5 hours
openclaw-sbx-agent-main-subagent-7a40e27d-a39-ad2d9c95 Up 6 hours
Likely missing --rm flag in Docker spawn logic or container lifecycle management issue.
Additional Context
This issue causes subagent spawns to hang indefinitely when the concurrent limit is reached, severely impacting workflows that rely on background task delegation.
Closing this as not reproducible on current main after Codex review.
Current main does not support the reported causal path. Docker sandbox containers are intentionally persistent per sandbox scope and pruned on idle/age, while subagent concurrency limits are enforced by the in-process subagent lane and active-run registry rather than by counting running Docker containers.
What I checked:
Sandbox containers are persistent by scope: Docs define sandbox scope as controlling how many containers exist (agent, session, shared), and ensureSandboxContainer() reuses an existing named container instead of removing it after each run. (src/agents/sandbox/docker.ts:524, c13836804058)
Persistence is documented, not accidental: Sandbox CLI docs explicitly say existing runtimes keep running and are normally pruned only after inactivity; defaults shown are idleHours: 24 and maxAgeDays: 7. Public docs: docs/cli/sandbox.md. (docs/cli/sandbox.md:151, c13836804058)
Prune logic removes old runtimes by idle/age:maybePruneSandboxes() checks idleHours/maxAgeDays and removes registered runtimes only when those thresholds are exceeded. (src/agents/sandbox/prune.ts:24, c13836804058)
Subagent maxConcurrent is a queue lane limit, not a container-slot limit: Docs define agents.defaults.subagents.maxConcurrent as the dedicated in-process subagent queue lane concurrency, and the queue implementation stores only active task ids per lane. (src/process/command-queue.ts:235, c13836804058)
Active-child gating ignores completed children:sessions_spawn blocks only when countActiveRunsForSession() reaches maxChildrenPerAgent; that counter excludes ended children once descendants are done, with direct regression coverage. (src/agents/subagent-registry-queries.ts:157, c13836804058)
Activity
2670044605 commentedon Mar 14, 2026
Update: After cleanup, testing if the bug reproduces. Will update with results.
2670044605 commentedon Mar 14, 2026
Proposed Fix
After investigation, the issue appears to be in the Docker container lifecycle management.
Root Cause
The Docker spawn logic is likely missing the
--rmflag or container cleanup is not triggered properly when subagent tasks complete/fail.Suggested Fix
Option 1: Add
--rmflag to Docker run command:Option 2: Implement explicit cleanup in orchestration layer:
User Workaround
Add to crontab for automatic cleanup:
steipete commentedon Apr 25, 2026
Closing this as not reproducible on current
mainafter Codex review.Current main does not support the reported causal path. Docker sandbox containers are intentionally persistent per sandbox scope and pruned on idle/age, while subagent concurrency limits are enforced by the in-process subagent lane and active-run registry rather than by counting running Docker containers.
What I checked:
agent,session,shared), andensureSandboxContainer()reuses an existing named container instead of removing it after each run. (src/agents/sandbox/docker.ts:524, c13836804058)idleHours: 24andmaxAgeDays: 7. Public docs:docs/cli/sandbox.md. (docs/cli/sandbox.md:151, c13836804058)maybePruneSandboxes()checksidleHours/maxAgeDaysand removes registered runtimes only when those thresholds are exceeded. (src/agents/sandbox/prune.ts:24, c13836804058)agents.defaults.subagents.maxConcurrentas the dedicated in-processsubagentqueue lane concurrency, and the queue implementation stores only active task ids per lane. (src/process/command-queue.ts:235, c13836804058)sessions_spawnblocks only whencountActiveRunsForSession()reachesmaxChildrenPerAgent; that counter excludes ended children once descendants are done, with direct regression coverage. (src/agents/subagent-registry-queries.ts:157, c13836804058)Review notes: reviewed against c13836804058.