Skip to content

The agent that grows with you

fix(gateway): close the wrapper's stderr pipe in finally; hoist test imports (gate follow-up)

kshitijk4pooraa68a17aeb4c
diff --git a/hermes_cli/stderr_timestamp.py b/hermes_cli/stderr_timestamp.py
index c45464521a9..7b194cd5490 100644
--- a/hermes_cli/stderr_timestamp.py
+++ b/hermes_cli/stderr_timestamp.py
@@ -142,11 +142,11 @@ def main(argv: Sequence[str] | None = None) -> int:
previous_handlers = _install_signal_forwarders(proc)
try:
_copy_stderr_with_timestamps(proc.stderr, log_path)
- proc.stderr.close()
# Keep forwarding until the child has actually exited: a signal that lands between
# its stderr EOF and wait() would otherwise kill the wrapper with the default action.
returncode = proc.wait()
finally:
+ proc.stderr.close()
for signum, handler in previous_handlers.items():
signal.signal(signum, handler)
return _child_returncode_for_supervisor(args.command, returncode)
diff --git a/tests/hermes_cli/test_stderr_timestamp.py b/tests/hermes_cli/test_stderr_timestamp.py
index f375d6cff1f..c408aae608b 100644
--- a/tests/hermes_cli/test_stderr_timestamp.py
+++ b/tests/hermes_cli/test_stderr_timestamp.py
@@ -1,7 +1,11 @@
"""Tests for hermes_cli.stderr_timestamp."""
+import os
import re
+import signal
+import subprocess
import sys
+import time
import pytest
@@ -221,11 +225,6 @@ def test_wrapper_forwards_sigusr1_restart_request_to_child(tmp_path):
drain-aware SIGUSR1 to the wrapper. It must reach the gateway child and the wrapper must
report the child's planned exit code — not die of the signal itself (which makes launchd
treat the restart as a crash and apply its back-off to every sibling profile)."""
- import os
- import signal
- import subprocess
- import time
-
log_path = tmp_path / "gateway.error.log"
ready = tmp_path / "ready"
child = (