Repository navigation
refactor(web-search): split build into named typed stages - #223
Merged
Merged
Conversation
lanyue-llk
commented
Nov 4, 2026
lanyue-llk
left a comment
Contributor
Author
There was a problem hiding this comment.
Independent review, round 1
Reviewed head a9fdd8b4 against base 332084e5. One finding (P3). The behaviour-preservation claims hold.
Findings
P3: cohorts is annotated as Iterable[Any], but the code needs a sized collection. src/harness/web_search/report.py:531, :624, :1537, :1604
- Problem:
_load_collectiontestsif cohorts:(line 534) and_write_manifesttestsnot cohorts(line 1581). Both rely on truthiness, which an iterator does not provide. The annotation this PR adds says any iterable is acceptable, so it misstates the contract. The behaviour itself is unchanged, and the CLI passes a list. - Reproduced on this head:
build(out, source=src, cohorts=iter(()))setscollection_receipt_sha256tonull, whilecohorts=()records the hash.build(out, cohorts=iter(()))raises "Additional cohorts require a primary source".
- Fix: annotate all four sites as
Sequence[tuple[str, Path]]. That is the shapeload_report_runsunpacks andmainbuilds. Then drop theIterableimport.
What I verified
- AST: my own comparison of the old and new modules shows
buildis the only changed function. All other definitions and module statements are identical and in the same order, and the only added statements are the three imports. I read all 817 old lines against the new stages and found no reordering of side effects. That covers theindependent-review.jsonwrite before the assessment profile, the bundle order, route removal before the public calls, thereason_labeloverride after the inventory row, and the review and relevance rebinding. aggregatededuplication:aggregateincore.pyis pure, andoverview_summaryandall_call_summaryare only read. The four dropped calls were never read. The all-call failure timing in the PR body is slightly understated: the failure now comes before the public bundle writes and before old routes are removed, not just before pages. That is harmless.- Independent differential: I wrapped
buildwith a pytest plugin and ran all oftests/web_searchon base and head, with builder identity pinned andrenderer_sha256and temporary paths normalized. That gave 166 paired builds and 3,391 files, with the same return values and exceptions. 15 builds differed, all in JSON fields:manifest.jsonandindependent-review.jsonhashes that derive from a review frozen against the fixture's first manifest, which carries the renderer hash.- Timestamps and receipt hashes from live-collection tests.
- No route file differed. The pin made 71 of the 520 tests fail on both trees because they assert builder identity. Those builds were still compared up to the point of failure.
correctionwas not exercised, so I checked that branch by reading it.
- Snapshot: only
manifest.jsonmoves intests/golden/web-search.json. This does not meet the issue's literal "snapshots do not move", but it is disclosed and unavoidable while the manifest records the file's own hash. All six earlier edits to this file since the snapshots were added moved that snapshot too. A direct old and new build of the same fixture differs only inrenderer_sha256,browser_evaland the bundle hash of the version file, plusbrowser-eval-version.jsonitself. - Frozen bindings: none found.
- The file's SHA-256 and blob ID do not appear in Git at base.
renderer_sha256is written once in the Web Search code and never read there.producer_sourcesinweb_search/visual.pycoversvisual.py,pages.pyand the sharedreporting/visual.py, not this file.- A review frozen with base code builds and passes
checkunder this head, because the review'ssource_bindingshash of the manifest is not compared with the current manifest.
- Tests and lint at this head:
tests/web_search: 520 passed.- Golden, presentation contract, UTF-8, privacy, entrypoint precedence and language suites: 265 passed, with the correct
PYTHONPATH. That includes the five failures the PR body attributes to its local import path. - Both ruff gates pass.
- Scope and rules:
Closes #218is accurate.buildis 36 lines and the longest stage is 72. There are no aliases or parallel implementations, no evidence files changed, and new text is in English. - CI at
a9fdd8b4: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" all pass.
Contributor
Author
|
Review round 1: fixed the one finding, nothing disputed.
|
lanyue-llk
commented
Nov 4, 2026
lanyue-llk
left a comment
Contributor
Author
There was a problem hiding this comment.
Independent review, round 2
Reviewed head fc1a7d2d against main 332084e5, which is still the current main. No defects found.
What I verified
- Round 1 fix: all four
cohortssites now useSequence[tuple[str, Path]], the shape thatload_report_runsunpacks andmainbuilds, and theIterableimport is gone. The commit changes only those annotations and one line oftests/golden/web-search.json. - Code against the old function: I read every stage against the old
build.- Write order, route order, comparison chapters before
index.html, andreason_labelbeing overridden only after the inventory row is built all match. - A symbol-table check found no stage reading a module global that shares a name with an old
buildlocal, so no variable was silently rebound.
- Write order, route order, comparison chapters before
- Summary deduplication: an AST check confirms the old
summarywas read only in the core table and the oldphysicalonly in the successful-call table.- At those points they held
aggregate(scoring_rows(profile, overview_rows))andaggregate(rows), which are exactlyoverview_summaryandall_call_summary. aggregateis pure. After each of 188 edition writes undertests/web_searchand the golden tests, recomputing both summaries gave equal values, including 2 editions where the overview was narrower than all rows.
- At those points they held
- My own old/new differential (not the author's scripts): I wrapped
buildso each call also ran the basereport.pyfrom the same pre-state, then compared the file trees, return value and exception, withrenderer_sha256and temporary paths normalized.- 169 of 171 builds were identical, 2 of them raising the same error in both versions.
- The builds covered zh and en editions, authored content, review and relevance.
- The 2 mismatches come from the harness, not the code.
test_projection_only_publishes_metadata_for_materialized_callsandtest_content_hash_binds_rendered_snapshot_when_source_changes_during_buildpatch helpers on the new module only, so the base copy ran unpatched. Both tests pass on this head. These are the same two the PR excludes from its in-process run. I did not repeat its separate sequential comparison for them. - These builds use synthetic fixtures; no real evidence was rebuilt, as the PR also states.
- Snapshot: only the
manifest.jsonline moves intests/golden/web-search.json, and the differential's normalized comparison shows no other change. I accept this as the one unavoidable move: the manifest records the hash ofreport.py, and the six earlier edits the PR names (#212, #192, #177, #163, #146, #137) appear in that snapshot's history. It is explained in the PR. - Frozen bindings:
git grepat base finds neither the file's SHA-256 nor its blob ID. Undersrc/harness/web_search/, the only reference torenderer_sha256is the line that writes it, and I found no reader of the Web Search value elsewhere. The other uses areweb_fetch's own separate value.configs/report-templates.jsonandsource_policy.pyrecord only the path. - Size and scope claims: old
buildwas 817 lines, newbuildis 36, and the longest stage is_default_home_bodyat 72. The diff touches only those two files.Closes #218is accurate: #218 asks only for this split, and #104's other functions stay with #104.
Tests and CI
- Lint: both ruff gates pass.
- Local tests:
tests/web_searchandtests/test_golden_reports.pygave 536 passed. The language, presentation, UTF-8, privacy and checkout-entrypoint targets, run with the golden tests, gave 265 passed. - CI on
fc1a7d2d: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks", "Python 3.11" and "OCR dispatch" all pass. The PR is mergeable and clean.
lanyue-llk
added a commit
that referenced
this pull request
Nov 4, 2026
… pairs The stages test cohorts for truthiness, so an iterator would change behaviour. The manifest records the renderer hash, so one snapshot line moves.
lanyue-llk
force-pushed
the
refactor/web-search-report-stages
branch
from
November 4, 2026 04:40
fc1a7d2 to
0e032bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
Closes #218
Part of the #104 and #87 refactor series; the other functions listed in #104 stay with that issue.
Summary
buildinsrc/harness/web_search/report.pywas 817 lines. It is now a 36-line sequence of named, typed stages in the same file: validate options, load inputs, write the public bundle, write each language edition, write the manifest, select the entry and run the evidence check. The longest stage is_default_home_bodyat 72 lines.ReportInputscarries the loaded evidence andReportEditioncarries one language's prefix, navigation and notice; both are frozen dataclasses.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:
aggregatecalls, and the results of four were never read.ReportInputs.overview_summaryandall_call_summaryreplace them.aggregateis pure, so output does not change. If it raised on malformed rows, the all-call failure would now happen before any page is written rather than after.pagebecame the module-level_write_page, and stages bind it withpartial.hit_keymoved to_known_page_metric;reason_labeland dataset rows moved to_reason_labeland_dataset_row.dsloop became a list comprehension. A repeated-calls block became an early return in_physical_calls_detail.All other functions and module-level statements are AST-identical, apart from the three new imports.
One snapshot line moves
tests/golden/web-search.jsonchanges on one line,manifest.json. This is unavoidable: the manifest records the SHA-256 ofreport.pyitself asrenderer_sha256, and the last six edits of this file each changed one line of this snapshot (#212, #192, #177, #163, #146, #137). The other 18 Web Search routes are unchanged. Replacing the new hash with the old one in the rebuilt manifest gives exactly the old snapshot digest,7df3bd51..., so that field is the only difference.Frozen bindings: none found
git grepfinds neither the file's SHA-256 nor its Git blob ID.configs/report-templates.jsonandsrc/harness/reporting/source_policy.pyrecord only the path, which does not change.tests/web_search/test_runner.pyasserts that.implementation_sourcescoverslexbench_websearchonly.renderer_sha256is written per build. Nothing in the repository reads it back, so existing reports keep verifying.Report instances outside Git were not available to inspect, but the only binding to this file a build writes is that unread field.
Test plan
Run locally on macOS with Python 3.11 from the shared locked environment.
tests/test_golden_reports.pypasses with the one-line change above.tests/test_golden_reports.py,tests/web_search,tests/test_report_presentation_contract.py,tests/test_explicit_utf8_io.py,tests/test_public_tree_privacy.py,tests/benchmarks/test_checkout_entrypoint_precedence.py: 660 passed, 5 failed. The failures are a local setup problem: the import path was set with pytest's-o pythonpath, which subprocesses do not inherit, so they import the shared environment's older installedharnessor none. They aretest_rubric_import_and_judge_help_are_cold_offline,test_report_builds_are_byte_identical_under_an_ascii_localeand threetest_lexbench_report_builds_under_an_ascii_localecases. The offline-import test failed the same way before the split. CI covers all five.tests/test_source_language_policy.py,tests/test_public_report_language.py,tests/test_report_language_routes.pyandtests/test_report_languages.pypass.ruff check --config 'include=["*.py"]' --select F,TID252 .andruff checkpass.buildcall made bytests/web_searchran on a copy of the old module and on the new one, on the same inputs in one process. 166 builds (164 complete, 2 fail) plus 1,408 replays across 22 input shapes, each raising from one helper the build called. The output-tree digest, return value, exception type and message, and ordered helper-call trace are identical in all of them, with 94 distinct error messages. The comparison normalizesrenderer_sha256and temporary paths, and leavesaggregateandscoring_rowsout of the trace because of the deduplication above.test_projection_only_publishes_metadata_for_materialized_callsandtest_content_hash_binds_rendered_snapshot_when_source_changes_during_build. A separate old-then-new sequential run included them, and their digests and traces matched._write_method_pagesand_write_performance_pagemakes the differential report a mismatch in both the manifest and the trace.tests/web_search. Of the 28 not reached, 3 are docstrings. The rest are rare branches, such as profile-only builds, identity corrections and unsafe asset paths; they were moved verbatim, and the AST comparison covers them.Limit: these builds use synthetic evidence. No real evidence was rebuilt.
fc1a7d2d: "Tests and static checks" (which includes the five local-only failures above), "Installation and packaging" and "Rendered reference and report checks" pass.