Repository navigation
fix(agent-server): spare operator docker-exec sessions from the orphan sweeper (#1153) - #1154
Merged
Merged
Conversation
…n sweeper (#1153) The periodic cgroup orphan sweeper (#817) SIGKILLed operator `docker exec` sessions within 0–30s — the same class of actor (an operator/platform process maintaining the agent) that the allowlist already deliberately protects for SSH. A long `docker exec agent-X sh -c '...sleep...'` died with exit 137; weeks of FAISS index-build failures were misdiagnosed as OOM/capacity. Root cause: a `docker exec` entry process matches none of the allowlist sources (no execution id, no env tag, no shared pgid, not sshd) and was reaped as an orphan — yet it is exactly the SSH-session case. Fix: - orphan_allowlist: new `_docker_exec_session_pids()` — inside the container PID namespace a `docker exec` entry has **PPID 0** (real parent is outside the namespace); genuinely-leaked orphans reparent to **PID 1**, never 0, so PPID 0 is an unspoofable "operator exec session" signal. Allowlist every PPID-0 process (excluding PID 1, already hard-protected) + its descendant tree. Wired into `resolve_allowlist`. When the session exits, leftover children reparent to PID 1 and fall out → reaped next sweep (#817 guarantee preserved). - orphan_sweep: each real kill now logs at **WARNING** with `pid` + a length-capped `cmd=` (was INFO). One such line turns the weeks-long "which process keeps dying?" misdiagnosis into a 5-minute fix. dry_run stays INFO. cmdline capped at 200 chars. - docs: TRINITY_COMPATIBLE_AGENT_GUIDE gains a "Long-Running & Background Processes (the orphan sweeper)" section — the `persistent-processes.allow` escape hatch and "run maintenance as a platform execution" guidance. Tests: tests/unit/test_1153_docker_exec_allowlist.py (5) — PPID-0 entry + descendants protected, PID 1 (and its children) excluded, reparented orphan not protected, resolve_allowlist end-to-end, post-exit child reaped. #912 suite still green (13 passed together). Live-verified on a fresh trinity-agent-base:0.6.0 agent: a 30s `docker exec` loop survived a real mid-flight sweep and exited 0; agent-server + sshd spared under the production sweep_pid; a planted PPID-1 orphan was reaped. Related to #1153 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
vybe
approved these changes
Jun 11, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Validated via /validate-pr — focused P1 reliability fix, unspoofable PPID-0 signal, full unit + live verification, CI green, security scan clean. Approving.
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The periodic cgroup orphan sweeper (#817) SIGKILLed operator
docker execsessions within 0–30s — the same class of actor the allowlist already protects for SSH.docker exec agent-X sh -c '...sleep 60'died with exit 137; weeks of FAISS index-build failures were misdiagnosed as OOM/capacity (a host was upsized for nothing). It also exposed the platform's own exec paths (pre-check hooks, git recovery, session-JSONL reaping, agent terminal — alldocker exec).Root cause
A
docker execentry process matches none of the allowlist sources (no execution id, noTRINITY_EXECUTION_ID, no shared pgid, not sshd) → reaped as an orphan. But it's exactly the operator-debugging case_ssh_session_pids()exists to protect.Fix
orphan_allowlist._docker_exec_session_pids()— inside the container PID namespace adocker execentry has PPID 0 (real parent is the containerd shim, outside the namespace); genuinely-leaked orphans reparent to PID 1, never 0. PPID 0 is an unspoofable "operator exec session" signal. Allowlist every PPID-0 process (excluding PID 1, already hard-protected) + its descendant tree. Wired intoresolve_allowlist. When the session exits, leftover children reparent to PID 1 → fall out of the set → reaped next sweep (the bug: Runaway subprocess after task failure makes agent-server unresponsive, triggering persistent CB cascade #817 guarantee is preserved).orphan_sweep— each real kill logs at WARNING withpid+ a length-capped (200)cmd=(was INFO, count-only summary in the loop). dry_run stays INFO. One such line turns a weeks-long "which process keeps dying?" into a 5-minute fix.TRINITY_COMPATIBLE_AGENT_GUIDE.mdgains a "Long-Running & Background Processes (the orphan sweeper)" section: the~/.trinity/persistent-processes.allowescape hatch and "run maintenance as a platform execution" guidance.Verification
Unit —
tests/unit/test_1153_docker_exec_allowlist.py(5): PPID-0 entry + descendants protected; PID 1 (and its children) excluded; reparented orphan not protected;resolve_allowlistend-to-end; post-exit child reaped. #912 suite still green (13 passed together).Live (fresh
trinity-agent-base:0.6.0agent, real cgroup sweep mid-flight,sweep_pid= agent-server's pid as in production):docker execloop (PPID 0)sh -c sleep 300(PPID 1, reparented)sudo .../sshdpython3 /app/agent-server.pyAC
docker execsurvives sweep cycles, exits 0Note: agent-runtime change → base image rebuilt (
trinity-agent-base:0.6.0/latest); takes effect on newly created/restarted agent containers.Related to #1153
🤖 Generated with Claude Code