Skip to content

The agent that grows with you

fix(agent): attribute verify runs behind timeout durations and valued wrapper flags

Teknium9e96c6db9705
diff --git a/agent/verification_evidence.py b/agent/verification_evidence.py
index 84f39d7e6fa..695d59f8f2e 100644
--- a/agent/verification_evidence.py
+++ b/agent/verification_evidence.py
@@ -267,6 +267,10 @@ def _canonical_tokens(canonical: str) -> list[str]:
_STATUS_PRESERVING_WRAPPERS = {"timeout", "nice", "nohup", "stdbuf"}
+# Wrapper options whose value is the next token (``timeout -s KILL 300``).
+_WRAPPER_VALUE_FLAGS = {"-s", "--signal", "-k", "--kill-after", "-n", "--adjustment", "-i", "-o", "-e"}
+# A bare count or a ``timeout`` duration: ``300``, ``5m``, ``1.5h``.
+_WRAPPER_ARG_RE = re.compile(r"^\d+(?:\.\d+)?[smhd]?$")
def _strip_command_prefix(tokens: list[str]) -> list[str]:
@@ -280,8 +284,8 @@ def _strip_command_prefix(tokens: list[str]) -> list[str]:
i += 1
elif tokens[i] in _STATUS_PRESERVING_WRAPPERS:
i += 1
- while i < len(tokens) and (tokens[i].startswith("-") or tokens[i].isdigit()):
- i += 1
+ while i < len(tokens) and (tokens[i].startswith("-") or _WRAPPER_ARG_RE.match(tokens[i])):
+ i += 2 if tokens[i] in _WRAPPER_VALUE_FLAGS else 1
else:
break
return list(tokens[i:])
diff --git a/tests/agent/test_verification_evidence.py b/tests/agent/test_verification_evidence.py
index 1fb86b6740f..bf1d08b1fc4 100644
--- a/tests/agent/test_verification_evidence.py
+++ b/tests/agent/test_verification_evidence.py
@@ -188,7 +188,10 @@ def test_dot_slash_script_invocation_matches_detected_script(tmp_path, monkeypat
assert evidence.canonical_command == "scripts/run_tests.sh"
[email protected]("command", ["timeout 300 pytest -q", "nice -n 5 pytest -q"])
+ "command",
+ ["timeout 300 pytest -q", "nice -n 5 pytest -q", "timeout 5m pytest -q", "timeout -s KILL 300 pytest -q"],
+)
def test_status_preserving_wrapper_still_attributes_the_run(tmp_path, monkeypatch, command):
"""``timeout``/``nice`` return the child's status, so the run proves the verifier's."""
monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))