Skip to content

refactor(browser-use): make English the source of the report renderer - #243

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

lanyue-llk merged 2 commits into
mainfrom
refactor/browser-use-english-source

Conversation

@lanyue-llk

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

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Part of #99. Remaining after this PR:

  • Web Fetch renderers (separate PR).
  • browser_use/report_publish.py (3 lines: the Chinese home-title marker and default site title), browser_use/publication.py (1 line: the truncation note in evidence excerpts) and assets/evidence-viewer.js (1 line, which picks its language at runtime). These are outside this step and have no catalog need worth a rewrite.
  • The English-edition leftovers listed below, which stay because rendered output must not change here.

Summary

The Browser Use report no longer renders Chinese and rewrites it afterwards. build_report now renders the pages twice, once per edition, through t(id, english) from the existing reporting.locales.catalog_text. Chinese lives in browser_use/messages.json under semantic IDs. The English pass runs in a scratch directory and only its HTML joins the report under en/; data files still come from the Chinese pass.

Deleted: report-translations.json (1,515 exact strings and phrases), about 130 regex translations, translate_text, the import-time reads of research/*.json, and the dependency on Web Fetch's translator. report_i18n.py keeps the catalog binding plus the link, navigation and attribute rewrite for en/.

File Lines with Han characters, before After
report.py 562 0
report_check.py 71 0
report_i18n.py 135 1 (the 中文 language link)
report-translations.json 1,508 deleted
messages.json none 690

report.py and report_check.py are added to the source policy's CATALOG_RENDERERS, so inline Chinese fails the existing check.

Left in place

  • Hash-bound: evaluation/browser-use/webarena-verified-pilot.json. Its 90 task rationales are project-written Chinese with no English field, and 28 had English in the old table. Those 28 moved to messages.json under rationale_en; the other 62 stay Chinese on English routes, as they do today.
  • Bound report content: release, review, fix-log and reviewed-cause prose keeps its own zh/en fields. The renderer now reads the field for the edition instead of going through a table.
  • Measured and dataset text: intents, evaluator output and trajectories stay as written.

Existing English-edition defects kept on purpose

Fixing any of these changes rendered bytes, so they are preserved and marked by _ZH, or by a small helper, in the code:

  • Chinese on English routes: 待复核, 未分类, 处理:, the step label before : on result pages, the evaluator error log, and the diagnosis text in the result search index.
  • The task label in the same-task comparison keeps its Chinese rationale on English routes, even for the 28 with English, because the old table never matched #<id> · <rationale>.
  • The home page's diagnostic table header shows an escaped <span> in both editions.
  • 规则 becomes Rule inside one task's search index entry (_searchable_rationale).
  • 、 and ; remain in joined model lists and some per-model cells.

Output differences that fixtures cannot show

There is no real Browser Use evidence on this machine, so none of this has been checked against a real report:

  • The old phrase substitution could rewrite parts of measured text on English routes. It no longer runs, so that text now stays raw.
  • Strings that had no English before now render real English. I wrote about 60 of those sources by hand, including evaluator fallback messages and rarely reached labels; the fixtures cover few of them.
  • A bound record with no English now stays Chinese on English routes. Before, an exact match in the old table could translate it.
  • An English build now renders every page twice, so it takes about twice as long.

Test plan

  • tests/test_golden_reports.py: browser-use-pass and browser-use-fail pass with no snapshot regeneration, and the other tracks are unchanged.
  • Differential check: I kept all 15 reports built by the Browser Use report tests, before and after the change, and compared them byte for byte. 2,380 files were identical. The only differences were the 14 browser-eval-version.json files, which record the source hash.
  • tests/browser_use, source policy, packaging, public language, templates, visual, privacy and publication groups: 694 passed and 1 failed on a mixed-case catalog ID, which I fixed. After that fix I reran only test_report_i18n.py, test_report.py and golden: 126 passed.
  • Removed tests that asserted translate_text mappings. Added catalog tests (semantic IDs, catalog equals used IDs, placeholders supplied, no Chinese in the renderers) and a direct English-edition build test.
  • Review fix: test_english_failed_result_shows_the_hash_of_its_linked_evidence_file builds a failed result from a real one-frame trace and fails without the fix. After the fix, tests/test_golden_reports.py, tests/browser_use and tests/test_report_browser_interactions.py pass (368) with no snapshot regeneration.
  • Lint gate: both ruff commands pass.
  • The full local suite is not a usable signal here. A run stopped at its failure limit at about 37%; the failures I read came from local setup (missing node_modules, a missing report profile, a stale dataset lock on the shared environment), and I did not triage all of them. CI is the full-suite gate: "Tests and static checks" and "Installation and packaging" both pass on this head.

Render the English edition directly from t(id, english) lookups, with Chinese in messages.json. Remove the post-render translation tables and the import of the Web Fetch translator. Rendered Chinese and English routes are 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 complete · b9f114e

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +4161 to +4162
_write_pages(Path(scratch), inputs, automatic_failure_counts)
write_english_report(Path(scratch), stage)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
P2 — English result pages advertise hashes for discarded scratch artifacts when a failed execution has publishable screenshots. In this pass, _extract_trace_screenshots writes English label values into the screenshots array in execution-evidence.json; _write_execution_artifacts hashes that JSON, and _execution_evidence_html displays the hash. Only HTML is copied back, while its artifact links still resolve to the Chinese-pass JSON, whose labels—and therefore SHA-256—differ. Reuse the published execution artifact metadata/hashes when rendering English pages (localizing gallery labels separately), and add a failed-execution-with-screenshot test that compares the English page's displayed hash with the linked file.

@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 b9f114ed. One defect found. It is the same bug the OCR bot reported, which I reproduced independently.

P1: English result pages publish a wrong SHA-256 for failed executions with screenshots

  • Where: src/harness/browser_use/report.py:1679 (label written into the evidence bundle), report.py:1783 (hash shown), report.py:4160-4162 (English pass discarded except for HTML).
  • Problem: _extract_trace_screenshots writes t(...) into screenshots[].label, and _write_execution_artifacts stores that in execution-evidence.json and hashes the file. The English pass therefore produces a JSON with different bytes from the Chinese pass, in a scratch directory that is then deleted. Only its HTML is kept, so en/results/<id>.html shows the hash of a file that was never published, next to a link to the Chinese-pass file.
  • Scope: failed scoring executions whose trace has a publishable frame, which is the normal case for a real failed result. The goldens and the 15-report differential miss it because every fixture trace is placeholder bytes, so no screenshot is extracted.
  • Reproduction: I built the build_browser_use_fixture(language="en", failed=True) report with a real one-frame trace.zip, then compared the published execution-evidence.json hash with the hashes on the English page.
    • Base 2383a20f: match.
    • This PR: mismatch on en/results/gpt-5.6-sol-moli-44.html (the file hashes to d31841af6f11…, which the page does not show). Across all pages in that report, this is the only one whose hash set differs between editions.
  • Why it matters: a reader checking evidence against the English page gets a false integrity failure. _check_execution_artifacts only reads the Chinese result page, so the release gate does not catch it. The PR's statement that rendered output is unchanged does not hold for these pages.
  • Suggested fix (about 4 lines, trial-run): keep the bundle independent of the edition and localize only at render time.
    • In _extract_trace_screenshots, write the label with _ZH(...). The public JSON then keeps its current bytes.
    • In _screenshot_gallery, render the alt and caption with t("extract_trace_screenshots.final_page_frame", ..., index=index, total=len(screenshots)), iterating with enumerate.
    • With this applied, the mismatch is gone and the English captions (Final page frame 1/1) and Chinese captions are as before.
  • Test: add a failed-result test with a real trace frame that asserts the English page shows the SHA-256 of the linked file. It should fail on the current head.

Verified with no finding

  • Over-design: the two-pass render with a module-level t adds no new lookup, registry or route table. It reuses catalog_text. _Authored, _searchable_rationale and _PageWriter exist only to keep bytes identical, as the scope requires.
  • Escaping: no t source in report.py contains ", < or &, so the quote=False path in _e for _Authored text does not break the attributes I checked.
  • Catalog: the 665 zh IDs match the IDs used in both renderers, and no ID has two different English sources. Chinese strings match the old source. The 6 that did not match by mechanical search were strings split across lines in the old code; I confirmed the 4 I read directly.
  • Table removal: the fields that relied on the deleted table have their own English. All browser_use_reviews and browser_use_releases records in research/report-changes.json have i18n.en, and verified causes are read through localized_cause. I found no comparison that depends on the edition other than the two _ZH checks for "not recorded".
  • Issue scope: "Part of #99" is accurate, and the remaining work and known defects are listed. Han-line counts match the PR table (report.py 0, report_check.py 0, report_i18n.py 1, messages.json 690).
  • Evidence: no files under evaluation/ or research/ changed, and no golden snapshots were regenerated.
  • Local runs: both ruff gates pass. tests/test_golden_reports.py, tests/browser_use/test_report.py, test_report_i18n.py, test_report_check.py and tests/test_report_software_versions.py gave 190 passed. I did not run the full suite locally.
  • Not checked: no real Browser Use evidence was available, so I did not build a report from it.

CI on b9f114ed

"Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" pass. ocr-review is red because of the finding above, so it comes from this PR and I did not rerun it.

…dition

The frame label was rendered per edition into the hashed evidence bundle, so
English result pages showed the hash of a discarded scratch file. Keep the
bundle label fixed and render the caption per edition in the gallery.
@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1:

Fixed (2be2d28): English result pages showed a wrong SHA-256 for execution-evidence.json on failed executions with publishable trace frames. The frame label in the hashed bundle now always comes from the catalog's Chinese text, as it did before this PR, and _screenshot_gallery renders the alt text and caption for the edition.

Added test_english_failed_result_shows_the_hash_of_its_linked_evidence_file, which uses a real one-frame trace. It fails without the fix and passes with it.

A one-off check on that failed fixture with a trace also found every non-HTML file from the English scratch pass byte-identical to the one kept from the Chinese pass.

Disputed: nothing.

Golden snapshots passed with no regeneration.

@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 · 2be2d28

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +92 to +94
def _rationale(task: dict[str, Any]) -> str:
"""Read the frozen selection rationale, which has no English field of its own."""
return _Authored(english_rationale(task["rationale"])) if _language() == "en" else task["rationale"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
P2: Apply this helper to the visible task label in _same_task_comparison as well. That function still renders _e(task["rationale"]), so removing the old post-render translation loses the existing English labels for the 28 rationales retained in rationale_en. For example, “Open an authenticated GitLab target page” now appears in English on the dataset page but remains Chinese in the English comparison matrix. Use _rationale(task) for that label and cover a mapped rationale in the English analysis-page test; leave unmapped rationales and measured intents unchanged.

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.

Disputed: this is not a regression from this PR. The old post-render translation never translated this label, because the text node is #<id> · <rationale>, which the exact-string table did not match.

  • I ran base 2383a20f's localize_html over this cell for all 90 pilot tasks, including the 28 with an entry in rationale_en. All 90 kept their raw Chinese rationale.
  • I built the English fixture report on base and on 2be2d289, passing and failing, with a real trace. Every HTML file is byte-identical, including #44 · 打开一个需要登录的 GitLab 目标页 in en/analysis/index.html.

The suggested change would alter rendered output, which this PR must keep byte-identical. It stays Chinese here, and I added it to the PR's list of existing English-edition defects kept on purpose.

@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 2be2d289. No P0, P1 or P2 defects found. One P3 note, which does not block.

P3: research/browser-use-failure-analysis.json no longer has a reader

  • Where: research/browser-use-failure-analysis.json
  • Problem: the import-time read in the old report_i18n.py was its only reader. On this head, git grep finds no reference to it anywhere in the repository. Rendered output is not affected.
  • Suggested fix: delete it in this PR if it has no other purpose, since AGENTS.md asks for superseded files to be removed with their last caller.

What I verified

  • Round 1 fix: test_english_failed_result_shows_the_hash_of_its_linked_evidence_file passes. It fails when the bundle label at report.py:1679 goes back to t(...). No other writer of execution artifacts calls t, so the JSON those hashes cover no longer depends on the edition. Gallery captions use the same index and total as the old stored label, because the total is the frame count in both.
  • Disputed OCR finding on report.py:94: the dispute is sound. Base translate_text leaves #44 · 打开一个需要登录的 GitLab 目标页 unchanged, so this is not a regression and the suggested change would alter rendered output. I did not repeat the author's HTML comparison between base and head.
  • Chinese text: every Han fragment in the catalog appears in the base renderers, apart from 6 fragments in 5 entries. I sampled two of those five; their text is still in the base source, split across string concatenations. I did not compare placeholder values against the old f-string expressions call by call.
  • English text against the old translator: I ran base translate_text over each placeholder-free catalog entry and compared it with the new English source. There were 95 differences.
    • I read them all. Most are strings the old table left Chinese or partly translated, including text the base renderer already kept in English beside it.
    • A few are wording changes that do not alter the meaning, such as Expert-repair origins becoming Expert-repaired paths. These sit on code paths the fixtures may not reach, so they could change real English pages. The PR body's list of output differences does not name this kind of rewording.
  • Data-driven text: I listed every repository JSON string under research/ and evaluation/browser-use/ that the old translator rewrote. The reader-facing groups now come from rationale_en, localized_cause and _record_text. The other groups are the now-unread file above and records for other tracks.
  • Rendering twice:
    • Load-time t calls are limited to the three "not recorded" defaults and _automatic_failure_type. All render paths for the defaults go through _recorded or an explicit comparison. The stored automatic_failure_type only reaches data/results.jsonl.
    • The page writers do not change shared input fields in ways I could find, and the renderer has no cached translated text.
  • Escaping:
    • _Authored turns off quote escaping, but no _e(t(...)) or _e(_rationale(...)) call sits directly in an attribute. A scan of the renderer found none, though it would not catch a value passed through a variable first.
    • I checked the catalog values passed without _e at the sites most likely to carry measured text: _failure_brief, the task identity line and the result hero. I did not review each of the other unwrapped values one by one, and I did not compare these sites' escaping with base.
  • Scope: the Chinese-line counts in the PR body match what I measured, per file and on base. "Part of #99" is accurate, and the remaining list matches the Han lines left under src/harness/browser_use/. The diff does not touch tests/golden, evaluation/ or research/.
  • Over-design: nothing to remove. The change deletes more than it adds, reuses catalog_text, and adds no new lookup or registry. The AST catalog tests have the same kind of counterpart in the trajectory replay and web search message tests.
  • Local runs on this head: both ruff gates pass, and tests/test_golden_reports.py plus tests/browser_use pass (353) with no snapshot regeneration. I did not run the browser interaction tests or the full suite locally.

CI

  • Passing on 2be2d289: Tests and static checks, Installation and packaging, Rendered reference and report checks, Python 3.11, Select check scope and OCR dispatch.
  • Red: ocr-review, which reports 1 blocking finding. That is the disputed finding above, so I do not count it as a defect in this PR.
  • Rerun: my one attempt failed, because gh run rerun returned a 404 while looking up the OCR dispatch workflow. The status is still red and needs the owner to clear it or re-trigger the bot.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
@lanyue-llk
lanyue-llk merged commit 20b5964 into main Nov 4, 2026
6 of 7 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/browser-use-english-source branch November 4, 2026 15:09
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.

1 participant