Skip to content

refactor(replay): move identical report and diagnostics definitions into core - #235

Merged
lanyue-llk merged 3 commits into
mainfrom
refactor/replay-remove-duplicates
Nov 4, 2026
Merged

lanyue-llk merged 3 commits into
mainfrom
refactor/replay-remove-duplicates

Conversation

@lanyue-llk

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

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #103

Summary

An AST and source-text comparison of the curated and public replay modules found 24 definitions with identical code. 22 of them behave the same in both tracks and now live in one place. The curated track stays, per the owner default.

  • trajectory_replay/core/report.py holds 16 report definitions (_e, _trace_text, _show, _stat, ComparedValue, _source_references and others). _rate had no caller in either track, so it was deleted instead of moved.
  • trajectory_replay/core/diagnostics.py holds 6 diagnostics definitions (classify_failure, build_failure_groups, add_llm_diagnoses, diagnose_summary and their helpers). Callers import from core directly; there are no re-exports.
  • _nav and _detail_filename stay in each track. Their code is identical, but they read that track's own PAGES and REPORT_STEM, so they are not real duplicates.
  • Moved names keep their spelling, including the leading underscore, so the report modules' call sites stay unchanged.
  • tests/trajectory_replay/public_webarena/test_diagnostics.py is deleted. It was a copy of the curated test file, and both now test one implementation.

Dead code removed in the same change:

  • _article_body's paired and cohort_commits in browser_use/report.py, with _cohort_commits and its plumbing.
  • The unused source parameter of resource_result in core/docker_runner.py.
  • load_macos_resources in lexbench/report.py is now two conditional calls, macOS first.

No hash binding names the changed files. A repository search for their paths finds only ruff per-file ignores, configs/report-templates.json renderer paths, a README and a test constant, and none of those carries a hash. The file_sha256(Path(__file__)) bindings do not cover these modules.

Remaining definitions shared by the two tracks differ in code, so this PR does not change them. resource_summary in environments/webarena/runtime.py has the same kind of dead first parameter; it was outside this item and is unchanged.

Test plan

  • ruff check with the F,TID252 gate and the default config: both pass.
  • tests/test_golden_reports.py: 17 passed with no snapshot regenerated, so rendered curated, public and Browser Use routes are unchanged.
  • tests/trajectory_replay, tests/browser_use, tests/test_resource_accounting.py, the Lexbench report, CLI and verification tests, and tests/test_shared_hash_json_helpers.py, run with the golden tests: 2790 passed, 5 skipped.
  • The full suite was not run locally; CI is the full-suite gate.
  • Re-ran the AST comparison across report, diagnostics, runner, metrics, executor, suite and cli: only _nav and _detail_filename remain identical.

@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 · b05ab7f

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 b05ab7fb. One P2 finding; no P0 or P1.

Findings

P2: src/harness/trajectory_replay/diagnostics.py:1 and src/harness/trajectory_replay/public_webarena/diagnostics.py:1: stale module docstrings.
Both modules still open with "Rule-based and optional LLM-assisted failure diagnosis." This PR moved all of that code to core/diagnostics.py, so neither module holds rule-based or LLM failure diagnosis now. The curated module holds input and readiness audits, saved-correction audits and the saved-retrieval rescore. The public module holds the Codex repair packet and repair jobs, recorded-outcome audits and the runtime smoke entry point. A reader looking for classify_failure or diagnose_summary is sent to the wrong file.
Fix: change the first line of each docstring to what the module now holds, for example "Read-only audits of curated replay inputs and saved evidence." and "Public WebArena repair-packet, recorded-outcome and runtime-smoke diagnostics." Check the second docstring sentence at the same time, because it describes the code that moved.

What I verified

  • AST comparison, base 35bed218 against head. At base there were 18 identical definitions in report.py and 6 in diagnostics.py. At head only _nav and _detail_filename remain identical, and they read each track's own PAGES and REPORT_STEM. The other replay modules (runner, metrics, executor, suite, cli) have no identical definitions apart from the __all__ in __init__.py.
  • Byte-level moves. The source of all 6 diagnostics functions and the 13 report functions and classes I compared is unchanged from base. SUITE_FILTER_JS and EVIDENCE_DIALOG_JS load the same asset files, because core/report.py resolves ASSETS to trajectory_replay/assets.
  • Stale references. No attribute access, getattr or import reaches the old location of a moved diagnostics name. Report names still imported through the track modules (_annotate_source_marks in tests, SUITE_FILTER_JS in tests/package_smoke.py) resolve because those modules really use them.
  • Deleted test. tests/trajectory_replay/public_webarena/test_diagnostics.py differed from the curated file only in its imports and in lacking the credentials test, so no coverage is lost.
  • Dead code.
    • _rate has no caller.
    • paired and cohort_commits are gone from _article_body, and _cohort_commits is removed. paired_by_model and bundles still have other users.
    • resource_result has both callers updated.
    • load_macos_resources keeps the macOS-first order and the None results.
  • Hash bindings. No hash binding names the changed files. The repository references are ruff per-file ignores, a configs/report-templates.json renderer path, a README and a test constant. The Path(__file__) hash sites in trajectory_replay, browser_use, lexbench and reporting do not cover the changed modules.
  • Scope. The curated track stays, as the owner default says. catalog_runner.py no longer imports private public-track helpers. I found no missing part of the assigned scope for Closes #103.
  • Over-design. No new abstraction beyond the two core modules the item asks for.
  • Golden snapshots. No snapshot file is changed.

Local runs and CI

  • Both ruff gates pass.
  • tests/test_golden_reports.py, tests/trajectory_replay and tests/test_resource_accounting.py: 2296 passed, 5 skipped.
  • CI at this head: Tests and static checks, Installation and packaging, Rendered reference and report checks, and Python 3.11 all pass.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1:

Fixed: the module docstrings of trajectory_replay/diagnostics.py and public_webarena/diagnostics.py now describe what each file holds after the move to core/diagnostics.py, including the second sentence (b309953). Comments only; route-hash snapshots are unchanged.

Disputed: nothing.

@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 · b309953

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 b3099535. No P0, P1 or P2 defects. One P3 nit, which does not block merge.

Finding

P3: tests/trajectory_replay/public_webarena/test_report.py:115. test_source_permalink_character_is_annotated_not_removed is byte-identical to the test at tests/trajectory_replay/test_report.py:38. Since _annotate_source_marks moved to core/report.py, both copies test one function, and both reach it through a track module's import. The PR deleted public_webarena/test_diagnostics.py for this same reason.
Suggested fix: delete the public copy and its import, and import _annotate_source_marks from harness.trajectory_replay.core.report in the curated test.

What I verified

  • Moved code: my own AST and source-segment comparison against 35bed218 covered report, diagnostics, runner, metrics, executor, suite and cli. The 15 moved report definitions and 6 diagnostics definitions match the old curated and public text exactly, and ASSETS in core matches the public line.
  • Remaining copies: only _nav and _detail_filename are still identical. Leaving them is sound because PAGES and REPORT_STEM differ per track at runtime. _rate had no caller.
  • Rest of the track modules: no other definition changed, apart from the resource_result(...) call in each _run_task.
  • Test deletion: public_webarena/test_diagnostics.py differed from the curated file only in its imports, and the curated file is a superset. The credential test that ran against both modules now runs against core once.
  • Patch targets: monkeypatch targets moved to core.diagnostics, so they still intercept the real calls.
  • Dead parameters: paired, cohort_commits, _cohort_commits and the source parameter of resource_result are gone along with all their plumbing. paired_by_model is still used by its other consumer. load_macos_resources keeps macOS first, and each call still runs only when its path is set.
  • Hash bindings: no file under evaluation/ or research/ names the changed modules. The non-source references are ruff per-file ignores and configs/report-templates.json, and neither carries a hash. Neither evaluation/ nor research/ changed, and neither did configs/ or any golden snapshot.
  • Rule compliance: there are no compatibility aliases. Track modules import the moved names only because they use them.
  • Docstrings: the round 1 fix is correct, and both module docstrings now describe what the modules hold.
  • Issue scope: Closes #103 fits the scope given for this PR. The curated track stays under the owner default.

Results

  • Lint: the F,TID252 gate and default ruff check both pass.
  • Local tests: tests/test_golden_reports.py, tests/trajectory_replay, tests/browser_use and tests/test_resource_accounting.py gave 2631 passed, 5 skipped. A second run of tests/test_shared_hash_json_helpers.py with the Lexbench-named test files gave 214 passed. No snapshot was regenerated.
  • CI on b3099535: all checks pass, including "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks". The packaging job includes the installed-package smoke test.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 2: fixed the one finding, nothing disputed.

  • P3, duplicate source-mark test: fixed in fdbce89. Deleted the copy in tests/trajectory_replay/public_webarena/test_report.py. The test in tests/trajectory_replay/test_report.py now imports _annotate_source_marks from harness.trajectory_replay.core.report.

Local runs: ruff gates pass; tests/trajectory_replay/test_report.py, tests/trajectory_replay/public_webarena/test_report.py and tests/test_golden_reports.py give 52 passed, with golden snapshots unchanged.

@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 skipped · fdbce89

No reviewable content was selected for this run.

@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 3

Head reviewed: fdbce89, based on current main 35bed21.

No defects were found: no P0, P1, P2 or P3 findings.

What I verified

  • Duplicate inventory. My own AST comparison of the base commit found 24 definitions identical between the curated and public report and diagnostics modules: 18 in report, 6 in diagnostics. At head, only _nav and _detail_filename remain. They read each track's own PAGES and REPORT_STEM, so keeping them is correct. A scan of every top-level function and class under trajectory_replay/ found no other curated/public duplicate.
  • Moved code. All 15 moved report definitions and all 6 diagnostics definitions have the same AST as both base copies. No definition kept in a track module changed. _rate had no caller. core/report.py resolves ASSETS to the same trajectory_replay/assets directory, which holds both shared JS files.
  • No re-exports. Callers import moved names from core. Track modules import only the names they use, and no test or script reaches a moved name through a track module.
  • Deleted test. public_webarena/test_diagnostics.py at base held only tests also present in the curated file, with no public-specific case.
  • Dead code.
    • paired, cohort_commits and _cohort_commits are gone. paired_by_model and bundles remain live through other readers. _cohort_commits did no validation, and _load_evidence_bundles always sets the keys it read.
    • Every resource_result caller is updated, and both runners still use resources for counters and the sampler.
    • load_macos_resources keeps the same arguments and the macOS-first order.
  • Hash bindings. No committed path or hash binding names the changed modules. pyproject.toml and configs/report-templates.json hold paths only, and the Path(__file__) hash sites do not cover these files.
  • Import boundary. Importing core.diagnostics and the curated audit module loads neither playwright nor webarena_verified.
  • Scope. The items in #103 as scoped for this PR are done, and the curated track is kept per the owner default. The resource_summary dead parameter is left alone and disclosed in the PR body. Closes #103 is accurate for that scope.
  • Earlier rounds. The round 1 docstring fix and the round 2 duplicate-test fix are both in place.

Local runs

  • Both ruff gates passed.
  • tests/test_golden_reports.py, tests/trajectory_replay and tests/test_resource_accounting.py: 2295 passed, 5 skipped, with no snapshot changed.
  • tests/browser_use/test_report_check.py, the Lexbench report runtime and verification tests, and tests/test_shared_hash_json_helpers.py: 175 passed.

CI on fdbce89

All checks pass, including "Tests and static checks", "Installation and packaging", and "Rendered reference and report checks". The PR is mergeable on current main.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
lanyue-llk added a commit that referenced this pull request Nov 4, 2026
…nto core

Move the definitions that are byte-identical between the curated and public
replay modules into trajectory_replay/core/{report,diagnostics}.py and delete
the copies, along with the unused _rate helper and the public diagnostics tests
that duplicated the curated ones.

Remove dead parameters: _article_body's paired and cohort_commits with
_cohort_commits, and resource_result's source. Simplify load_macos_resources to
two conditional calls.
@lanyue-llk
lanyue-llk force-pushed the refactor/replay-remove-duplicates branch from fdbce89 to 41d8de2 Compare November 4, 2026 09:12

@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 · 41d8de2

No findings in this review.

@lanyue-llk
lanyue-llk merged commit 99e44fa into main Nov 4, 2026
7 of 8 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/replay-remove-duplicates branch November 4, 2026 09:24
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.

Consolidate parallel Trajectory Replay modules (curated vs public WebArena)

1 participant