Repository navigation
Description
What happened?
While fixing and validating the error-recovery changes in #217, we found a small, intermittent macOS process-exit timing issue in the local-mode cancellation test. Filing it separately because it affects process cleanup/test synchronization rather than error-recovery scoring.
The observed impact is flaky test validation. We did not observe a persistent child process or ongoing work after cancellation: every captured failing child disappeared without another signal within approximately 1.6 ms of the assertion. This appears to be a low-severity timing issue based on the evidence below.
The failing case is:
tests/test_harbor_local_mode.py::test_streamed_exec_escalates_after_launcher_exits_with_term_ignoring_descendant[cancel]
tests/test_harbor_local_mode.py:3349:
with pytest.raises(ProcessLookupError):
E Failed: DID NOT RAISE ProcessLookupError
The test expects the child PID to have disappeared immediately when cancellation cleanup returns. Occasionally os.kill(child_pid, 0) still succeeds while macOS is finishing the child's exit.
Reproduction steps
On macOS, use a disposable checkout of either commit listed below with the project's test and Harbor dependencies installed. A single run often passes. This wrapper invokes the existing test unchanged 100 times with distinct test IDs, allowing four workers to exercise the race:
cat > tests/_process_reap_comparison_test.py <<'PY'
from pathlib import Path
import runpy
import pytest
original = runpy.run_path(str(Path(__file__).with_name("test_harbor_local_mode.py")))[
"test_streamed_exec_escalates_after_launcher_exits_with_term_ignoring_descendant"
]
@pytest.mark.parametrize("attempt", range(100))
def test_cancel_repeat(tmp_path, attempt):
original(tmp_path=tmp_path, lifecycle="cancel")
PY
PYTHONPATH="$PWD/src" .venv/bin/python -m pytest -n 4 -q tests/_process_reap_comparison_test.py
rm tests/_process_reap_comparison_test.pyObserved results in isolated source copies using the same Python environment:
| Commit | Ten individual runs | 100 runs across four workers |
|---|---|---|
5349e9b |
10 passed | 98 passed, 2 failed |
22d82c7 |
10 passed | 98 passed, 2 failed |
The failing test and src/skillevaluator/tier3/harbor/local_environment.py are byte-for-byte identical between these commits. The failure therefore predates the Harbor-marker follow-up in 22d82c7.
Process-state evidence
A separate diagnostic run on 5349e9b invoked the original test 200 times across four workers, recording os.kill/os.killpg outcomes and reading macOS KERN_PROC_PID state immediately after the assertion's successful PID probe. The observation occurred before the test's finally block could send another signal. That run produced 193 passes and 7 failures.
In all seven captured failures:
- Cleanup successfully sent
SIGKILLto the process group. - The subsequent
os.killpg(group, 0)raisedPermissionError(EPERM). The existing group-wait helper returns on that exception. - The test's immediate
os.kill(child, 0)still succeeded. - The child PID disappeared naturally, without another signal, within about 1.6 ms of the assertion.
Four kernel-state captures showed:
parent PID: 1
process state: SRUN
process flags: 0x2004, including P_WEXIT ("Working on exiting")
exit status: 9 (SIGKILL)
next observation: ESRCH (PID no longer present)
In the other three cases, the PID had already disappeared before the first kernel-state read completed. The reader was validated against a deliberately unreaped child, which correctly reported SZOMB, and then ESRCH after waitpid.
These observations support a short exit-teardown race. They do not establish that the captured children were in a stable zombie state: the observed states were exiting (P_WEXIT) or already gone. No persistent child was observed in these runs.
Relevant code at the baseline revision:
Expected outcome: make the cleanup/test synchronization tolerate bounded exit completion on macOS while retaining a meaningful failure when a child actually survives cancellation. The appropriate change to the wait helper or assertion still needs review; no fix for this issue is included in #217.
SkillEvaluator version or commit
- Baseline:
5349e9b0c2c83dcb6d331b3800a3ec98085592ae - Follow-up:
22d82c7c0b998d048d28a5429653d22d377f5f11 - Branch:
fix/error-recovery-149inmavericksea-ai/SkillEvaluator
Environment
- macOS 27.0.1, arm64
- Python 3.13.12 in the repository virtual environment
- Harbor 0.24.0
- pytest 9.1.1; pytest-xdist 3.8.0
- Four workers (
-n 4); the existing test initializes local mode with sandboxing disabled
Before submitting
- I agree to follow this project's Code of Conduct.
- I searched existing issues and found no duplicate of this report.
Activity
mavericksea-ai commentedon Oct 23, 2026
Adding the diagnostic sources and raw failure records so the process-state evidence can be reproduced independently. This adds evidence only; it does not propose or apply a code fix.
The diagnostic calls the existing
test_streamed_exec_escalates_after_launcher_exits_with_term_ignoring_descendanttest withlifecycle="cancel", unchanged. It wrapsos.kill/os.killpgto record the group signals and, if the assertion's PID probe succeeds, samplesKERN_PROC_PIDbefore the test'sfinallyblock can send another signal. It uses the macOS SDK'sstruct kinfo_procthrough a small C helper rather than hard-coded ctypes structure offsets.5349e9b5349e9b22d82c7Across all 19 captured failures, SIGKILL to the group returned successfully, the following group existence check raised
EPERM, and the child's immediate PID probe still succeeded. Every observed child then disappeared without another signal. In 12 captures the state reader sawSRUN,P_WEXIT(0x2000) set, and exit status 9; in the other seven, the child was already gone before the first state read. The reader's separate self-check reportsSZOMBfor a deliberately unreaped child andESRCHafterwaitpid.The uninstrumented 100-repetition wrapper in the issue also reproduced the same assertion: originally 98 passed / 2 failed on each of
5349e9band22d82c7, and another 98 passed / 2 failed on5349e9bduring today's recheck. Instrumentation can affect timing; these counts are observations, not an estimate of a universal failure rate. The sampling loop sleeps approximately 1 ms between reads, so the reported durations are observation intervals, not precise kernel exit latency or a guaranteed upper bound for other runs. This supports a brief exit-completion race in this scenario, not a claim that every cancellation path is safe.Run the diagnostic
Requires macOS, Xcode Command Line Tools (
xcrun clang), and the checkout's installed Python test dependencies including Harbor and pytest-xdist. Save the following block as/tmp/issue221-diagnostics.sh, then run it from the checkout root:The runner prints a new temporary directory containing the sources, compiled reader, all 200 per-attempt JSON records,
results.xml, andpytest.log. It creates no tracked repository files. If the interpreter is elsewhere, setISSUE221_PYTHON=/absolute/path/to/pythonwhen invoking it. Use a checkout of5349e9bor22d82c7to match the recorded revisions; the runner records the actual checkout HEAD and verifies that the cleanup module imports from that checkout'ssrcdirectory. A nonzero pytest exit is expected when the reported assertion reproduces; a clean run does not disprove an intermittent race.Complete diagnostic runner (shell, C state reader, and Python test wrapper)
Raw evidence
Below are all failure records from the three diagnostic runs, including the original seven cited in the issue. Numeric values, timestamps, PID samples, and signal outcomes are preserved from the saved per-attempt JSON; they are grouped here with counts derived from all 200 records in each run. Passing per-attempt records are omitted from this comment for size; the runner writes both passing and failing records when reproduced.
time_nsis a monotonic timestamp, not wall-clock time. On the recorded macOS environment, errno 1 isEPERMand errno 3 isESRCH.Raw JSON: all 19 captured failures across three runs
[ { "run": "Original diagnostic run, 2026-10-21", "trials": 200, "passed": 193, "failed": 7, "maximum_observation_ms": 1.503458, "failure_records": [ { "attempt": 18, "revision": "5349e9b", "events": [ { "time_ns": 118733855521791, "operation": "killpg", "pgid": 62573, "signal": 15, "errno": 0 }, { "time_ns": 118733856032416, "operation": "killpg", "pgid": 62573, "signal": 9, "errno": 0 }, { "time_ns": 118733856058541, "operation": "killpg", "pgid": 62573, "signal": 0, "errno": 1 } ], "child_pid": 62580, "assertion_time_ns": 118733856490500, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118733856531958, "pid": 62580, "errno": 3 } ], "observation_ms": 0.370625, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 54, "revision": "5349e9b", "events": [ { "time_ns": 118734383246333, "operation": "killpg", "pgid": 62740, "signal": 15, "errno": 0 }, { "time_ns": 118734383919166, "operation": "killpg", "pgid": 62740, "signal": 9, "errno": 0 }, { "time_ns": 118734383941625, "operation": "killpg", "pgid": 62740, "signal": 0, "errno": 1 } ], "child_pid": 62745, "assertion_time_ns": 118734384343375, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734384378041, "pid": 62745, "ppid": 1, "pgid": 62740, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 118734385699583, "pid": 62745, "errno": 3 } ], "observation_ms": 1.369875, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 57, "revision": "5349e9b", "events": [ { "time_ns": 118734526953541, "operation": "killpg", "pgid": 62776, "signal": 15, "errno": 0 }, { "time_ns": 118734535966916, "operation": "killpg", "pgid": 62776, "signal": 9, "errno": 0 }, { "time_ns": 118734535998416, "operation": "killpg", "pgid": 62776, "signal": 0, "errno": 1 } ], "child_pid": 62783, "assertion_time_ns": 118734536730125, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734536810500, "pid": 62783, "ppid": 1, "pgid": 62776, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 118734538170791, "pid": 62783, "errno": 3 } ], "observation_ms": 1.503458, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 58, "revision": "5349e9b", "events": [ { "time_ns": 118734624043291, "operation": "killpg", "pgid": 62804, "signal": 15, "errno": 0 }, { "time_ns": 118734624608125, "operation": "killpg", "pgid": 62804, "signal": 9, "errno": 0 }, { "time_ns": 118734624633041, "operation": "killpg", "pgid": 62804, "signal": 0, "errno": 1 } ], "child_pid": 62811, "assertion_time_ns": 118734625048666, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734625083875, "pid": 62811, "errno": 3 } ], "observation_ms": 0.087625, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 66, "revision": "5349e9b", "events": [ { "time_ns": 118734355248041, "operation": "killpg", "pgid": 62729, "signal": 15, "errno": 0 }, { "time_ns": 118734355942000, "operation": "killpg", "pgid": 62729, "signal": 9, "errno": 0 }, { "time_ns": 118734355969583, "operation": "killpg", "pgid": 62729, "signal": 0, "errno": 1 } ], "child_pid": 62738, "assertion_time_ns": 118734356378458, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734356417750, "pid": 62738, "ppid": 1, "pgid": 62729, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 118734357752750, "pid": 62738, "errno": 3 } ], "observation_ms": 1.389375, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 67, "revision": "5349e9b", "events": [ { "time_ns": 118734479777583, "operation": "killpg", "pgid": 62760, "signal": 15, "errno": 0 }, { "time_ns": 118734480315208, "operation": "killpg", "pgid": 62760, "signal": 9, "errno": 0 }, { "time_ns": 118734480337958, "operation": "killpg", "pgid": 62760, "signal": 0, "errno": 1 } ], "child_pid": 62765, "assertion_time_ns": 118734480731125, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734480765708, "pid": 62765, "errno": 3 } ], "observation_ms": 0.082458, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 115, "revision": "5349e9b", "events": [ { "time_ns": 118734855056375, "operation": "killpg", "pgid": 62884, "signal": 15, "errno": 0 }, { "time_ns": 118734855603041, "operation": "killpg", "pgid": 62884, "signal": 9, "errno": 0 }, { "time_ns": 118734855627833, "operation": "killpg", "pgid": 62884, "signal": 0, "errno": 1 } ], "child_pid": 62891, "assertion_time_ns": 118734856003333, "assertion_kill_errno": 0, "samples": [ { "time_ns": 118734856037208, "pid": 62891, "ppid": 1, "pgid": 62884, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 118734857355166, "pid": 62891, "errno": 3 } ], "observation_ms": 1.368583, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" } ] }, { "run": "Independent recheck, 2026-10-23", "trials": 200, "passed": 195, "failed": 5, "maximum_observation_ms": 1.477958, "failure_records": [ { "attempt": 22, "revision": "5349e9b", "events": [ { "time_ns": 170790591581416, "operation": "killpg", "pgid": 98409, "signal": 15, "errno": 0 }, { "time_ns": 170790592132750, "operation": "killpg", "pgid": 98409, "signal": 9, "errno": 0 }, { "time_ns": 170790592155833, "operation": "killpg", "pgid": 98409, "signal": 0, "errno": 1 } ], "child_pid": 98416, "assertion_time_ns": 170790592592958, "assertion_kill_errno": 0, "samples": [ { "time_ns": 170790592636875, "pid": 98416, "ppid": 1, "pgid": 98409, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 170790593973083, "pid": 98416, "errno": 3 } ], "observation_ms": 1.391708, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 30, "revision": "5349e9b", "events": [ { "time_ns": 170790384490458, "operation": "killpg", "pgid": 98348, "signal": 15, "errno": 0 }, { "time_ns": 170790388488375, "operation": "killpg", "pgid": 98348, "signal": 9, "errno": 0 }, { "time_ns": 170790388515958, "operation": "killpg", "pgid": 98348, "signal": 0, "errno": 1 } ], "child_pid": 98353, "assertion_time_ns": 170790388924375, "assertion_kill_errno": 0, "samples": [ { "time_ns": 170790388967833, "pid": 98353, "errno": 3 } ], "observation_ms": 0.375458, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 53, "revision": "5349e9b", "events": [ { "time_ns": 170790762005208, "operation": "killpg", "pgid": 98459, "signal": 15, "errno": 0 }, { "time_ns": 170790762567125, "operation": "killpg", "pgid": 98459, "signal": 9, "errno": 0 }, { "time_ns": 170790762589875, "operation": "killpg", "pgid": 98459, "signal": 0, "errno": 1 } ], "child_pid": 98467, "assertion_time_ns": 170790762996625, "assertion_kill_errno": 0, "samples": [ { "time_ns": 170790763037458, "pid": 98467, "ppid": 1, "pgid": 98459, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 170790764406166, "pid": 98467, "errno": 3 } ], "observation_ms": 1.477958, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 153, "revision": "5349e9b", "events": [ { "time_ns": 170791551271791, "operation": "killpg", "pgid": 98721, "signal": 15, "errno": 0 }, { "time_ns": 170791551838666, "operation": "killpg", "pgid": 98721, "signal": 9, "errno": 0 }, { "time_ns": 170791551861250, "operation": "killpg", "pgid": 98721, "signal": 0, "errno": 1 } ], "child_pid": 98727, "assertion_time_ns": 170791552274916, "assertion_kill_errno": 0, "samples": [ { "time_ns": 170791552306458, "pid": 98727, "ppid": 1, "pgid": 98721, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 170791553624083, "pid": 98727, "errno": 3 } ], "observation_ms": 1.367959, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 156, "revision": "5349e9b", "events": [ { "time_ns": 170791706490083, "operation": "killpg", "pgid": 98773, "signal": 15, "errno": 0 }, { "time_ns": 170791707522500, "operation": "killpg", "pgid": 98773, "signal": 9, "errno": 0 }, { "time_ns": 170791707546541, "operation": "killpg", "pgid": 98773, "signal": 0, "errno": 1 } ], "child_pid": 98779, "assertion_time_ns": 170791707946041, "assertion_kill_errno": 0, "samples": [ { "time_ns": 170791707979125, "pid": 98779, "ppid": 1, "pgid": 98773, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 170791709289291, "pid": 98779, "errno": 3 } ], "observation_ms": 1.355667, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" } ] }, { "run": "Portable diagnostic validation, 2026-10-23", "trials": 200, "passed": 193, "failed": 7, "maximum_observation_ms": 1.420458, "failure_records": [ { "attempt": 22, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171674080227375, "operation": "killpg", "pgid": 99883, "signal": 15, "errno": 0 }, { "time_ns": 171674080891333, "operation": "killpg", "pgid": 99883, "signal": 9, "errno": 0 }, { "time_ns": 171674080921791, "operation": "killpg", "pgid": 99883, "signal": 0, "errno": 1 } ], "child_pid": 99888, "assertion_time_ns": 171674081347875, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171674081390916, "pid": 99888, "ppid": 1, "pgid": 99883, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 171674082732125, "pid": 99888, "errno": 3 } ], "observation_ms": 1.402541, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 43, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171673971840875, "operation": "killpg", "pgid": 99853, "signal": 15, "errno": 0 }, { "time_ns": 171673972372416, "operation": "killpg", "pgid": 99853, "signal": 9, "errno": 0 }, { "time_ns": 171673972413541, "operation": "killpg", "pgid": 99853, "signal": 0, "errno": 1 } ], "child_pid": 99860, "assertion_time_ns": 171673972850375, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171673972895833, "pid": 99860, "errno": 3 } ], "observation_ms": 0.688541, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 46, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171674187198458, "operation": "killpg", "pgid": 99910, "signal": 15, "errno": 0 }, { "time_ns": 171674187708583, "operation": "killpg", "pgid": 99910, "signal": 9, "errno": 0 }, { "time_ns": 171674187733750, "operation": "killpg", "pgid": 99910, "signal": 0, "errno": 1 } ], "child_pid": 99915, "assertion_time_ns": 171674188170458, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171674188207625, "pid": 99915, "ppid": 1, "pgid": 99910, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 171674189556166, "pid": 99915, "errno": 3 } ], "observation_ms": 1.420458, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 113, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171674746598541, "operation": "killpg", "pgid": 192, "signal": 15, "errno": 0 }, { "time_ns": 171674747256666, "operation": "killpg", "pgid": 192, "signal": 9, "errno": 0 }, { "time_ns": 171674747279916, "operation": "killpg", "pgid": 192, "signal": 0, "errno": 1 } ], "child_pid": 199, "assertion_time_ns": 171674747668875, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171674747707250, "pid": 199, "errno": 3 } ], "observation_ms": 0.100416, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 131, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171674920844166, "operation": "killpg", "pgid": 251, "signal": 15, "errno": 0 }, { "time_ns": 171674921448416, "operation": "killpg", "pgid": 251, "signal": 9, "errno": 0 }, { "time_ns": 171674921471166, "operation": "killpg", "pgid": 251, "signal": 0, "errno": 1 } ], "child_pid": 257, "assertion_time_ns": 171674921889208, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171674921924791, "pid": 257, "ppid": 1, "pgid": 251, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 171674923231083, "pid": 257, "errno": 3 } ], "observation_ms": 1.365667, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 178, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171675368919708, "operation": "killpg", "pgid": 439, "signal": 15, "errno": 0 }, { "time_ns": 171675369793500, "operation": "killpg", "pgid": 439, "signal": 9, "errno": 0 }, { "time_ns": 171675369824250, "operation": "killpg", "pgid": 439, "signal": 0, "errno": 1 } ], "child_pid": 445, "assertion_time_ns": 171675370371500, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171675370414791, "pid": 445, "errno": 3 } ], "observation_ms": 0.1055, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" }, { "attempt": 180, "revision": "22d82c7c0b998d048d28a5429653d22d377f5f11", "events": [ { "time_ns": 171675389210666, "operation": "killpg", "pgid": 444, "signal": 15, "errno": 0 }, { "time_ns": 171675389826458, "operation": "killpg", "pgid": 444, "signal": 9, "errno": 0 }, { "time_ns": 171675389850333, "operation": "killpg", "pgid": 444, "signal": 0, "errno": 1 } ], "child_pid": 452, "assertion_time_ns": 171675390282125, "assertion_kill_errno": 0, "samples": [ { "time_ns": 171675390321125, "pid": 452, "ppid": 1, "pgid": 444, "status": 2, "status_name": "SRUN", "comm": "bash", "flags": 8196, "exit_status": 9 }, { "time_ns": 171675391641416, "pid": 452, "errno": 3 } ], "observation_ms": 1.383083, "outcome": "Failed", "message": "DID NOT RAISE ProcessLookupError" } ] } ]The test file and
src/skillevaluator/tier3/harbor/local_environment.pyhave identical Git blob IDs at upstream2085a03,5349e9b,22d82c7, and main as checked on 2026-10-23:The open implementation question remains how to handle the group wait's
PermissionErrorand the test's immediate PID assertion while still detecting a child that actually survives cancellation. No fix or PR is included here.test: wait for descendant exit after streamed exec cleanup