Skip to content

refactor(trajectory-replay): share metrics and suite code between tracks - #200

Merged
lanyue-llk merged 4 commits into
mainfrom
refactor/trajectory-replay-shared-core
Nov 3, 2026
Merged

lanyue-llk merged 4 commits into
mainfrom
refactor/trajectory-replay-shared-core

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #194

Summary

The curated and public replay tracks each kept a copy of their metrics and suite code. That code now lives once in src/harness/trajectory_replay/core/, and each track adds only its own behaviour on top.

  • core/metrics.py owns the aggregation. Each track passes a ResultPolicy that says how its physical attempts become logical results.
  • core/suite.py owns BrowserTask, TaskSuite, validate_ground_truth_evidence and the common validation rules. Importers of those names now use this module directly, and neither the track suite.py modules nor the track packages re-export them. The unused complexity_tier helper is removed from both tracks.
  • public_webarena/metrics.py no longer re-exports harness.resource_accounting. Its test imports those names from the owner, and the F401/I001 ignore for the file is gone from pyproject.toml.

No result, denominator or report target changes, and neither track is retired. The curated report.py decision stays in #103.

What the audit got wrong

#103 lists metrics as shared in full, but the same definitions behave differently. These differences are track contracts, so I kept them instead of merging them:

Behaviour Curated Public WebArena
Task passes when any attempt passes the final attempt passes
Conditional latency and tokens first attempts that pass final attempts that pass
Resource comparison rows first attempts final attempts
Duration duration_ms execution_duration_ms, falling back to duration_ms
Ratios one engine pair also every engine against the baseline
Extra attempt fields none execution duration and evidence fields
Suite schemas /3 /3 and /4
Actions 12 those 12 plus 10 more

validate_selector and the track-specific step rules also differ, so they stay in each track's suite.py.

Frozen bindings

Neither metrics.py nor suite.py in these tracks is recorded by a frozen binding, so no file had to be left alone. I searched the repository for both paths. remote_execution.py hashes its own runtime sources, but that list names neither file.

Test plan

  • Lint: both gates pass.
  • tests/trajectory_replay and tests/test_golden_reports.py: 2196 passed, 5 skipped on the current head. Route-hash snapshots are unchanged.
  • New tests/trajectory_replay/test_shared_core.py: covers the shared task rules and shows the tracks still diverge where their contracts do. This includes a retry that passes after a failure: curated counts the task as passed with no conditional latency sample, public takes the retry's latency. Accepting every passing attempt in curated successful_rows makes this test fail.
  • Comparison against the base commit (one-off script, not committed, run before the review fixes): I ran the old modules from f3201951 against the new ones on randomized inputs, comparing serialized output including key order, or the exact exception type and message.
    • summarize_attempts: 6,600 comparisons, all identical.
    • load_suite: 24,000 comparisons, all identical (7,518 loaded, 16,482 rejected, covering 116 distinct error messages).
  • Rest of tests/ on macOS: 17576 passed, 65 failed, 55 skipped.
    • Some failures are on the known local failure list.
    • The others are outside the replay code. The three I re-ran all failed on the web fetch dataset lock ("not recorded in the dataset lock" or "not recorded in data-lock.json"). I did not check the remaining failures one by one or run them on the base commit.
    • CI on Linux is the gate for these.

Move the code both tracks copied into trajectory_replay/core. Each track keeps its own result policy, schema and action vocabulary on top, so no result, denominator or report target changes.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 57be03a

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 1

Reviewed head 57be03a8 against f3201951, which is the current main.

Result: no correctness defects. Three findings: one P2 and two P3. None of them changes a result, denominator or report target.

Findings

P2: tests/trajectory_replay/test_shared_core.py:50: curated conditional latency has no test for a pass on retry

  • Problem: The PR table lists "Conditional latency and tokens: first attempts that pass" as a curated contract, and the new file says it shows the tracks still diverge. No test pins this for curated. I changed curated successful_rows (src/harness/trajectory_replay/metrics.py) to accept every passing attempt, and all of tests/trajectory_replay plus tests/test_golden_reports.py gave the same result as the unmutated copy. That is the failure path this policy split makes easy to break. The nearby test, test_summary_separates_first_pass_retry_recovery_and_final_outcome, uses the right rows but never asserts duration_ms.
  • Fix: Add the mirror of the existing retry case, an attempt that fails and then passes on retry. The current code returns these values, which I checked by running it:
    • Curated: final_passes == 1, duration_ms["n"] == 0
    • Public: final_passes == 1, duration_ms["n"] == 1, duration_ms["mean"] == 11.0 for a retry duration of 11

P3: src/harness/trajectory_replay/core/suite.py:39: complexity_tier has no callers

  • Problem: git grep finds no callers at the head or the base, in src, tests, scripts or examples. The PR merges two dead copies into a new module and lists the function as owned there.
  • Fix: Delete it and remove it from the PR summary. AGENTS.md asks to remove code that no supported entry point calls.

P3: src/harness/trajectory_replay/__init__.py:3 and src/harness/trajectory_replay/public_webarena/__init__.py:3: re-exports remain despite the summary

  • Problem: The summary says importers use the core module "with no re-exports". This PR rewrites these two lines, and both packages still re-export BrowserTask and TaskSuite from core.suite through __all__. I found no importer of those two names from either package.
  • Fix: Drop the two names from both __init__.py files, or narrow the sentence in the summary to the suite.py modules.

What I verified

  • Metrics differential: I wrote my own comparison of the f3201951 modules against the new ones. It covered 6,000 randomized inputs per track, with 0 to 4 engines, shuffled rows, retries, malformed durations and non-numeric resources. Serialized output, including key order, and exception type and message were identical in every case. About 5% to 8% of inputs raised an exception, so the error paths were exercised.
  • Suite differential: I ran 30,000 randomized suites through each track's old and new load_suite. All outcomes matched: public loaded 20,845 and curated loaded 5,859. The only difference is that curated tasks now carry evaluator, environment and trajectory, all None. Nothing in the replay source, scripts or examples uses asdict or inspects those fields on a task, so this is not observable.
  • Reading the old and new code:
    • The curated ratio path moved from .get("duration_ms") to row["duration_ms"]. The difference is unreachable, because by_engine already reads the same rows with row["duration_ms"] first.
    • With three or more engines, curated now computes ratios and discards them, with the same output.
  • Other mutations: The tests caught changes to public comparison_rows, curated comparison_rows, public successful_rows, evidence_status, network_har, relative_ratios, curated duration and the shared action-sequence check.
  • Imports and references:
    • Every harness.trajectory_replay module imports in a fresh process, so there are no import cycles.
    • Removed names such as LEGACY_SCHEMA have no remaining users, and no one imports the moved names from the old suite modules.
    • The removed resource_accounting re-export has no remaining users.
    • core/ is packaged through packages.find.
  • Frozen bindings:
    • No SHA-256 of a changed source file at the base appears anywhere in the tree.
    • remote_execution.py, which this PR edits, does hash itself into each cohort receipt. webarena_results.py does not compare that entry with the current file, and the entry appears in no tracked file, so this edit breaks no verification. Earlier PRs have also edited this file.
    • The PR's statement about metrics.py and suite.py holds.
  • Scope: Closes #194 is justified. The metrics and suite code is shared and the track differences stay on top. The executor, runner and report work remains under #103, and no track is retired.
  • Local checks: Both lint gates pass. tests/trajectory_replay and tests/test_golden_reports.py gave 2195 passed and 5 skipped, with no snapshot changes.
  • CI for this head: All checks pass, including "Tests and static checks" and "Installation and packaging". The PR is mergeable.

I did not run the rest of tests/ locally, and rely on CI for it.

@lanyue-llk

lanyue-llk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Review round 1 fixes, head b02f2b3a. No finding disputed.

  • P2, missing test for curated conditional latency (0cf0fb34): added a case where an attempt fails and the retry passes. Curated gives final_passes == 1 and duration_ms n == 0. Public gives final_passes == 1, n == 1 and mean 11.0. Changing curated successful_rows to accept every passing attempt now fails this test.
  • P3, dead complexity_tier (c1030be1): deleted the function and removed it from the PR summary.
  • P3, re-exports in the package __init__.py files (b02f2b3a): dropped BrowserTask and TaskSuite from both files. load_suite stays exported there because it is outside this finding. The PR summary now says the track packages do not re-export the task model.

Lint passes. tests/trajectory_replay and tests/test_golden_reports.py: 2196 passed, 5 skipped, with route-hash snapshots unchanged.

CI on this head: the first run of "Tests and static checks" failed with 3 failures and 15 errors, and 19708 tests passed. All 18 were the same BrowserType.launch: Timeout 180000ms exceeded while starting Chrome, on browser tests across unrelated areas including web search and report interactions. I reran the failed jobs on the same commit with no code change, and all checks then passed. This looks like a runner flake, though I did not find its cause.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Re-review complete · b02f2b3

No findings in this incremental review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 2

Reviewed head b02f2b3a against base f3201951. No defects found.

What I verified

Behaviour against the base commit. I wrote my own comparison, separate from the author's script, and loaded the old modules from f3201951 next to the new ones. It compared serialized output including key order, or the exact exception type and message.

  • summarize_attempts: 12,000 comparisons across both tracks, with 0 to 4 engines, shuffled row order, retries, and missing or non-numeric fields. There were 0 differences, and 2,090 of the inputs raised on the old code.
  • load_suite: 62,000 comparisons across both tracks and both schemas, with 0 differences. The valid-biased run of 30,000 loaded 6,071 suites and hit 257 distinct error messages. The first, more hostile run of 32,000 loaded none, so it only exercises the rejection paths.
  • Reading the code also confirmed that the action sets (12 curated, 22 public) and the saved-output action sets match the old lists. Curated now computes ratios for every engine pair and discards them unless there are exactly two engines. This costs a little time but cannot change output or raise a new error, because the by_engine step reads the same durations first.

Round 1 fixes.

  • Making curated successful_rows accept every passing attempt now fails test_tracks_keep_their_own_conditional_latency_when_a_retry_passes_after_a_failure.
  • Making public logical_passed use any attempt also fails the new and existing tests.
  • complexity_tier is gone, with no references left, and neither track package exports BrowserTask or TaskSuite.

Imports. All 1,004 names imported from harness.trajectory_replay* in tracked Python files resolve, including scripts/ and examples/. No references to the removed LEGACY_SCHEMA or DIFFICULTIES remain outside the core module.

Scope of Closes #194. Nothing shared remains copied between the two metrics.py files or the two suite.py files. What stays in each track is what the PR table lists. The curated report.py decision stays in #103, as the issue requires, and neither track is retired.

Frozen bindings.

  • No file under evaluation/, research/ or configs/, and no golden snapshot, changes in this PR.
  • No frozen binding names either metrics.py or suite.py.
  • The PR does edit an import line in remote_execution.py, which cohort_reference_hashes hashes. That hash is recorded and compared within a single cohort run, so stored certificates are not checked against the current file. Earlier PRs have changed this file too.

Tests and lint on this head (macOS).

  • Both lint gates pass.
  • tests/trajectory_replay and tests/test_golden_reports.py: 2196 passed, 5 skipped, with route hashes unchanged. This matches the PR's test plan.
  • I did not rerun the rest of tests/ locally and rely on CI for it.

CI on b02f2b3a. Python 3.11, Tests and static checks, Installation and packaging, Rendered reference and report checks, Select check scope and OCR dispatch all succeeded. The PR is mergeable and its merge state is clean.

Other. Commits and the PR body contain no attribution lines, and the added lines contain no local usernames, local paths or internal hostnames.

lanyue-llk added a commit that referenced this pull request Nov 3, 2026
@lanyue-llk
lanyue-llk merged commit 16b2d72 into main Nov 3, 2026
10 of 12 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/trajectory-replay-shared-core branch November 3, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share Trajectory Replay metrics and suite code between tracks

1 participant