diff --git a/src/openenv/harbor/atif.py b/src/openenv/harbor/atif.py index 183ea7b3ae..348305d6e1 100644 --- a/src/openenv/harbor/atif.py +++ b/src/openenv/harbor/atif.py @@ -41,14 +41,15 @@ def load_atif(trial_dir: str | Path) -> dict[str, Any] | None: - """Read `agent/trajectory.json` from a Harbor trial dir. None if the agent emitted none.""" + """Read the ATIF object from a Harbor trial dir, if available.""" path = Path(trial_dir) / "agent" / "trajectory.json" if not path.is_file(): return None try: - return json.loads(path.read_text()) + trace = json.loads(path.read_text()) except Exception: # noqa: BLE001 - a malformed trace must not break a good rollout return None + return trace if isinstance(trace, dict) else None def _pi_session_as_atif(trial_dir: Path) -> dict[str, Any] | None: diff --git a/tests/envs/test_harbor_reconcile.py b/tests/envs/test_harbor_reconcile.py index 255116ec21..45764b22f9 100644 --- a/tests/envs/test_harbor_reconcile.py +++ b/tests/envs/test_harbor_reconcile.py @@ -219,6 +219,18 @@ def test_pi_rollout_ended_by_the_proxy_budget_stop_reconciles(tmp_path): assert "proxy_budget_stops" in codes(report) +@pytest.mark.parametrize("content", ["[]", '"pending"', "false", "1", "null"]) +def test_non_object_atif_uses_the_pi_session(tmp_path, content): + agent_dir = tmp_path / "agent" + agent_dir.mkdir() + (agent_dir / "trajectory.json").write_text(content) + + native = pi_session(tmp_path, [(None, 10), (None, 20)]) + + report = reconcile(document([10, 20]), native) + assert report.ok, report.findings + + def test_pi_zero_token_reply_that_is_not_a_budget_stop_still_fails(tmp_path): doc = document([10, 20]) doc["budget_stop_count"] = 1