Repository navigation
refactor(browser-use): split build_report into named typed stages - #215
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
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_textimport moved from the top ofbuild_reportto function-local imports in the stages and_translated. A failure to importreport_i18nwould therefore surface later, inside thetry, instead of before profile validation. - The evidence-index entry used to be appended before the result page was rendered.
_write_result_pagenow 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_reportappear in the new stages with the same counts. The only additions arebrowser_versionsandbrowser_images, from the re-read the PR declares. - Every
_section,_hero,_table,_page,write_json,translatedand_article_bodycall matches after the declaredtranslatedandmodelrenames. - 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
publicrows (only during annotation),failure_reviews,verified_causesandaudit. 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_attemptmoved earlier, as declared._public_attempthas already readmodelandengineand convertedtask_idwithint().- The re-read of
versionsandimagesis equivalent, becauseenvironmentis not mutated. - The load order, including
official_datasetbefore_resolve_tasks, thetryscope and the publish rollback all match the old code. - All new stage functions have annotated parameters and returns.
build_reportis about 36 lines and the longest stage is_load_report_inputsat 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
0565b4aband on the head with a fixed temporary path, forzhanden, 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.jsonandreport-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.pyandtests/test_public_tree_privacy.py: 445 passed, 0 failed, run withPYTHONPATHset. 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 #209is accurate:build_reportis 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, andtemplate_identityrecords 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".
There was a problem hiding this comment.
✅ Re-review complete · 0d967ab
No findings in this incremental review.
|
Review round 1, both findings addressed. Nothing disputed.
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
left a comment
There was a problem hiding this comment.
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_reportchanged, and 53 definitions were added. - Every value expression in the old
build_reportappears unchanged in the new stages, after allowing fortranslatedto_translatedandmodeltomodel_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 examplesite_images) keep the right value in each stage: the methodology page keeps theconfigfallback and the reproduce page does not. by_attemptis built earlier, but_public_attempthas already runstr(row["model"]),str(row["engine"])andint(row["task_id"]), as the PR body says.- Importing
report_i18nlater is safe. In a fresh process, importing it changes no module-level data in theharnessmodules 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
zhanden, 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-reportmarker. This used synthetic evidence only. tests/test_golden_reports.pypasses 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.pyandtests/test_explicit_utf8_io.py: 178 passed.tests/browser_useandtests/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 #209is justified:build_reportis 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.pyand thepyproject.tomllint 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.
Issues
Closes #209
Part of the #104 and #87 refactor series; the other functions listed in #104 stay with that issue.
Summary
build_reportinsrc/harness/browser_use/report.pywas 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.ReportInputsis a frozen dataclass that carries the loaded evidence to the stages.The longest stage is
_load_report_inputsat 100 lines, 38 of which are theReportInputsconstructor. 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:
translatedbecame the module-level_translated, and the localmodelbecamemodel_names.by_attemptis built during input loading. It reads only fields_public_attempthas already read and converted, so it adds no failure path._write_public_environmentreadsbrowser_versionsandbrowser_imagesfromenvironmentagain, because the engine-page stage used to leave them in scope.bilingual_textimport moved from the top ofbuild_reportinto function-local imports in the stages that use it. It is the same imported function, so this does not change output._evidence_index_entryafter the result page is written, instead of before the page renders. Page rendering only readsexecution_records,publicandrow, and_public_attempthas already convertedrow["attempt"], so the entry's content does not change.All other functions and module-level statements are AST-identical.
Checked first: no frozen binding records this file's contents.
git grepdoes not find its SHA-256.configs/report-templates.jsonandtests/browser_use/test_report_check.pyrecord only its path, which does not change. The visual-receiptchecker_sourceshashesreport_visual.pyandreporting/visual.py, not this file.Test plan
Run locally on macOS with Python 3.11 from the shared locked environment, at
24dd3d64unless noted.Golden snapshots:
tests/test_golden_reports.pypasses with no snapshot changes, includingbrowser-use-passandbrowser-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 istest_report_builds_are_byte_identical_under_an_ascii_locale, a local setup problem: its pytest subprocess could not importharness, because this run set the import path with-o pythonpathrather thanPYTHONPATH, and the subprocess does not inherit that option. CI covers this test.Lint gate:
ruff check --config 'include=["*.py"]' --select F,TID252 .andruff checkpass.Before/after differential, using throwaway scripts outside the repository: 527
build_reportcalls on the old and new file, with these inputs:tests/browser_use/test_report.py;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_environmentand_write_review_datachanges 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 unreadReportInputs.manifestfield:tests/test_golden_reports.pypasses with no snapshot changes;tests/browser_use,tests/test_public_tree_privacy.pyand the golden tests give 386 passed;tests/browser_use/test_report.py,tests/test_explicit_utf8_io.pyand 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.
0d967ab9: "Tests and static checks" (which includes the ASCII-locale test above), "Installation and packaging" and "Rendered reference and report checks" pass.