Skip to content

refactor(browser-use): split build_report into named typed stages - #215

Merged
lanyue-llk merged 2 commits into
mainfrom
refactor/browser-use-report-stages
Nov 4, 2026
Merged

lanyue-llk merged 2 commits into
mainfrom
refactor/browser-use-report-stages

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 #209

Part of the #104 and #87 refactor series; the other functions listed in #104 stay with that issue.

Summary

build_report in src/harness/browser_use/report.py was 1,172 lines. It is now a 36-line sequence of named, typed stages in the same file: load inputs, open the stage directory, write each page class, write the public data files, add the language editions, bind the build version, then publish. ReportInputs is a frozen dataclass that carries the loaded evidence to the stages.

The longest stage is _load_report_inputs at 100 lines, 38 of which are the ReportInputs constructor. Moving routes into separate modules and direct per-language rendering stay out of scope, as #209 says.

The code was moved by script from line ranges of the old file rather than retyped. An AST comparison of the old function and the new stages shows these differences only:

  • translated became the module-level _translated, and the local model became model_names.
  • by_attempt is built during input loading. It reads only fields _public_attempt has already read and converted, so it adds no failure path.
  • _write_public_environment reads browser_versions and browser_images from environment again, because the engine-page stage used to leave them in scope.
  • The bilingual_text import moved from the top of build_report into function-local imports in the stages that use it. It is the same imported function, so this does not change output.
  • The evidence-index entry is now built by _evidence_index_entry after the result page is written, instead of before the page renders. Page rendering only reads execution_records, public and row, and _public_attempt has already converted row["attempt"], so the entry's content does not change.
  • New signatures, annotations and stage calls.

All other functions and module-level statements are AST-identical.

Checked first: no frozen binding records this file's contents. git grep does not find its SHA-256. configs/report-templates.json and tests/browser_use/test_report_check.py record only its path, which does not change. The visual-receipt checker_sources hashes report_visual.py and reporting/visual.py, not this file.

Test plan

Run locally on macOS with Python 3.11 from the shared locked environment, at 24dd3d64 unless noted.

  • Golden snapshots: tests/test_golden_reports.py passes with no snapshot changes, including browser-use-pass and browser-use-fail.

  • tests/test_golden_reports.py, tests/browser_use, tests/test_explicit_utf8_io.py, tests/test_public_tree_privacy.py: 444 passed, 1 failed. The failure is test_report_builds_are_byte_identical_under_an_ascii_locale, a local setup problem: its pytest subprocess could not import harness, because this run set the import path with -o pythonpath rather than PYTHONPATH, and the subprocess does not inherit that option. CI covers this test.

  • Lint gate: ruff check --config 'include=["*.py"]' --select F,TID252 . and ruff check pass.

  • Before/after differential, using throwaway scripts outside the repository: 527 build_report calls on the old and new file, with these inputs:

    • the builds made by tests/browser_use/test_report.py;
    • one change at a time to the evidence files, attempt rows and profile (delete, empty, garbage, dropped, null or altered key);
    • an injected exception in each of 48 helpers;
    • language options, replacing a marked output and refusing an unmarked one.

    The output-tree digest, return value, exception type and message, leftover directories and an ordered trace of helper calls with their string results are identical in all 527. Of these, 252 complete and 275 fail, with 77 distinct messages.

  • Negative control for the trace: swapping _write_public_environment and _write_review_data changes the trace of all 3 completed builds in the control scenario but not their output trees. The trace therefore catches a reorder that the output digest misses.

  • At 0d967ab9, which removes the unread ReportInputs.manifest field: tests/test_golden_reports.py passes with no snapshot changes; tests/browser_use, tests/test_public_tree_privacy.py and the golden tests give 386 passed; tests/browser_use/test_report.py, tests/test_explicit_utf8_io.py and the golden tests give 178 passed; the lint gate passes. The 527-call differential was not rerun for this commit, since it only deletes a field that no stage reads.

  • Line trace: every statement in the stages ran. The shared fixture misses eight (merged review attempts, the replay bridge data files, the symlink and missing-figure guards, and publish rollback), so the differential adds scenarios that reach them by patching helpers.

Limit: these builds use synthetic evidence, and the fixture's bridge scenario patches the bridge loader instead of loading a real hash-bound bridge. No real evidence was rebuilt.

  • CI on Linux at 0d967ab9: "Tests and static checks" (which includes the ASCII-locale test above), "Installation and packaging" and "Rendered reference and report checks" pass.

@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 · 24dd3d6

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 24dd3d64 against main 0565b4ab (main has not moved). I found no behavioural defect. There are two P3 findings, both small.

Findings

P3. src/harness/browser_use/report.py:2671 (set at line 2855): ReportInputs.manifest is never read.
Nothing in the file reads inputs.manifest. The stages use bundle["manifest"], inputs.protocol and inputs.environment. The other 36 fields are all read. The field widens the shared stage input and suggests that one manifest speaks for every cohort, when bundles[0] is only the first.
Fix: remove the field and its constructor argument. Keep the local manifest in _load_report_inputs, which still needs it for config, protocol, environment and _resolve_measured_tasks.

P3. PR body, "Summary": the list of AST differences is presented as complete, but it omits two moves.
The body says the comparison "shows these differences only". My comparison found two more:

  • The bilingual_text import moved from the top of build_report to function-local imports in the stages and _translated. A failure to import report_i18n would therefore surface later, inside the try, instead of before profile validation.
  • The evidence-index entry used to be appended before the result page was rendered. _write_result_page now builds it after the page is written.

Neither changes output. Every field the entry reads has already been read by that point, and the old list held the same execution_records object, so any later change to it was visible either way. The list is still the basis of the byte-identity argument, so it should be complete.
Fix: add both moves to the list. No code change is needed.

What I verified

Structure (my own AST script over the old and new file)

  • No function was removed. All pre-existing functions other than build_report, and all module-level statements, are AST-identical. No imports were added at module level.
  • All string constants in the old build_report appear in the new stages with the same counts. The only additions are browser_versions and browser_images, from the re-read the PR declares.
  • Every _section, _hero, _table, _page, write_json, translated and _article_body call matches after the declared translated and model renames.
  • No stage has a free name that was a local of the old function, so none can silently resolve to a module global instead.
  • The old function mutates only values it builds locally: the public rows (only during annotation), failure_reviews, verified_causes and audit. None of the shared inputs are mutated by page stages, and none of them were rebound between what are now stages, so carrying them on a frozen dataclass is equivalent.
  • by_attempt moved earlier, as declared. _public_attempt has already read model and engine and converted task_id with int().
  • The re-read of versions and images is equivalent, because environment is not mutated.
  • The load order, including official_dataset before _resolve_tasks, the try scope and the publish rollback all match the old code.
  • All new stage functions have annotated parameters and returns. build_report is about 36 lines and the longest stage is _load_report_inputs at 101 lines, as claimed. No type checker is installed in the locked environment, so I checked annotations by reading them against the helpers they call, not by running a checker.

Differential

  • I built the shared fixture on 0565b4ab and on the head with a fixed temporary path, for zh and en, pass and fail (4 builds). Per-file SHA-256 digests match across all routes, and no stage directory is left over.
  • A first run with differing temporary paths showed differences in data/environment.json, data/summary.json, data/interpretation-evidence.json and report-data.json. They disappeared with a fixed path, so they came from the fixture's paths and not from the code.
  • I did not repeat the 527-run failure-path differential described in the PR. My failure-path check is the code comparison above.

Tests and lint (macOS, Python 3.11)

  • tests/test_golden_reports.py, tests/browser_use, tests/test_explicit_utf8_io.py and tests/test_public_tree_privacy.py: 445 passed, 0 failed, run with PYTHONPATH set. This includes the ASCII-locale test that the PR's test plan reports as a local failure, which confirms that failure came from how that run set the import path.
  • The golden snapshots have no diff; the PR touches only report.py.
  • Both lint gates pass.

Scope and rules

  • Closes #209 is accurate: build_report is split into named, typed stages in the same file, and routes and direct per-language rendering stay out of scope as the issue says.
  • No frozen binding records this file. The old file's SHA-256 is not in Git or in local evidence JSON. The tracked references (configs/report-templates.json, pyproject.toml, tests/browser_use/test_report_check.py) record only the path, and template_identity records only the path.
  • No compatibility aliases, parallel implementations, evidence changes or private data.

CI at 24dd3d64
All checks pass: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks", "Python 3.11", "Select check scope", "OCR dispatch" and "ocr-review".

@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 · 0d967ab

No findings in this incremental review.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1, both findings addressed. Nothing disputed.

  • ReportInputs.manifest unread (P3): fixed in 0d967ab. The field and its constructor argument are gone, and _load_report_inputs keeps its local manifest. No new test: this only deletes a field that nothing reads, and the route snapshots are the behavioral check. They did not change.
  • Differences list incomplete (P3): PR body updated, no code change. The list now includes the bilingual_text import move and the later evidence-index entry construction. I also corrected the _load_report_inputs length to 100 lines.

The 527-call differential was not rerun for 0d967ab. CI at 0d967ab: "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks" pass.

@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 0d967ab9 against base 0565b4ab (current main).

No defects were found. Both round 1 findings are resolved: ReportInputs.manifest is gone, and the PR body now lists the bilingual_text import move and the later evidence-index entry construction.

What I verified

Equivalence with the old code

  • All other top-level functions, classes and module-level statements are AST-identical to the base. Only build_report changed, and 53 definitions were added.
  • Every value expression in the old build_report appears unchanged in the new stages, after allowing for translated to _translated and model to model_names. The only unmatched old values are thin wrappers around the same calls (include_english, model, adoption_evidence, automatic_failure_counts, by_attempt), which I read by hand.
  • The ordered sequence of the 46 side-effecting calls (write_text, write_json, mkdir, copy2, rename, rmtree, _write_execution_artifacts, language and version binding) is identical once the stages are inlined.
  • No stage reads a global that used to be a local of build_report, and no stage has an undefined name. The old locals bound more than once (for example site_images) keep the right value in each stage: the methodology page keeps the config fallback and the reproduce page does not.
  • by_attempt is built earlier, but _public_attempt has already run str(row["model"]), str(row["engine"]) and int(row["task_id"]), as the PR body says.
  • Importing report_i18n later is safe. In a fresh process, importing it changes no module-level data in the harness modules already loaded, so pages rendered before that import cannot differ. If a required translation file were missing, the error would now appear later in the build, but no output would be published and the stage directory would still be removed.

Output

  • I built the shared fixture with the old and the new code, in zh and en, for pass and fail outcomes, using scripts outside the repository. All four complete output trees (127 and 231 files) are byte-identical, including the data files and the .generated-report marker. This used synthetic evidence only.
  • tests/test_golden_reports.py passes with no snapshot changes, and the PR does not touch the snapshot files.

Tests and lint, run locally at this head

  • tests/test_golden_reports.py, tests/browser_use/test_report.py and tests/test_explicit_utf8_io.py: 178 passed.
  • tests/browser_use and tests/test_public_tree_privacy.py: 370 passed.
  • Both ruff gates pass.

I did not rerun the PR's 527-call differential.

Scope and rules

  • Closes #209 is justified: build_report is a 36-line sequence of stages in the same file, and all stage signatures are annotated. Separate route modules and per-language rendering stay out of scope, as the issue says.
  • The base file's SHA-256 does not appear anywhere in the tracked tree. References to the path in configs/report-templates.json, tests/browser_use/test_report_check.py and the pyproject.toml lint setting record only the path, which does not change.
  • The diff touches only src/harness/browser_use/report.py. It adds no compatibility aliases, parallel implementation, evidence or private data.
  • The line counts in the PR body are correct: 1,172 before, 36 for build_report, and 100 for _load_report_inputs, of which 38 are the constructor.

CI at 0d967ab9
"Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" all pass. The run's head SHA matches this commit.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
@lanyue-llk
lanyue-llk merged commit e8cf235 into main Nov 4, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/browser-use-report-stages branch November 4, 2026 02:48
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.

Split Browser Use build_report into named stages

1 participant