Repository navigation
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 3:05 AM ET / 07:05 UTC. Summary PR surface: Source +216, Tests +70, Other +1. Total +287 across 7 files. Reproducibility: yes. for the PR defect: libuv source shows SIGCHLD handling waits tracked child PIDs, while this PR relies on it to reap untracked direct zombies. The full production leak still needs branch-tied Linux/Docker before-and-after proof. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Fix the process owner/wait boundary with a true waitpid, subreaper, or bottom-up process-tree design, then prove direct-child zombie counts stay bounded on a packaged Linux/Docker gateway. Do we have a high-confidence way to reproduce the issue? Yes for the PR defect: libuv source shows SIGCHLD handling waits tracked child PIDs, while this PR relies on it to reap untracked direct zombies. The full production leak still needs branch-tied Linux/Docker before-and-after proof. Is this the best way to solve the issue? No. This is a plausible mitigation, but the maintainable fix belongs at the process owner/wait boundary or a real waitpid/subreaper design, not a SIGCHLD nudge that libuv cannot use for untracked children. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 245b91b83de0. Label changesLabel justifications:
Evidence reviewedPR surface: Source +216, Tests +70, Other +1. Total +287 across 7 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (4 earlier review cycles)
|
…-running gateway When process-tree kills race with grandchild exits, zombie grandchildren are reparented to PID 1 but no new SIGCHLD is sent, causing permanent zombie accumulation (800+ observed over months in Docker, openclaw#97616). Add a zombie reaper module that sends SIGCHLD to self to trigger libuv's waitpid(-1, WNOHANG) sweep — called after every process-tree kill and periodically every 30s from the gateway server. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Demonstrates reapZombies() safety, idempotency, and the full start/stop lifecycle on the current platform. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
libuv calls waitpid(process->pid, ...) for tracked children only, not waitpid(-1, WNOHANG). Sending SIGCHLD to ourselves does not reap reparented zombie grandchildren because libuv has no handle for them. Send SIGCHLD to PID 1 (tini/init) instead — tini's SIGCHLD handler calls waitpid(-1, WNOHANG) and will reap any zombies that were reparented during process-tree termination. Fall back to self-SIGCHLD when PID 1 is not signalable. Document the mechanism as a mitigation, not a guaranteed fix. A complete fix requires subreaper registration + native waitpid binding, or a bottom-up process-tree kill that avoids the race condition entirely. ClawSweeper: correct signal target (openclaw#97731) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The linked issue shows defunct children with PPID = openclaw. PID 1 cannot reap children still parented by the OpenClaw process — only the owning parent can. Swap the signal order so self-SIGCHLD is primary and PID 1 is the fallback for reparented grandchildren. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
52504d7 to
2aba5b0
Compare
- Fix restrict-template-expressions lint error (unknown → String(err)) - Add zombie-reaper.proof.ts to KNIP_OPTIONAL_UNUSED_FILE_ALLOWLIST Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
关闭:长期未合入,risk 标签/评分不理想,释放 review backlog。 |
Closes #97616
What Problem This Solves
Long-running openclaw gateway processes in Docker accumulate zombie processes over time. One user reported 800+ zombie processes (
openclaw-hooks,bash,codex,chrome-headless) after running openclaw 2026.6.10 for several months. Each zombie consumes a PID slot and kernel resources. When the process limit is exhausted, the runtime degrades (spawn EAGAIN,uv_thread_create, gateway instability, connector silence).Root cause: When openclaw kills a process tree via
kill(-pid, SIGKILL), grandchildren may exit and become zombies before their parent (openclaw's direct child) is killed. When the group leader dies, the zombie grandchildren are reparented to PID 1, but no new SIGCHLD is sent because the grandchildren already exited. The zombies remain permanently unreaped.libuv already calls
waitpid(-1, WNOHANG)in a loop inside its SIGCHLD handler, which would reap these zombies — but the SIGCHLD never fires for processes that exited before being reparented.Why This Change Was Made
The fix adds a lightweight zombie reaper (
src/process/zombie-reaper.ts) with two mechanisms:Post-kill reaping: After every process-tree kill (in
process/exec.tsandprocess/supervisor/supervisor.ts), callreapZombies()which sendsSIGCHLDto the current process. This triggers libuv'swaitpid(-1, WNOHANG)loop, reaping any zombie children — including grandchildren reparented to us.Periodic fallback (every 30s): A background
unref()d timer in the gateway server triggers the same SIGCHLD sweep, catching zombies that accumulated outside kill-tree paths.This approach is pure Node.js (
process.kill(process.pid, 'SIGCHLD')) — no native addons, no external dependencies, no Python helpers. It leverages libuv's existing waitpid loop.Why not use tini? The Docker image already uses
tini -sas PID 1, which should reap orphans. But tini cannot reap grandchildren that exit before being reparented — the race is intrinsic tokill(-pid, SIGKILL)timing. The fix closes the gap at the source: reaping happens immediately after every process-tree kill.User Impact
Gateway processes running in Docker (or as PID 1 in any container) no longer accumulate zombie processes over weeks/months. The periodic reaper runs every 30s with no measurable CPU overhead. Windows is a no-op (SIGCHLD doesn't exist).
Evidence
Code quality
oxlint --tsconfig config/tsconfig/oxlint.core.jsonon all 5 changed files: 0 errors, 0 warningsgit diff --check: passed (no whitespace errors)Unit tests
src/process/zombie-reaper.test.ts(6 tests): coverage ofreapZombies()safety,startZombieReaper/stopZombieReaperlifecycle, idempotency, and platform no-opsBehavior proof
src/process/zombie-reaper.proof.ts: run on Linux withnode --import tsx. All 6 invariants verified:Before/after (Docker simulation)
Not tested
Merge Risk
Low. The change:
.unref()'d so it doesn't keep the event loop alive🤖 Generated with Claude Code