Skip to content

The agent that grows with you

fix(agent): trust PIPESTATUS behind && only when the chain reached the pipeline

Tekniumb82a6f7cdfaf
diff --git a/agent/verification_evidence.py b/agent/verification_evidence.py
index c67a627f1e4..83e3de38600 100644
--- a/agent/verification_evidence.py
+++ b/agent/verification_evidence.py
@@ -223,7 +223,10 @@ def _segment_status(
Only the last ``;``-separated sequence reports its status; backgrounding and ``||``
hide it; an ``&&`` chain proves each member only on success. A pipeline hides every
status but the last segment's, unless ``pipeline_status`` (the shell's PIPESTATUS
- array) is supplied and the match is the pipeline's leading command.
+ array) is supplied and the match leads the sequence's last pipeline. Behind ``&&``
+ that pipeline may never have run, leaving PIPESTATUS from an earlier one
+ (``true | false && pytest | tail``); a short-circuited chain exits non-zero, so
+ there the array counts only when the shell's own code is 0, as for plain ``&&``.
"""
if not segments or not 0 <= match_index < len(segments) or any(s.following_operator == "&" for s in segments):
return None
@@ -248,7 +251,8 @@ def _segment_status(
),
default=sequence_start,
)
- if pipeline_status and len(pipeline_status) >= 2 and match_index == pipeline_start:
+ chain_ran = "&&" not in operators or int(exit_code) == 0
+ if chain_ran and pipeline_status and len(pipeline_status) >= 2 and match_index == pipeline_start:
return pipeline_status[0]
return None
if not operators:
diff --git a/tests/agent/test_verification_evidence.py b/tests/agent/test_verification_evidence.py
index ba3e8b1ca01..d6c88222c21 100644
--- a/tests/agent/test_verification_evidence.py
+++ b/tests/agent/test_verification_evidence.py
@@ -117,6 +117,24 @@ def test_piped_verifier_without_pipeline_status_is_not_evidence(tmp_path, monkey
) is None
[email protected]("command, exit_code, pipeline_status, expected", [
+ ("true | false && pytest -q | tail -5", 1, [0, 1], None),
+ ("cd . && pytest -q | tail -5", 0, [1, 0], "failed"),
+])
+def test_piped_verifier_behind_and_counts_only_when_the_chain_ran(
+ tmp_path, monkeypatch, command, exit_code, pipeline_status, expected,
+):
+ """A short-circuited ``&&`` skips the verifier and leaves an earlier pipeline's PIPESTATUS."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ _python_project(tmp_path)
+
+ evidence = classify_verification_command(
+ command, cwd=tmp_path, session_id="s1", exit_code=exit_code, pipeline_status=pipeline_status,
+ )
+
+ assert (evidence and evidence.status) == expected
+
+
@pytest.mark.parametrize("pipeline_status", [[0], [1]])
def test_piped_verifier_with_single_pipeline_status_is_not_evidence(
tmp_path, monkeypatch, pipeline_status,