Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 55 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
mrveiss
left a comment
There was a problem hiding this comment.
Verdict: APPROVE @ f013bb4
Static review; not run.
Process tree: run_shell_bounded -> create_subprocess_shell(start_new_session=True) = sh -c "<cmd>", group leader (pgid == pid), non-interactive so no job control and every descendant stays in that group. <cmd> is sh -c 'record; sleep 60'; the recorded $$ is the inner sh, the leader or its direct child depending on whether the outer sh execs its last command. Nothing uses setsid/nohup. In the new test sleep 60 & is a true non-leader grandchild.
Diagnosis (product correct): bounded_subprocess.py:99-115 _wait_bounded: on TimeoutError finished stays False, so finally runs kill_and_reap(process, process_group=True). subprocess_reap.py kill_and_reap does an unconditional os.killpg(process.pid, SIGKILL) (no returncode guard on the group path), suppressing only ProcessLookupError (group already empty), then reaps the leader. The leader is still unreaped at kill time, so its pid is still the pgid; no pid-reuse window. No SIGTERM grace path, no early return. If the shell exits by itself at the deadline, the group is still killed (the group path ignores returncode). SIGKILL cannot be blocked, and delivery to another task is asynchronous. A zombie also answers kill(pid,0). So a correct product can fail the old one-shot _alive, and (A) is sufficient. Established: control flow, and the log (_alive(14027) True at 09:11:56, one failure in ~7300). Not established: zombie vs pending-signal, and whether the pid was dead afterwards (the log has no later probe). A real leak is not excluded by data, only by the code path. This matches #20740's AC ("kills the process on expiry; a test shows a sleeping command killed at the bound").
False green: bound = _DEADLINE_S = 1 s, polled after the run already returned; the children sleep 60 s. A shell-only kill leaves sleep 60 in state S with the same start time, so the poll returns False at 1 s and the assertion fails. Natural exit cannot mask it (60 s >> 1 s) in any of the three tests. Weakness, non-blocking: in the default-deadline and own-group tests, if the outer sh execs the inner sh the recorded pid IS the leader, so those two cannot distinguish shell-only from group kill. The new grandchild test is the discriminating one, and it does (real grandchild, wait keeps the shell alive until killed).
Stat line: $$ is expanded by the inner sh (it sits inside the outer single quotes), so it is the inner sh's own pid; > file binds to the echo only; in the new test $! is the sleep's pid. The start time is unchanged by exec. _stat_fields splits after the LAST ): state = index 0, starttime = index 19 (field 22). Correct. Fallback to ProcessLookupError on read handled.
False red: after the 1 s kill window a Z zombie counts as gone (right even where no init reaps). Non-blocking: reusing the 1 s deadline as the poll bound leaves little margin on the same loaded worker that caused the flake. Use a separate _GONE_WITHIN_S of ~5 s; false green is unaffected since the sleeps are 60 s.
Hygiene: test file only, 187 lines, no product change, Refs not Closes, no footer, labels/milestone set. Added runtime: one extra ~1 s test. /proc is Linux-only and the file has no skip markers (killpg/getpgid already POSIX-only); CI is Linux, fine. Non-blocking: on assertion failure the sleep 60 leaks for a minute (no finally kill); add one.
Own CI: gh pr checks returned no shard rows yet.
Blocking: none. Non-blocking: wider poll bound; cleanup in finally; optional product strengthening (bounded wait for the group to be empty) tracked on #21308.
|
Both findings addressed in cb8d2fc (test file only; not run locally; needs CI).
|
mrveiss
left a comment
There was a problem hiding this comment.
Verdict: APPROVE @ cb8d2fc
Scope: delta f013bb4..cb8d2fc, one file (bounded_shell_default_20740_test.py, +34/-11). The earlier diagnosis and analysis stand.
Poll bound: _EXIT_POLL_BOUND_S = 5 s. The loop uses loop.time() (monotonic), asyncio.to_thread for the /proc read and asyncio.sleep, so the event loop is never blocked. It returns False at the bound, and the assert runs on that boolean after the loop. Every child sleeps 60 s, so a surviving child reads as alive for the whole 5 s and a false pass is impossible. Worst case is about 6 s when the product is broken and milliseconds past the 1 s deadline when it is correct. No per-test timeout exists in the suite config: the only "timeout" match in pytest.ini is a comment, and pyproject.toml has none.
Cleanup (a)-(e):
(a) pid/start are read before the try, by _identity_from, which raises before any finally exists. No unbound name and no masking.
(b) _kill_leftover handles ProcessLookupError, and _is_gone handles a missing stat file. The remaining exposure is an empty or short stat read, which would raise IndexError. That is extremely unlikely for a pid this test started, and it would surface only on the failure path.
(c) The pid-reuse guard is sound. _is_gone compares the recorded start time, so a recycled pid is treated as gone and never signalled. A same-user pid also rules out PermissionError.
(d) On the success path the process is already gone, so _kill_leftover returns without sending a signal.
(e) The grandchild test cleans the grandchild sleep. If the product were broken, the shell is blocked in wait, and killing the sleep lets it exit, so nothing is left behind. In the two tests that clean the sh -c pid, a non-exec'ing sh could leave its own sleep 60 behind. It would exit by itself within 60 s.
Line length: line 192 (the grandchild docstring) is 121 columns. It is new in this PR, since main has no line over 120 and the grandchild test does not exist there. It was already 121 columns at f013bb4 (line 172). CI enforces max-line-length = 120 in .flake8, but that file's per-file-ignores list E501 for *_test.py, so flake8 will not fail it. Black does not rewrap docstrings.
Hygiene: signal and os are both used. _gone_within_bound is consistent at all three call sites, and no stale names remain. There is no comment-marker matching and no glob-like quoted strings.
Findings:
- Non-blocking: wrap the 121-column docstring at line 192 to 120 or less.
- Non-blocking: in _is_gone, treat an empty or short stat read as gone, or catch IndexError.
- Non-blocking: in the two
sh -ctests, the innersleep 60is not tracked if sh does not exec it.
CI at head: only "Detect changed paths" is pending, and no shard has completed.
Static review; not run.
✅ SSOT Configuration Compliance: Passing🎉 No new hardcoded values of either class — Known backlog in |
|
Boarded merge train #21373 (T114) at |
|
Landed on main through merge train #21373 as 394642f; member head cb8d2fc is an ancestor of main (the PR branch has since moved to 5e5b587, an auto-sync merge of main only, not in the train). Content check on main (3-dot diff of the member head against main is empty): No revert of it on main. Issue #21308 stays open: the absence of the flake needs several subsequent CI runs. |
|
Branch audit (zero-change deletion). This PR shows 0 changed files against |
Thinking Path
The assertion that failed (
the child outlived the deadline) is the safety property of #20740, so the first question was whether the product or the test is wrong. The product sends SIGKILL to the whole process group and then reaps only the group leader (autobot_shared/subprocess_reap.pykill_and_reap, called fromutils/bounded_subprocess.py_wait_bounded). Its contract (#20740 ACs: kill on expiry, a test shows a sleeping command killed at the bound) is "killed", and a non-leader member of the group cannot be reaped by the caller: it stays a zombie in the group until its new parent reaps it, so the product has no deterministic thing to wait on either.The test checked liveness once, immediately, with
os.kill(pid, 0). That call succeeds for a zombie, and for a process whose SIGKILL has been queued but not yet delivered, which is likely on a loaded worker. Sightings: the original report (killpg test), PR #21328 head 2a91f28 (shard 3/8), merge-train PR #21349 run 43176216525 shard 3/8, line 51_alive(<pid>)True, one failure in ~7300 tests on a parallel worker.What Changed
autobot-backend/utils/bounded_shell_default_20740_test.py: both single-shot checks (test_a_command_with_no_policy_is_killed_at_the_default_deadline,test_a_timed_out_command_kills_only_its_own_process_group) now poll/proc/<pid>/statuntil the process is gone, bounded by the deadline value the test hands the runner (_DEADLINE_S). Gone means absent, a zombie (state Z), or a different process under the same pid (start time recorded by the child itself from its own stat line, builtins only).test_a_grandchild_the_shell_waits_on_dies_with_the_group.Why this shape
Product wait was considered and rejected: the group keeps zombie members until their parent reaps them, so polling the group would wait on an init-side event the product does not control. A zombie is dead for the safety property. The new test would fail on a shell-only kill: a
sleep 60the shell is blocked on inwaitwould be orphaned and stay running (state S) past the poll bound, so it cannot pass by timing accident. A survivor is detected by state, not by elapsed time.Verification
_alive(14027)True; source reading ofkill_and_reapand the old_alive.Model Used
Claude Sonnet 5.5
Refs #21308