Repository navigation
refactor(trajectory-replay): share metrics and suite code between tracks - #200
Conversation
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.
lanyue-llk
left a comment
There was a problem hiding this comment.
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 oftests/trajectory_replayplustests/test_golden_reports.pygave 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 assertsduration_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.0for a retry duration of 11
- Curated:
P3: src/harness/trajectory_replay/core/suite.py:39: complexity_tier has no callers
- Problem:
git grepfinds no callers at the head or the base, insrc,tests,scriptsorexamples. 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
BrowserTaskandTaskSuitefromcore.suitethrough__all__. I found no importer of those two names from either package. - Fix: Drop the two names from both
__init__.pyfiles, or narrow the sentence in the summary to thesuite.pymodules.
What I verified
- Metrics differential: I wrote my own comparison of the
f3201951modules 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 carryevaluator,environmentandtrajectory, allNone. Nothing in the replay source,scriptsorexamplesusesasdictor 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")torow["duration_ms"]. The difference is unreachable, becauseby_enginealready reads the same rows withrow["duration_ms"]first. - With three or more engines, curated now computes ratios and discards them, with the same output.
- The curated ratio path moved from
- Other mutations: The tests caught changes to public
comparison_rows, curatedcomparison_rows, publicsuccessful_rows,evidence_status,network_har,relative_ratios, curateddurationand the shared action-sequence check. - Imports and references:
- Every
harness.trajectory_replaymodule imports in a fresh process, so there are no import cycles. - Removed names such as
LEGACY_SCHEMAhave no remaining users, and no one imports the moved names from the oldsuitemodules. - The removed
resource_accountingre-export has no remaining users. core/is packaged throughpackages.find.
- Every
- 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.pydoes 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.pyandsuite.pyholds.
- Scope:
Closes #194is 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_replayandtests/test_golden_reports.pygave 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.
|
Review round 1 fixes, head
Lint passes. 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 |
There was a problem hiding this comment.
✅ Re-review complete · b02f2b3
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
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_enginestep reads the same durations first.
Round 1 fixes.
- Making curated
successful_rowsaccept every passing attempt now failstest_tracks_keep_their_own_conditional_latency_when_a_retry_passes_after_a_failure. - Making public
logical_passeduse any attempt also fails the new and existing tests. complexity_tieris gone, with no references left, and neither track package exportsBrowserTaskorTaskSuite.
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/orconfigs/, and no golden snapshot, changes in this PR. - No frozen binding names either
metrics.pyorsuite.py. - The PR does edit an import line in
remote_execution.py, whichcohort_reference_hasheshashes. 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_replayandtests/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.
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.pyowns the aggregation. Each track passes aResultPolicythat says how its physical attempts become logical results.core/suite.pyownsBrowserTask,TaskSuite,validate_ground_truth_evidenceand the common validation rules. Importers of those names now use this module directly, and neither the tracksuite.pymodules nor the track packages re-export them. The unusedcomplexity_tierhelper is removed from both tracks.public_webarena/metrics.pyno longer re-exportsharness.resource_accounting. Its test imports those names from the owner, and theF401/I001ignore for the file is gone frompyproject.toml.No result, denominator or report target changes, and neither track is retired. The curated
report.pydecision 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:
duration_msexecution_duration_ms, falling back toduration_ms/3/3and/4validate_selectorand the track-specific step rules also differ, so they stay in each track'ssuite.py.Frozen bindings
Neither
metrics.pynorsuite.pyin 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.pyhashes its own runtime sources, but that list names neither file.Test plan
tests/trajectory_replayandtests/test_golden_reports.py: 2196 passed, 5 skipped on the current head. Route-hash snapshots are unchanged.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 curatedsuccessful_rowsmakes this test fail.f3201951against 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).tests/on macOS: 17576 passed, 65 failed, 55 skipped.