Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- Budget-limited Tier 3 coverage checks retain admitted attempt ordinals, avoiding false missing/excess errors when a denied slot leaves a gap.
- HTML reports retain budget context for fully budget-denied runs without
restoring untrusted score evidence.
- Fully budget-denied runs exit successfully and finish progress without an
Expand Down
36 changes: 29 additions & 7 deletions src/skillevaluator/tier3/harbor/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6820,6 +6820,7 @@ def _condition_execution_summary(
pass_threshold: float = 0.50,
attempt_slots: dict[str, dict[str, Any]] | None = None,
expected_attempts_by_case: Mapping[str, int] | None = None,
expected_attempt_ordinals_by_case: Mapping[str, set[int]] | None = None,
) -> dict[str, Any]:
"""Describe whether a Harbor condition produced complete logical attempts.

Expand Down Expand Up @@ -6958,8 +6959,14 @@ def _case_attempt_coverage(case_id: str, attempts: list[dict[str, Any]]) -> tupl
if required > n_attempts:
errors.append(f"Scored case {case_id!r} has an attempt ordinal above configured maximum {n_attempts}")

expected_ordinals = set(range(1, required + 1))
if expected_attempt_ordinals_by_case is not None and case_id in expected_attempt_ordinals_by_case:
expected_ordinals = set(expected_attempt_ordinals_by_case[case_id])
if stop_on_pass and first_pass is not None:
expected_ordinals = {ordinal for ordinal in expected_ordinals if ordinal <= required}
required = len(expected_ordinals)

if all_explicit:
expected_ordinals = set(range(1, required + 1))
actual_ordinals = set(explicit + recovered_ordinals)
missing_ordinals = sorted(expected_ordinals - actual_ordinals)
if attempt_slots is not None:
Expand All @@ -6970,12 +6977,13 @@ def _case_attempt_coverage(case_id: str, attempts: list[dict[str, Any]]) -> tupl
}
return required, bool(missing_ordinals), bool(actual_ordinals - expected_ordinals)
if attempt_slots is not None:
# Stop-on-pass runs each attempt as its own labelled job, so a case
# with nothing scored owes every ordinal through the maximum.
# Labelled jobs with nothing scored still owe every admitted ordinal.
attempt_slots[case_id] = {
"required": required,
"missing": max(0, required - len(attempts)),
"missing_ordinals": list(range(1, required + 1)) if stop_on_pass and not attempts else None,
"missing_ordinals": sorted(expected_ordinals)
if not attempts and (stop_on_pass or (expected_attempt_ordinals_by_case or {}).get(case_id) is not None)
else None,
}
return required, len(attempts) < required, len(attempts) > required

Expand Down Expand Up @@ -7517,7 +7525,7 @@ def collect_harbor_results(
def budget_expectations(
agent: str,
arm: str,
) -> tuple[int | None, list[str] | None, int | None, dict[str, int] | None, bool]:
) -> tuple[int | None, list[str] | None, int | None, dict[str, int] | None, dict[str, set[int]] | None, bool]:
matching = [
item
for item in budget_not_run
Expand All @@ -7526,12 +7534,15 @@ def budget_expectations(
and item.get("reason") in {None, "budget_exhausted"}
]
if not matching:
return expected_trials, expected_case_ids, expected_cases, None, False
return expected_trials, expected_case_ids, expected_cases, None, None, False
attempts_by_case: dict[str, int] = {}
omitted_ordinals: dict[str, set[int]] = {}
for item in matching:
selector = str(item.get("case_id") or "")
case_id = (case_id_by_task_selector or {}).get(selector, selector)
attempts_by_case[case_id] = attempts_by_case.get(case_id, 0) + 1
if type(attempt := item.get("attempt")) is int and 1 <= attempt <= n_attempts:
omitted_ordinals.setdefault(case_id, set()).add(attempt)
active_ids = [case_id for case_id in (expected_case_ids or []) if attempts_by_case.get(case_id, 0) < n_attempts]
if expected_case_ids:
active_case_ids: list[str] | None = active_ids
Expand All @@ -7544,6 +7555,11 @@ def budget_expectations(
attempt_counts = {
case_id: max(0, n_attempts - count) for case_id, count in attempts_by_case.items() if count < n_attempts
}
attempt_ordinals = {
case_id: set(range(1, n_attempts + 1)) - omitted_ordinals[case_id]
for case_id, count in attempts_by_case.items()
if case_id in attempt_counts and len(omitted_ordinals.get(case_id, set())) == count
}
actual_trials = None if expected_trials is None else max(0, expected_trials - len(matching))
denied_slots = {
(
Expand All @@ -7566,7 +7582,7 @@ def budget_expectations(
budget_denied = expected_cases > 0 and len(denied_cases) == expected_cases
else:
budget_denied = bool(expected_trials and len(denied_cases) * n_attempts == expected_trials)
return actual_trials, active_case_ids, active_cases, attempt_counts, budget_denied
return actual_trials, active_case_ids, active_cases, attempt_counts, attempt_ordinals, budget_denied

# Unscored conditions keep the requested grading policy instead of
# falling back to the default metric set, which custom_only never grades.
Expand Down Expand Up @@ -7607,13 +7623,15 @@ def budget_expectations(
with_expected_case_ids,
with_expected_cases,
with_expected_attempts,
with_expected_ordinals,
with_budget_denied,
) = budget_expectations(agent, "with")
(
without_expected_trials,
without_expected_case_ids,
without_expected_cases,
without_expected_attempts,
without_expected_ordinals,
without_budget_denied,
) = budget_expectations(agent, "without")
if skip_baseline:
Expand Down Expand Up @@ -7724,6 +7742,7 @@ def budget_expectations(
stop_on_pass=stop_on_pass,
pass_threshold=pass_threshold,
expected_attempts_by_case=with_expected_attempts,
expected_attempt_ordinals_by_case=with_expected_ordinals,
)
if with_policy == "mixed-score-policies":
_fail_execution_with_error(with_execution, "Conflicting score policies within the with-skill condition")
Expand Down Expand Up @@ -7974,6 +7993,7 @@ def budget_expectations(
pass_threshold=pass_threshold,
attempt_slots=without_slots if tolerance_on else None,
expected_attempts_by_case=without_expected_attempts,
expected_attempt_ordinals_by_case=without_expected_ordinals,
)
if without_policy == "mixed-score-policies":
_fail_execution_with_error(
Expand Down Expand Up @@ -8081,6 +8101,7 @@ def budget_expectations(
stop_on_pass=stop_on_pass,
pass_threshold=pass_threshold,
expected_attempts_by_case=without_expected_attempts,
expected_attempt_ordinals_by_case=without_expected_ordinals,
)
if without_budget_denied:
without_execution["skip_reason"] = "budget_exhausted"
Expand Down Expand Up @@ -8417,6 +8438,7 @@ def budget_expectations(
stop_on_pass=stop_on_pass,
pass_threshold=pass_threshold,
expected_attempts_by_case=without_expected_attempts,
expected_attempt_ordinals_by_case=without_expected_ordinals,
)
tolerance_failures, tolerance_code = _baseline_timeout_failures(
job_dir=without_job_dir,
Expand Down
49 changes: 49 additions & 0 deletions tests/tier3/test_budget_admitted_ordinals.py
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import pytest
from tests.tier3.test_baseline_timeouts import _attempt_job

from skillevaluator.tier3.harbor.collector import collect_harbor_results
from skillevaluator.tier3.harbor.runner import _merge_attempt_jobs


@pytest.mark.parametrize("ordinals", [(1, 3), (1,), (3,), (), (1, 2), (1, 2, 3)])
@pytest.mark.parametrize("reason", ["budget_exhausted", None, "execution_failed"])
@pytest.mark.parametrize("stop_on_pass", [False, True])
def test_coverage_uses_admitted_slots(tmp_path, ordinals, reason, stop_on_pass):
not_run = []
for arm in ("with", "without"):
jobs = [
_attempt_job(tmp_path, "agent", arm, "selector", ordinal, "pass" if ordinal == 3 else "fail")
for ordinal in ordinals
]
_merge_attempt_jobs(jobs, tmp_path / "jobs" / f"demo-agent-{arm}")
row = {"agent": "agent", "arm": arm, "case_id": "selector", "attempt": 2, "status": "not_run"}
if reason is not None:
row["reason"] = reason
not_run.append(row)

result = collect_harbor_results(
skill_name="demo",
agents=["agent"],
output_dir=tmp_path / "results",
jobs_dir=tmp_path / "jobs",
n_attempts=3,
expected_trials=None if stop_on_pass else 3,
expected_case_ids=["case"],
expected_cases=1,
case_id_by_task_selector={"selector": "case"},
budget_not_run=not_run,
stop_on_pass=stop_on_pass,
)
omitted = reason != "execution_failed"
complete = ordinals == ((1, 3) if omitted else (1, 2, 3))
assert result["execution_status"] == ("succeeded" if complete else "failed")
for condition in result["agents"]["agent"]["conditions"].values():
assert condition["expected_attempts"] == (2 if omitted else 3)
if complete:
assert condition["scored_attempts"] == condition["expected_attempts"]
assert not condition["execution_errors"]
else:
assert any("scored attempts" in error for error in condition["execution_errors"])
Loading