Skip to content

refactor(web-fetch): make English the source of report text - #244

Merged
lanyue-llk merged 5 commits into
mainfrom
refactor/web-fetch-english-source
Nov 4, 2026
Merged

lanyue-llk merged 5 commits into
mainfrom
refactor/web-fetch-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. This is the last English-source step for the project's own report text. What remains of #99 is listed below with the reason it stays.

Summary

Web Fetch report text now has English as its source: t(id, english) in the renderer, with Chinese in src/harness/web_fetch/messages.json (2,118 messages).

  • Text that already had both editions (h(zh, en), x if english else y, model_text, bilingual_text) now reads the catalog directly.
  • The post-render Localizer stays. Rendering each language directly would mean a second full build pass, and machine keys, sort order and attribute values depend on the Chinese text. In this pipeline t returns the Chinese text and declares its English in the existing TEXT table, so no new lookup is added.
  • report-translations.json and the Localizer regex rules match base. An earlier revision of this PR deleted 625 of 3,285 exact-string entries and 26 regex rules as unused. All are restored, because frozen and refresh builds render saved Chinese text without running t.
  • A table entry wins over t: t adds English only for text the table lacks, so a Chinese placeholder value cannot replace a fully English entry with mixed text. 浏览器 therefore keeps its table translation, Web text, as on base.
  • messages.json is added to package data and to renderer_sha256, so a catalog edit still refreshes the presentation.

Chinese lines per file

Lines containing a Chinese character, in the source files whose text moved. messages.json adds 2,118 lines and report-translations.json is unchanged at 3,409.

File Before After
report.py 1157 162
report_i18n.py 222 222
report_components.py 212 6
report_explainer.py 163 139
failure_diagnosis.py 65 1
report_diagnostic.py 52 5
report_check.py 46 22
report_resources.py 41 2

Does this remove the translation table's maintenance burden?

No. The table stays at 3,285 entries and the regex rules stay, and this PR adds a second place for Chinese. For 899 catalog values a translation now exists in both the renderer and the table, and the table's wins. New text needs only t, unless it can be saved and rendered by a later build; such text also needs a table entry to stay English there. What this PR removes is hand-typed Chinese in the renderers.

What this does and does not prove

  • Golden builds: no snapshot was regenerated, and all 17 pass. A kept-build diff was also used during migration.
  • Branches the fixtures do not render: golden does not cover them. About 570 strings had no English anywhere, so I wrote it for this PR. Where such a string reaches an English page, that page changes from Chinese to English. If a value inside the template is Chinese and the rendered Chinese has no table entry, the page shows mixed text; with an entry, the table's English stays, as on base. The English written for this PR has not been reviewed on a real report.
  • Process order: t registers English only in the process that runs it. Text saved by an earlier build reaches the English pass without a t call: diagnoses stored in results.jsonl by rescoring.py, reused by report_build.py, and log headings rebuilt by refresh_local_presentation. These translate only through the table and regex rules. Restoring them returns the fresh-process result to base for every input. Saved text that base could not translate stays Chinese: 1,219 of the 2,118 catalog values have no table entry or rule, including 53 of the 93 failure_diagnosis.py strings. A build that runs diagnose shows those in English; a build that reuses a saved diagnosis shows Chinese, as on base.
  • Real report: I did not rebuild one, because no current measured evidence is on this machine. Because the table and rules match base, bound prose outside Git translates as it did on base.

What remains of #99, and why

  • report_i18n.py, report-translations.json: the Localizer, all its regex rules and all 3,285 exact-string entries remain. Saved results, earlier builds and bound prose depend on them. Removing them needs direct per-language rendering plus a way to carry English with saved text, a large rewrite for a small gain now. This is the largest part of Make English the source language of all report renderers, with Chinese as a catalog #99 still open.
  • report_explainer.py: the 139 lines are mostly sentence fragments split around values and inline tags. They would need rewriting into whole messages, and this file has the least to gain.
  • report.py:
    • Cohort-specific WebMainBench prose (Moli fix chapters, the werewolf-page correction) belongs in bound report content.
    • WCXB per-language tables already keep both editions per field.
    • Whole-node rules whose replacement translates a Chinese value stay, because an exact template would leave that value untranslated.
    • Machine keys such as data-kind values and filter keys are unchanged, because they are rendered bytes.
  • report_check.py: forbidden-text lists and negative controls match Chinese output on purpose.
  • Known English-page leaks, left as is: 参考状态:未提供完整参考。 on en/datasets/* renders in Chinese today. Eight t calls in report.py carry an inline link in their values (the_denominator_is_all_first_round_failed, passing_results_have_three_way_check_records, source_page_observations_and_output_checks_are, full_text_recall_precision_and_f1_do, characters_this_scoring_input, the_body_text_was_extracted_by, if_the_task_requires_body_text_and, call_time_configuration_implementation_versions_and_scorer), so their key never matches a text node and they stay Chinese on English pages, the same as before this PR. Fixing either changes golden output, so it needs its own change.
  • Hash bindings: no file a hash binding freezes was edited.

Test plan

Run at this head unless noted.

  • tests/test_golden_reports.py: 17 passed, tests/golden unchanged, nothing regenerated.
  • tests/test_local_audit.py: 61 passed. test_report_reading.py: 8 passed. test_report_body_scope.py: 64 passed, 1 skipped. test_failure_diagnosis.py: 26 passed.
  • tests/test_source_language_policy.py, test_public_report_language.py, test_report_locales.py: 63 passed.
  • Both ruff gates (ruff check and --select F,TID252,B023,B905): pass.
  • tests/test_optional_reports.py fails locally on main too, because its child process imports another checkout. Linux CI is the gate for it. The wider -k report run from earlier heads was not repeated.
  • test_chinese_value_keeps_the_base_english_on_the_dataset_page builds a real English dataset page through runner.run_evaluation and build_report, with a named_link contract and version 3 body rules. It failed before t stopped overwriting table entries, with 具名详情入口: 至少 3 条 complete and unique records, checked by 详情链接 and 每段硬下限 60.0%. Those three sentences now match base 2383a20. The page's only other text differences from base are two strings that were Chinese there and are now English: 标题 and 。入口按域名与路径去重。.
  • test_catalog_text_translated_without_a_render_does_not_shrink counts catalog values fully translated by a fresh TEXT loaded from the JSON alone, with placeholders filled with a number, and requires at least the current 899 of 2,118. The earlier per-key version of this check failed on 644 values before the table was restored, and on 20 with only the JSON restored, which is why the regex rules are restored too.
  • test_saved_diagnosis_translates_in_a_process_that_never_diagnosed passes saved diagnose() output through localize_html in a new process. It failed before the table was restored with 源站拒绝该次访问, 源站访问, 直接返回依据 and 未命中登记的目标资源。 on the English page.
  • Tests changed: test_report_reading builds its samples with t and adds a regression test for an escaped error message; test_renderer_identity_covers_loaded_assets also covers the catalog. test_report_presentation is unchanged from base.

Move report text in the Web Fetch renderer modules to t(id, english), with Chinese in messages.json. t declares its English for the post-render pass, so migrated translation entries are deleted. Rendered output of every golden build is 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 · ffe4ed1

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

"""Identify the presentation: the renderer and the stylesheets and scripts it loads."""
package = Path(__file__).parent
sources = [package / 'report.py', *sorted(
sources = [package / 'report.py', package / 'messages.json', *sorted(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

test · medium
P2: Adding this required file breaks tests/test_local_audit.py::test_renderer_identity_covers_loaded_assets. That test redirects report_build.__file__ to a temporary package containing only report.py and assets/report.css, so its first renderer_sha256() call now raises FileNotFoundError for messages.json before checking asset invalidation. Update the fixture to create the catalog, and also assert that changing its contents changes the digest. Keep the catalog mandatory in production.

+ (' data-winner="true" class="good"' if winner else '')+'>'+text+'</span>')
def latency_table(population):
return _table(['浏览器', '样本数', '平均总耗时 · ms', 'P50 · ms', 'P95 · ms'], [
return _table([t('web_text', 'Web text'), '样本数', '平均总耗时 · ms', 'P50 · ms', 'P95 · ms'], [

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: This column contains browser configuration names, but the new English source labels it “Web text”. The catalog maps web_text to 浏览器, and t() registers TEXT['浏览器'] = 'Web text', so the English localization mislabels the comparison dimension while Chinese still looks correct. The same substitution appears in the combined pass-rate table below. Use a Browser/Method message for both headings and check their English output; these tables compare methods across document and media tasks as well as webpage text.

Comment thread src/harness/web_fetch/report_i18n.py Outdated
def t(key: str, source: str, /, **values) -> str:
"""Render one Chinese text node and declare its English for the post-render pass."""
chinese = translate(MESSAGES, key, "zh", **values)
TEXT[chinese.strip()] = source.format_map(values)

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: Registering only the complete formatted string loses translations when HTML escaping splits it into parser events. For example, empty_output_reason() passes a retained error such as can't connect into this helper, and report.py escapes the result before rendering. Localizer(convert_charrefs=False) then receives the Chinese prefix plus can, &#x27;, and t connect separately; none matches this TEXT key. The removed regex previously translated the prefix in that first text event, so this is a regression on ordinary error messages containing quotes (also affecting ampersands and angle brackets). Preserve localization across escaped entities, or carry the English edition explicitly for these dynamic nodes, and add a regression test through localize_html() with an escaped error message.

…over the catalog in tests

An HTML-escaped value splits a text node, so a rule with an open text group is the only thing that still translates the prefix. Restore those rules. Label the browser column Browser, include messages.json in the renderer identity test, and satisfy the B023 lint gate.

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

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 1

Head reviewed: e92b66b1. CI on this head is green (Tests and static checks, Installation and packaging, Rendered reference and report checks).

Findings

P1: a review refresh can turn English diagnostic log pages Chinese (src/harness/web_fetch/report.py:2373, src/harness/web_fetch/report-translations.json)

  • Problem: t registers English only when it runs in the current process. The refresh loop in generate rebuilds every logs/*.html route from the Chinese h1 and note saved in the previous build, so no t call runs for that text. This PR deleted three of those strings from TEXT:
    • 已保存的诊断日志
    • 仅包含实际观测的日志。
    • 产品实际返回;公开副本已隐藏凭据与本机路径。
  • When it happens: scripts/build_report.py --refresh-review with an unchanged renderer hash. Only the freshly reviewed attempts go through run_log_section, but all logs/*.html routes and their en/ copies are in the install list (report_build.py:1705-1721). If no selected attempt has a public debug log or public response, the strings are never registered. The same applies to the note if every selected attempt has its own public_log_note. en/logs/*.html is then overwritten with a Chinese heading or note.
  • Nothing catches it: the untranslated-text check in write_english_report only runs on guide/ routes (report_i18n.py:739), and golden builds do not cover this path.
  • Evidence: in a fresh process I called diagnostic_view_page(out, 'logs/a.txt', '已保存的诊断日志', '仅包含实际观测的日志。'), then write_english_report(out, source_routes=['logs/a.html']).
    • Base 2383a20f: h1: Saved diagnostic logs | note: Contains only observed logs.
    • This head: h1: 已保存的诊断日志 | note: 仅包含实际观测的日志。
    • I ran this at function level and traced the refresh path by reading the code. I did not run a full refresh end to end.
  • PR text: the "Process order" bullet says the only caller renders before it calls write_english_report. This loop is the exception, so the bullet needs correcting.
  • Fix: restore those three exact entries to report-translations.json, since this text comes from saved pages and not from a t call in that process. Add a test that builds a log route with TEXT reset to the JSON contents and asserts the English h1 and note.

P3, not blocking: eight t calls hold English that can never render (report.py:835, 837, 876, 2256, 2283, 2345, 2347, 2671)

Their values contain an inline <a>, so the registered key never matches a text node. Those strings stay Chinese on English pages. This is not a regression: base produces the same Chinese for them. It does contradict the README's "one text node per call", and the leak list under "What remains of #99" omits them. Add one line to that list, or split these calls, if you touch this again.

Verified with no defect

  • Placeholders: across all 2,689 t, h and pair call sites, one key is non-constant and is a local wrapper. Every other call has a key in the catalog, matching placeholders in Chinese and English, and all placeholders supplied. Format specs (,, g, .1f, .2f) are all applied to numeric values or the same expressions as before, so I found no KeyError or ValueError risk in unrendered branches.
  • Chinese bytes: every fragment of every catalog value appears as a string constant in the base sources.
  • English from t: evaluated with base translate_text, 1,295 templates give the same English and 652 were previously Chinese or mixed. Only 3 differ, all 浏览器 to Browser, which the PR discloses. No Chinese text is registered with two different English values through t.
  • h and pair: all 713 English values match the base pairs or base TEXT wherever base had that Chinese text.
  • Deleted entries: I searched all 628 deleted TEXT keys across src/, research, evaluation, configs, scripts and the installed lexbench_webfetch package, and each hit was a substring of a longer string. No surviving rule depends on them. All 628 are in the catalog. Apart from the finding above, renderer text still goes through t.
  • Deleted regex rules: none has an open text group. The rules with open groups that matter for escaped values are present.
  • Catalog: 2,118 messages, none unused. messages.json is in package data and in renderer_sha256.
  • Hash-bound files: none in the diff. tests/golden is unchanged.
  • Scope: "Part of #99" is accurate, with no Closes. Per-file Chinese-line counts are in line with the table; a narrower CJK range gave slightly lower numbers, with the same reductions.
  • Over-design: t and pair are small and are the minimum needed while the post-render Localizer stays. I have no simpler form to suggest.

Run locally

  • tests/test_golden_reports.py: 17 passed, no regeneration.
  • Report test files (reading, local audit, presentation, public language, languages, explainer, Browser Use i18n, golden): 232 passed.
  • Ruff lint gate with F,TID252,B023,B905, plus the default config: passes.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1:

Fixed

  • P1, log routes rebuilt on a review refresh: b3e619a7 restores the three exact entries in report-translations.json (已保存的诊断日志, 仅包含实际观测的日志。, 产品实际返回;公开副本已隐藏凭据与本机路径。). A new test builds both log routes with TEXT reset to the JSON contents and asserts the English h1 and note. It failed before the restore. Golden snapshots are unchanged.
  • PR body: corrected the "Process order" bullet and the entry counts (625 deleted, 2,660 remain).
  • P3, inline-link t calls: confirmed that all eight stay Chinese on English pages, same as base. Named them in the leak list under "What remains of Make English the source language of all report renderers, with Chinese as a catalog #99". Not split, because that would change golden output.

Disputed: none.

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

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 b3e619a7. One P1. CI is green on this head (Tests and static checks, Installation and packaging, Rendered reference and report checks).

P1: English result pages show saved failure diagnoses in Chinese after a frozen rebuild or refresh

Where: src/harness/web_fetch/report-translations.json (entries deleted), src/harness/web_fetch/report.py:1488 and :2211-2214 (saved values rendered), src/harness/web_fetch/report_build.py:330 and :620 (diagnose skipped).

Problem: This is the same class as the round 1 log-header bug, on a much more visible route. rescoring.py:66 stores diagnose() output in results.jsonl. The later build reads those saved Chinese strings without calling diagnose:

  • _build_frozen_presentation only calls it if not record.get('diagnosis').
  • refresh_local_presentation passes the loaded records straight to generate.
  • build_report --local-audit keeps a saved failure-classification-v2 diagnosis.

So the t calls in failure_diagnosis.py never run in that process and never register their English. The PR deleted 35 of those strings from TEXT. A failed result's category, stage, evidence and certainty then stay Chinese on en/attempts/*.html, and the category also stays Chinese on en/analysis/index.html, including in the failure class column. No check catches it, because the untranslated-text check covers only guide routes and the golden fixture has no saved diagnosis.

Reproduced: I built the fixture report in one process. In a new process I gave the failed record a saved diagnosis made of strings diagnose produces, then called generate(..., presentation_only=True, ...), the call the refresh makes.

Checkout Chinese text on the English pages, beyond what both checkouts share
Base 2383a20f None
This head en/attempts/*.html: 源站拒绝该次访问 (twice), 源站访问, 未命中登记的目标资源。, 直接返回依据. en/analysis/index.html: 源站拒绝该次访问 (twice)

This was run at generate level. The route from build_report and refresh_local_presentation into it was traced by reading the code, not run end to end with a rescored snapshot.

The PR body's description does not cover this. "Process order" says the log route is the one exception. "Real report" only discusses prose in bound report assets, while these strings come from this repository's own diagnose, saved in results.jsonl.

Suggested fix:

  1. Restore these 35 exact entries to report-translations.json, with their base English:

    ;同时返回非目标资源:, 接口鉴权失败, 正文提取为空, 浏览器执行上下文中断, 调用截止时间, 内容核验, 输出文本解码损坏, 直接返回依据, 超过端到端预算, 已返回文件字节,但格式、长度或目标 SHA-256 校验未通过;逐项证据见文件交付详情, 文件校验未通过, 正文范围不完整, 正文不足, 有效条目不足, 加载 / 提取超时, 方法禁止跨站跳转, 方法空页规则拦截, 方法安全限制, 未命中登记的目标资源。, 没有可验证的原文件字节;文字或链接不能替代文件, 源站访问, 源站拒绝该次访问, 未取得原文件, 服务取页失败, 服务取页, 缺少关键信息, 缺少目标资源, 资源核验, 取页连接失败, 取页返回 404, 返回非目标资源, 源站要求验证码, 任务规则未满足, 服务未披露更细原因;不能仅凭该错误归责源站或服务内部, 不支持输入类型

  2. Add one test next to test_refreshed_log_route_translates_saved_chinese_header_without_a_prior_render, with TEXT reset to the JSON contents. It should translate saved diagnosis strings without diagnose having run.

  3. Correct the "Process order" bullet so it names saved diagnoses as a second exception.

No new mechanism is needed.

Verified, no finding

  • Round 1 fix: the three log entries are restored and the new test exercises them.
  • Catalog: every t, pair and report_text key resolves in messages.json, and placeholders match the supplied values. No Chinese text maps to two different English strings through t, so registration order cannot change a translation.
  • English: the only English that differs from a base TEXT entry is 浏览器, from Web text to Browser, which the PR discloses.
  • Deleted entries: all 625 have a registering t site. A literal search of src, research, evaluation, configs, scripts, docs and .agents finds 35 hits, but they are other tracks' own catalogs, regex fragments or an unrelated document, not a renderer path that relies on the deleted entry. Saved evidence is the gap above.
  • Hash-bound files: tests/golden, evaluation/ and .github/ are untouched. messages.json is in package data and renderer_sha256.
  • Issue section: "Part of #99" matches the listed remainder.
  • Local runs: both Ruff gates pass. tests/test_golden_reports.py, test_report_reading.py, test_report_presentation.py and test_local_audit.py: 124 passed, with no snapshot regenerated.

Frozen and refresh builds render saved Chinese text without running t(), so
entries and regex rules deleted as unused left Chinese on English pages. Restore
report-translations.json and the regex rules to their base state, and cover the
whole class with one test over every catalog value base could translate.
t() overwrote full English table entries with mixed text whenever a placeholder
value was Chinese. Register its English with setdefault so the table wins. This
also returns 浏览器 to its table translation.

Replace the saved-text fixture with a count of catalog values a fresh TEXT
translates, and add a dataset-page regression test.
lanyue-llk added a commit that referenced this pull request Nov 4, 2026
@lanyue-llk
lanyue-llk merged commit 7ab11dc into main Nov 4, 2026
5 of 9 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/web-fetch-english-source branch November 4, 2026 16:36
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