Repository navigation
refactor(web-fetch): make English the source of report text - #244
Conversation
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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'], [ |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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, ', 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.
There was a problem hiding this comment.
✅ Re-review complete · e92b66b
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
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:
tregisters English only when it runs in the current process. The refresh loop ingeneraterebuilds everylogs/*.htmlroute from the Chineseh1and note saved in the previous build, so notcall runs for that text. This PR deleted three of those strings fromTEXT:已保存的诊断日志仅包含实际观测的日志。产品实际返回;公开副本已隐藏凭据与本机路径。
- When it happens:
scripts/build_report.py --refresh-reviewwith an unchanged renderer hash. Only the freshly reviewed attempts go throughrun_log_section, but alllogs/*.htmlroutes and theiren/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 ownpublic_log_note.en/logs/*.htmlis then overwritten with a Chinese heading or note. - Nothing catches it: the untranslated-text check in
write_english_reportonly runs onguide/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', '已保存的诊断日志', '仅包含实际观测的日志。'), thenwrite_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.
- Base
- 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 atcall in that process. Add a test that builds a log route withTEXTreset to the JSON contents and asserts the Englishh1and 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,handpaircall 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 noKeyErrororValueErrorrisk 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 basetranslate_text, 1,295 templates give the same English and 652 were previously Chinese or mixed. Only 3 differ, all浏览器toBrowser, which the PR discloses. No Chinese text is registered with two different English values throught. handpair: all 713 English values match the base pairs or baseTEXTwherever base had that Chinese text.- Deleted entries: I searched all 628 deleted
TEXTkeys acrosssrc/,research,evaluation,configs,scriptsand the installedlexbench_webfetchpackage, 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 throught. - 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.jsonis in package data and inrenderer_sha256. - Hash-bound files: none in the diff.
tests/goldenis 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:
tandpairare small and are the minimum needed while the post-renderLocalizerstays. 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.
|
Review round 1: Fixed
Disputed: none. |
There was a problem hiding this comment.
✅ Re-review complete · b3e619a
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
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_presentationonly calls itif not record.get('diagnosis').refresh_local_presentationpasses the loaded records straight togenerate.build_report --local-auditkeeps a savedfailure-classification-v2diagnosis.
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:
-
Restore these 35 exact entries to
report-translations.json, with their base English:;同时返回非目标资源:,接口鉴权失败,正文提取为空,浏览器执行上下文中断,调用截止时间,内容核验,输出文本解码损坏,直接返回依据,超过端到端预算,已返回文件字节,但格式、长度或目标 SHA-256 校验未通过;逐项证据见文件交付详情,文件校验未通过,正文范围不完整,正文不足,有效条目不足,加载 / 提取超时,方法禁止跨站跳转,方法空页规则拦截,方法安全限制,未命中登记的目标资源。,没有可验证的原文件字节;文字或链接不能替代文件,源站访问,源站拒绝该次访问,未取得原文件,服务取页失败,服务取页,缺少关键信息,缺少目标资源,资源核验,取页连接失败,取页返回 404,返回非目标资源,源站要求验证码,任务规则未满足,服务未披露更细原因;不能仅凭该错误归责源站或服务内部,不支持输入类型 -
Add one test next to
test_refreshed_log_route_translates_saved_chinese_header_without_a_prior_render, withTEXTreset to the JSON contents. It should translate saved diagnosis strings withoutdiagnosehaving run. -
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,pairandreport_textkey resolves inmessages.json, and placeholders match the supplied values. No Chinese text maps to two different English strings throught, so registration order cannot change a translation. - English: the only English that differs from a base
TEXTentry is浏览器, fromWeb texttoBrowser, which the PR discloses. - Deleted entries: all 625 have a registering
tsite. A literal search ofsrc,research,evaluation,configs,scripts,docsand.agentsfinds 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.jsonis in package data andrenderer_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.pyandtest_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.
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 insrc/harness/web_fetch/messages.json(2,118 messages).h(zh, en),x if english else y,model_text,bilingual_text) now reads the catalog directly.Localizerstays. 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 pipelinetreturns the Chinese text and declares its English in the existingTEXTtable, so no new lookup is added.report-translations.jsonand theLocalizerregex 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 runningt.t:tadds 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.jsonis added to package data and torenderer_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.jsonadds 2,118 lines andreport-translations.jsonis unchanged at 3,409.report.pyreport_i18n.pyreport_components.pyreport_explainer.pyfailure_diagnosis.pyreport_diagnostic.pyreport_check.pyreport_resources.pyDoes 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
tregisters English only in the process that runs it. Text saved by an earlier build reaches the English pass without atcall: diagnoses stored inresults.jsonlbyrescoring.py, reused byreport_build.py, and log headings rebuilt byrefresh_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 93failure_diagnosis.pystrings. A build that runsdiagnoseshows those in English; a build that reuses a saved diagnosis shows Chinese, as on base.What remains of #99, and why
report_i18n.py,report-translations.json: theLocalizer, 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:data-kindvalues and filter keys are unchanged, because they are rendered bytes.report_check.py: forbidden-text lists and negative controls match Chinese output on purpose.参考状态:未提供完整参考。onen/datasets/*renders in Chinese today. Eighttcalls inreport.pycarry 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.Test plan
Run at this head unless noted.
tests/test_golden_reports.py: 17 passed,tests/goldenunchanged, 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.ruff checkand--select F,TID252,B023,B905): pass.tests/test_optional_reports.pyfails locally on main too, because its child process imports another checkout. Linux CI is the gate for it. The wider-kreport run from earlier heads was not repeated.test_chinese_value_keeps_the_base_english_on_the_dataset_pagebuilds a real English dataset page throughrunner.run_evaluationandbuild_report, with anamed_linkcontract and version 3 body rules. It failed beforetstopped 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_shrinkcounts catalog values fully translated by a freshTEXTloaded 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_diagnosedpasses saveddiagnose()output throughlocalize_htmlin a new process. It failed before the table was restored with源站拒绝该次访问,源站访问,直接返回依据and未命中登记的目标资源。on the English page.test_report_readingbuilds its samples withtand adds a regression test for an escaped error message;test_renderer_identity_covers_loaded_assetsalso covers the catalog.test_report_presentationis unchanged from base.