Repository navigation
Description
Observed CI failure
PR #675, macOS ARM64, Python 3.12 fails test_std_example_runner_cleans_the_tree_and_reports_captured_output in tools.test_process_tree.
The fixture intentionally times out after two seconds. The timeout handler terminates its process group, drains stdout/stderr, and raises TimeoutExpired. Context-manager exit calls close() and then terminate() again. That second os.killpg raises PermissionError, replacing the expected timeout in the caller:
subprocess.TimeoutExpired: Command '[... compiler.py run examples/std/case.wave]' timed out after 2 seconds
During handling of the above exception, another exception occurred:
tools/process_tree.py:169, __exit__ -> self.close()
tools/process_tree.py:154, close -> self.terminate()
tools/process_tree.py:146, terminate
os.killpg(self.process.pid, signal.SIGKILL)
PermissionError: [Errno 1] Operation not permitted
Ran 58 tests ... FAILED (errors=1, skipped=1)
The same cleanup exception occurs in the master run after #666 and #666's PR run; the latter fails test_timeout_stops_descendants_and_preserves_diagnostics. It is intermittent: latest master instead reaches the separate known standard-I/O failures.
Code evidence and deterministic mechanism check
ProcessTree.terminate/close and run_process perform the repeated group termination. Only ProcessLookupError is treated as an already-absent group; PermissionError escapes from cleanup and masks the primary exception.
A local fault-injection check, with no real processes or signals, confirms the exception replacement:
import subprocess
from unittest.mock import MagicMock, patch
from tools.process_tree import run_process
process = MagicMock()
process.pid = 424242
process.communicate.side_effect = [
subprocess.TimeoutExpired(['fixture'], 2),
('partial stdout', 'partial stderr'),
('partial stdout', 'partial stderr'),
]
with patch('tools.process_tree.subprocess.Popen', return_value=process), patch(
'tools.process_tree.os.killpg',
side_effect=[None, PermissionError(1, 'Operation not permitted')],
) as kill:
try:
run_process(['fixture'], timeout=2, capture_output=True, text=True)
except Exception as error:
print(type(error).__name__) # PermissionError
print(type(error.__context__).__name__) # TimeoutExpired
print(kill.call_count) # 2This proves the masking mechanism. It does not establish why Darwin returned EPERM in the native run; process-group lifecycle and ownership still need native diagnosis. Do not infer PID reuse or successful descendant cleanup solely from this traceback.
Scope and completion criteria
Difficulty: medium/high because process ownership, termination and error reporting must remain correct.
- Diagnose the native EPERM with bounded process/group lifecycle evidence.
- Make successful timeout cleanup and later context-manager cleanup cooperate without unsafe redundant signals or loss of descendant ownership.
- Preserve the original timeout classification and captured output. If cleanup truly fails, retain and clearly surface that failure too, rather than silently reporting that the tree was cleaned up.
- Add deterministic tests for repeated cleanup and termination errors, and run the existing timeout, parent-exits-first and unrelated-process protection tests on native macOS and Linux.
- Keep termination and stream-draining bounded and verify that descendants cannot perform the fixture's post-cleanup side effect.
- Do not blanket-ignore PermissionError, merely increase the timeout, skip macOS, or use a process-name-wide kill as a workaround.
Follow-up to closed #507's process-tree supervision. Separate from #634's generated TCP fixture hang and #633's Wave stdout-capture failures: this failure uses a fake Python compiler and happens in the Python supervision layer before the Rust/native-I/O suite.
Activity
fix: resolve native CI regressions and preserve independent checks (#686