Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@ All notable changes to SkillEvaluator are documented in this file.
case names receive the same Markdown escaping, publication-label masking and
terminal secret redaction as visible rows, before their displayed length is
bounded.
- Tier 3 token usage per case, per agent and over all agents now counts each
attempt in the case it belongs to. An unscored attempt of a native task whose
`[metadata] entry_id` differs from its directory joins that case's row
instead of a row of its own; the collector records the case in the attempt's
`failure.json`. A scored attempt whose trajectory recorded an invalid cache
counter is no longer counted with 0 cached tokens: it adds no tokens, and
the trial names the counter in `invalid_token_counters`. A case that a run
budget cut short expects only the attempts the budget admitted, so its row
is no longer partial with missing attempts. `tier3 evaluate` prints the
agent token sums for a run whose arms all failed, and once the report
payload left the case rows out, the terminal tables say that no report has
them instead of naming the report files. `tier3 evaluate` names only the
reports the run wrote, so a NeMo Gym run no longer points at a
`tier3-benchmark.md` it never writes.
- The Tier 3 security scan no longer scores an agent clearing its own output
directory as a destructive command. One literal, recursive and forced `rm` of
a path inside `/workspace/output` or an output directory established by the
Expand Down
41 changes: 26 additions & 15 deletions docs/reports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1103,22 +1103,29 @@ or gate.
- Attempts that failed before scoring, such as an attempt that hit the agent
timeout, still used tokens and are counted. So are the scored attempts of an
arm that failed. `coverage.unscored_attempts` counts the attempts without a
score. Such an attempt belongs to the case whose task directory its Harbor
`result.json` or `config.json` names, or else to the case its trial name
starts with. `resources` keeps its own totals, which need every attempt of an
arm scored and measured.
score. Such an attempt belongs to the case that its `failure.json` names in
`entry_id`, which the collector records from the task the attempt ran with
either backend, so a native task whose `[metadata] entry_id` differs from
its directory keeps its case. A run without that record gives the case whose
task directory its Harbor `result.json` or `config.json` names, or else the
case its trial name starts with. `resources` keeps its own totals, which
need every attempt of an arm scored and measured.
- Nothing is estimated. An attempt with a missing or invalid counter adds no
tokens. Its arm's `coverage.status` is then `partial` (other attempts were
measured) or `unavailable` (none were), and the totals cover only the measured
attempts. An arm that did not run is `not_run`, and its `totals` are `null`:
a skipped arm, or an arm without attempts that the agent has no record of or
that the payload `mode` leaves out (`with_skill_only` or `baseline_only`).
The score tables show such a baseline as not run. A sum above
9,007,199,254,740,991 (`2^53 - 1`), the largest integer JSON keeps exact, is
`unavailable` with `total_out_of_range` and `null` totals.
tokens. A report trial whose trajectory recorded an invalid counter names
it, never its value, in `invalid_token_counters`, and its `tokens` leave
that counter out. Its arm's `coverage.status` is then `partial` (other
attempts were measured) or `unavailable` (none were), and the totals cover
only the measured attempts. An arm that did not run is `not_run`, and its
`totals` are `null`: a skipped arm, or an arm without attempts that the agent
has no record of or that the payload `mode` leaves out (`with_skill_only` or
`baseline_only`). The score tables show such a baseline as not run. A sum
above 9,007,199,254,740,991 (`2^53 - 1`), the largest integer JSON keeps
exact, is `unavailable` with `total_out_of_range` and `null` totals.
- `coverage` also gives `expected_attempts`, `observed_attempts`,
`measured_attempts`, and `reason_codes` such as `missing_token_counters`,
`invalid_token_counters`, and `missing_attempts`.
`invalid_token_counters`, and `missing_attempts`. A case expects the
attempts its pass@k record planned: attempts skipped after a pass and
attempts a run budget did not admit are not expected.
- `delta.total_tokens` is with skill minus baseline, and
`delta.total_tokens_change_percent` divides it by the baseline. A change needs
complete counts in both arms for the same cases and attempts, and both arms
Expand Down Expand Up @@ -1173,8 +1180,12 @@ its bounded preview. Each table says how many more case rows are in the JSON
payload. The full terminal report (`validate --verbose` or `-r cli`) and
`tier3 evaluate --verbose` print the agent rows only and name the files that
hold the case rows: the HTML, Markdown and JSON reports for `validate`, and
`report.html` and `tier3-benchmark.md` in the run directory for
`tier3 evaluate`.
for `tier3 evaluate` the reports the run wrote in its run directory:
`report.html` and `tier3-benchmark.md` for a Harbor run, `report.html` alone
for a NeMo Gym run, and none when the report step failed. When the payload
left the case rows out, they say instead that no report has them.
`tier3 evaluate` also prints the agent rows for a run whose arms all failed,
after the panel that says the evaluation did not complete.

### Failure reasons and per-trial rows

Expand Down
5 changes: 4 additions & 1 deletion src/skillevaluator/evaluation/tier3_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3474,7 +3474,7 @@ def _normalize_trials(
metric_value,
overall_score,
)
from skillevaluator.tier3.harbor.report_data import logical_trial_reward_groups
from skillevaluator.tier3.harbor.report_data import _token_counter_names, logical_trial_reward_groups
from skillevaluator.tier3.harbor.resource_usage import normalized_trial_timing

out: list[dict[str, Any]] = []
Expand Down Expand Up @@ -3541,6 +3541,9 @@ def _normalize_trials(
}
if cached_tokens is not None:
trial["tokens"]["cached"] = cached_tokens
if invalid_counters := _token_counter_names(reward.get("_invalid_token_counters")):
# Names only: token usage counts the attempt as unmeasured, not as a zero cache.
trial["invalid_token_counters"] = invalid_counters
timing = normalized_trial_timing(traj.get("timing"))
if timing is not None:
trial["timing"] = timing
Expand Down
28 changes: 23 additions & 5 deletions src/skillevaluator/reporting/tier3_token_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
)
#: Where ``validate``'s terminal report, which prints agent rows only, sends readers for case rows.
VALIDATE_CASE_POINTER = "Token usage per case is in the HTML, Markdown and JSON reports (-r html, markdown or json)."
#: Where ``tier3 evaluate``'s terminal summary sends readers for case rows.
#: Where ``tier3 evaluate``'s terminal summary sends readers for case rows when the run wrote both reports.
EVALUATE_CASE_POINTER = "Token usage per case is in report.html and tier3-benchmark.md in the run directory."
#: The same pointer for a run that wrote ``report.html`` only, such as a NeMo Gym run.
EVALUATE_REPORT_CASE_POINTER = "Token usage per case is in report.html in the run directory."
#: Case rows per agent in the HTML table; the JSON payload keeps the rest.
HTML_CASE_ROWS_PER_AGENT = 64
#: Marks a case row whose ID is not one of the evaluation dataset's case IDs.
Expand Down Expand Up @@ -194,6 +196,21 @@ def dropped_case_rows_note(usage: object) -> str | None:
)


def dropped_case_rows_pointer(usage: object) -> str | None:
"""For a terminal summary: say that no report has the case rows the payload dropped, if it dropped any.

The payload that every report reads drops the case rows of every agent, so
a pointer to the reports would send readers to rows that are not there.
"""
count = _count(_mapping(usage).get("case_rows_omitted"))
if not count:
return None
return (
f"{count:,} case row(s) were left out of every report to keep the reports within their size limits, "
"so no report has token usage per case; the agent sums cover every attempt."
)


def token_usage_rows(
usage: object,
*,
Expand Down Expand Up @@ -291,8 +308,10 @@ def render_token_usage_table(
"""Print one row per agent and the all-agent row, then the notes; return whether anything printed.

``case_pointer`` names the files of the calling command that hold the
case rows. ``text`` makes agent names and notes safe for the console, for
example by redacting secrets. Cells are plain text, never console markup.
case rows, and is empty when the command wrote none; when the payload left
the case rows out, the table says that no report has them instead. ``text`` makes agent names and notes safe for the
console, for example by redacting secrets. Cells are plain text, never
console markup.
"""
rows, _omitted = token_usage_rows(usage, include_cases=False)
if not rows:
Expand All @@ -319,8 +338,7 @@ def render_token_usage_table(
pointer = " ".join(
part
for part in (
case_pointer,
dropped_case_rows_note(usage),
dropped_case_rows_pointer(usage) or case_pointer,
unverified_case_ids_note(usage, rows, case_label=text),
)
if part
Expand Down
68 changes: 68 additions & 0 deletions src/skillevaluator/tier3/harbor/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,40 @@ def _looks_like_trial_dir(path: Path) -> bool:
return any((path / name).exists() for name in TRIAL_DIAGNOSTIC_ARTIFACTS) or (path / "agent").exists()


def _unscored_trial_case_id(
trial_src: Path,
case_id_by_task_selector: dict[str, str] | None,
*,
arm_suffix: str = "",
task_entry_id_map: Mapping[str, str] | None = None,
) -> str:
"""Return the case of a Harbor trial without a scored reward, from the task it ran.

The task comes from the trial's ``result.json``, or from its ``config.json``
when the trial stopped before Harbor wrote a result. Without the trusted
selector mapping, the case counts only when it is authoritative: the
``[metadata] entry_id`` of the task path or of the arm's staged task, as
for a scored trial. Otherwise the reader keeps its own fallback.
"""
for name in ("result.json", "config.json"):
data = _read_json(trial_src / name)
if not isinstance(data, dict):
continue
result = data if name == "result.json" else {"config": data}
if case_id_by_task_selector is not None:
case_id = _entry_id_from_harbor_result(result, case_id_by_task_selector)
else:
case_id, is_authoritative = _resolve_harbor_result_entry_id(
result,
arm_suffix=arm_suffix,
task_entry_id_map=task_entry_id_map,
)
case_id = case_id if is_authoritative else ""
if case_id:
return case_id
return ""


def _save_unscored_trials(
rewards: list[dict[str, Any]],
trials_dir: Path,
Expand All @@ -1492,7 +1526,19 @@ def _save_unscored_trials(
agent_model: str | None = None,
agent_model_source: str | None = None,
persisted_names: dict[str, str] | None = None,
case_id_by_task_selector: dict[str, str] | None = None,
arm_suffix: str = "",
task_entry_id_map: Mapping[str, str] | None = None,
) -> None:
"""Persist each Harbor trial without a scored reward with a ``failure.json`` record.

The record names the attempt's case in ``entry_id``, from the trusted
``case_id_by_task_selector`` mapping, or without it from the arm's
``arm_suffix`` and staged ``task_entry_id_map`` when they resolve the case
as for a scored trial. Harbor names a trial after its task directory,
which for a native task with its own ``[metadata] entry_id`` is not the
case ID, so readers cannot derive the case from the name.
"""
if job_dir is None or not job_dir.exists():
return
agent = _bounded_reward_metadata_text(agent) or "unknown"
Expand Down Expand Up @@ -1578,6 +1624,13 @@ def _save_unscored_trials(
if agent_model:
error_summary.pop("model", None)
failure.update(error_summary)
if case_id := _unscored_trial_case_id(
trial_src,
case_id_by_task_selector,
arm_suffix=arm_suffix,
task_entry_id_map=task_entry_id_map,
):
failure["entry_id"] = case_id
failure_file = trial_out / "failure.json"
try:
_write_bounded_failure_artifact(failure_file, failure)
Expand Down Expand Up @@ -6376,6 +6429,9 @@ def _save_trials(
agent_model: str | None = None,
agent_model_source: str | None = None,
expected_case_ids: list[str] | set[str] | None = None,
case_id_by_task_selector: dict[str, str] | None = None,
arm_suffix: str = "",
task_entry_id_map: Mapping[str, str] | None = None,
) -> None:
"""Save per-trial reward.json and trajectory.json into the results directory."""
agent = _bounded_reward_metadata_text(agent) or "unknown"
Expand Down Expand Up @@ -6499,6 +6555,9 @@ def _save_trials(
agent_model=agent_model,
agent_model_source=agent_model_source,
persisted_names=unscored_names,
case_id_by_task_selector=case_id_by_task_selector,
arm_suffix=arm_suffix,
task_entry_id_map=task_entry_id_map,
)


Expand Down Expand Up @@ -7660,6 +7719,9 @@ def budget_expectations(
agent_model=agent_model,
agent_model_source=agent_model_source,
expected_case_ids=expected_case_ids,
case_id_by_task_selector=case_id_by_task_selector,
arm_suffix=with_arm_suffix,
task_entry_id_map=with_task_entry_ids,
)
with_summary = {
"agent": agent,
Expand Down Expand Up @@ -7918,6 +7980,9 @@ def budget_expectations(
agent_model=agent_model,
agent_model_source=agent_model_source,
expected_case_ids=expected_case_ids,
case_id_by_task_selector=case_id_by_task_selector,
arm_suffix=without_arm_suffix,
task_entry_id_map=without_task_entry_ids,
)
without_summary = {
"reused": reused_baseline_dir is not None,
Expand Down Expand Up @@ -8162,6 +8227,9 @@ def budget_expectations(
agent_model=agent_model,
agent_model_source=agent_model_source,
expected_case_ids=expected_case_ids,
case_id_by_task_selector=case_id_by_task_selector,
arm_suffix=with_arm_suffix,
task_entry_id_map=with_task_entry_ids,
)

agent_execution = _aggregate_execution([with_execution, without_execution])
Expand Down
Loading
Loading