Skip to content

The agent that grows with you

fix: inert heredoc bodies no longer trip the gateway lifecycle guard (#88336)

zgqq9aa0721b23e9
diff --git a/cron/lifecycle_guard.py b/cron/lifecycle_guard.py
index a3960c0efca..bea86cc8675 100644
--- a/cron/lifecycle_guard.py
+++ b/cron/lifecycle_guard.py
@@ -237,6 +237,15 @@ def contains_gateway_lifecycle_command(text: str) -> bool:
"""
if not text:
return False
+ # Heredoc bodies that are provably inert data (quoted delimiter, data-sink
+ # consumer like `cat > file <<'EOF'`) are masked before scanning (#88336):
+ # a runbook line "a human can run: hermes gateway restart" inside such a
+ # body is documentation, not a command this shell will execute. The
+ # stripper fails open on ANY ambiguity (unquoted delimiter, shell
+ # consumer, unterminated body), so executable heredocs are still scanned.
+ from tools.shell_heredoc import strip_inert_heredoc_bodies
+
+ text = strip_inert_heredoc_bodies(text)
normalized = _SHELL_LINE_CONTINUATION.sub(" ", text)
if _GATEWAY_LIFECYCLE_PATTERN.search(normalized):
return True
diff --git a/tests/hermes_cli/test_gateway_restart_loop.py b/tests/hermes_cli/test_gateway_restart_loop.py
index 4f8b27c10b4..c75016796f5 100644
--- a/tests/hermes_cli/test_gateway_restart_loop.py
+++ b/tests/hermes_cli/test_gateway_restart_loop.py
@@ -250,6 +250,25 @@ class TestGatewayLifecyclePattern:
def test_python_argv_stripping_stays_narrow(self, text):
assert not _contains_gateway_lifecycle_command(text), f"Should NOT match: {text!r}"
+ def test_inert_heredoc_body_prose_not_blocked(self):
+ # #88336: a quoted-delimiter heredoc feeding a data sink is inert
+ # data — runbook prose inside it must not block.
+ text = (
+ "cat > /tmp/runbook.md <<'EOF'\n"
+ "If the box is wedged, a human can run: hermes gateway restart\n"
+ "EOF"
+ )
+ assert not _contains_gateway_lifecycle_command(text), f"Should NOT match: {text!r}"
+
+ @pytest.mark.parametrize("text", [
+ # Executable heredoc (shell consumer) must stay blocked.
+ "bash <<EOF\nhermes gateway restart\nEOF",
+ # Unquoted delimiter = expansion-capable = fail open to scanning.
+ "cat > /tmp/x <<EOF\nhermes gateway restart\nEOF",
+ ])
+ def test_non_inert_heredocs_still_scanned(self, text):
+ assert _contains_gateway_lifecycle_command(text), f"Should match: {text!r}"
+
class TestProfileFlagGatewayLifecycle:
"""#78028: `hermes -p <profile> gateway restart|stop` bypasses Branch A's