diff --git a/CHANGELOG.md b/CHANGELOG.md index e08a26500..41cbcce32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ All notable changes to SkillEvaluator are documented in this file. ### Fixed +- Malformed optional trajectory `final_metrics` leave condition usage unavailable + and no longer abort fresh or reused Tier 3 result collection. - Allow GitHub all-tier CI to opt out of deployment records while retaining environment secrets. Existing consumers keep deployment tracking by default. - Point the PyPI Documentation link at the NVIDIA documentation instead of the GitHub diff --git a/src/skillevaluator/tier3/baseline_store.py b/src/skillevaluator/tier3/baseline_store.py index 003c9b5bf..aa5e9e405 100644 --- a/src/skillevaluator/tier3/baseline_store.py +++ b/src/skillevaluator/tier3/baseline_store.py @@ -67,6 +67,9 @@ def measured_condition_usage(condition_dir: Path) -> dict[str, float | None]: seen.add(trial_id) trajectory = json.loads(reward_path.with_name("trajectory.json").read_text(encoding="utf-8")) metrics = trajectory["final_metrics"] + if not isinstance(metrics, dict): + complete = False + continue for field in fields: value = metrics.get(field) if type(value) in (int, float) and math.isfinite(value) and value >= 0: diff --git a/src/skillevaluator/tier3/harbor/collector.py b/src/skillevaluator/tier3/harbor/collector.py index 67926370f..87351a585 100644 --- a/src/skillevaluator/tier3/harbor/collector.py +++ b/src/skillevaluator/tier3/harbor/collector.py @@ -757,7 +757,9 @@ def _trajectory_agent_runtime_failure_reason(trajectory: Any) -> str: steps = trajectory.get("steps") if not isinstance(steps, list): return "" - final_metrics = trajectory.get("final_metrics") or {} + final_metrics = trajectory.get("final_metrics") + if not isinstance(final_metrics, dict): + final_metrics = {} total_prompt = final_metrics.get("total_prompt_tokens") total_completion = final_metrics.get("total_completion_tokens") tokenless = (total_prompt in (None, 0)) and (total_completion in (None, 0)) diff --git a/tests/test_harbor_collector_runtime_failures.py b/tests/test_harbor_collector_runtime_failures.py index d2d32f698..ae6aa3a53 100644 --- a/tests/test_harbor_collector_runtime_failures.py +++ b/tests/test_harbor_collector_runtime_failures.py @@ -344,6 +344,25 @@ def test_tokenless_trajectory_still_reports_authentication_failure(metrics: dict ) +@pytest.mark.parametrize("final_metrics", (None, [], False, 42, "unavailable", [1], True)) +@pytest.mark.parametrize("message,reason", (("Completed the task.", ""), ("401 Unauthorized", "Unauthorized"))) +def test_fresh_runtime_failure_scan_accepts_nonobject_final_metrics( + tmp_path: Path, final_metrics: object, message: str, reason: str +) -> None: + job_dir = tmp_path / "job" + trial_name = "case-001__attempt" + agent_dir = job_dir / trial_name / "agent" + agent_dir.mkdir(parents=True) + (agent_dir / "trajectory.json").write_text( + json.dumps({"steps": [{"source": "agent", "message": message}], "final_metrics": final_metrics}), + encoding="utf-8", + ) + + failures = collector_module._extract_agent_runtime_failures(job_dir) + + assert failures == ([{"trial": trial_name, "reason": reason}] if reason else []) + + @pytest.mark.parametrize("failure_artifact", ("result.json", "agent/opencode.txt")) def test_explicit_runtime_failure_wins_over_step_token_usage(tmp_path: Path, failure_artifact: str) -> None: trial_dir = tmp_path / "case-001__attempt" diff --git a/tests/tier3/test_usage_metric_shapes.py b/tests/tier3/test_usage_metric_shapes.py new file mode 100644 index 000000000..b2550e1ae --- /dev/null +++ b/tests/tier3/test_usage_metric_shapes.py @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Malformed optional trajectory usage cannot abort completed result collection.""" + +import json +from pathlib import Path + +import pytest + +from skillevaluator.tier3.baseline_store import measured_condition_usage + + +@pytest.mark.parametrize("metrics", [None, [], False, 42, "unavailable"]) +@pytest.mark.parametrize("with_valid_trial", [False, True]) +def test_nonobject_final_metrics_leave_condition_usage_unavailable( + tmp_path: Path, metrics: object, with_valid_trial: bool +) -> None: + records = [("bad", metrics)] + if with_valid_trial: + records.append( + ( + "good", + { + "total_prompt_tokens": 10, + "total_completion_tokens": 4, + "total_cached_tokens": 2, + "total_cost_usd": 0.05, + }, + ) + ) + for trial_id, final_metrics in records: + trial = tmp_path / "trials" / trial_id + trial.mkdir(parents=True) + (trial / "reward.json").write_text(json.dumps({"trial_id": trial_id}), encoding="utf-8") + (trial / "trajectory.json").write_text(json.dumps({"final_metrics": final_metrics}), encoding="utf-8") + + assert measured_condition_usage(tmp_path) == { + "total_prompt_tokens": None, + "total_completion_tokens": None, + "total_cached_tokens": None, + "total_cost_usd": None, + }