Repository navigation
chore(lint): fix B023 and B905 and widen Ruff include per package - #241
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Reviewed head 45c7e117 against main at 8f2232b7.
Findings
P1: src/harness/web_fetch/report.py:3363 and :3526. A real late-binding bug is only half fixed, and the PR says none exists.
generate_webmainbench defines the local function scope(text) at line 3326. Inside the for english loop, line 3526 rebinds the same name to a dict: scope=anomaly_review['scope']. This is what B023 flagged on h. build_webmainbench_report loads research/webmainbench-anomaly-review.json and always passes it, so the branch runs on every real build.
I rendered sample_report_inputs with anomaly_review={'cases':[],'scope':{'signal_triggered_results':0,'distinct_cases':0}}:
| Commit | include_english=False |
include_english=True |
|---|---|---|
Base 8f2232b7 |
TypeError: 'dict' object is not callable (report.py:3528, the next h() call) |
same TypeError at 3528 |
Head 45c7e117 |
passes | TypeError: 'dict' object is not callable (report.py:3364, first h() of the English pass) |
The new default h=lambda zh,en,scope=scope,english=english:... keeps the function for the first pass. On the second pass it captures the dict left behind by the first pass, so the English build still crashes. No test or golden passes anomaly_review to this function, so CI stays green.
This also contradicts the PR body: "Real bugs: no late-binding bug" and "behavior does not change". The issue asks for each real bug to be named.
Suggested fix:
- Rename the dict local to
anomaly_scopeat line 3526 and at its two uses in the f-strings at line 3528. - Restore
h=lambda zh,en:scope(en if english else zh), or keep onlyenglish=englishif B023 still needs it. - Add one test that calls
generate_webmainbenchwithanomaly_reviewandinclude_english=True. - Name this bug in the PR body's real-bugs list.
Verified, no defect found
- Lint: all three gates pass on the head:
F,TID252,F,TID252,B023,B905and plainruff check. The diff adds nonoqa. strict=counts: 74strict=Trueand 5strict=Falsein the added lines, matching the PR body.strict=Truesites insrc/: I read each one. Lengths are equal by construction, or guarded by an earlier length check orlen()==len()short-circuit, or the site is already inside a validator that raisesValueError. Theevidence-comparezip atreport_explainer.py:773has exactly twoarticlepanes.strict=Falsesites: all are pairwisezip(x, x[1:]).- Other B023 default-argument sites in
src/: I found no other rebinding between definition and call, and no caller passes an extra positional argument. This includesre.subcallbacks,page.on('pageerror', ...)(one event argument) and thechecker(case, binding)call inrescoring.py. - Other helper swaps:
socket.timeoutis an alias ofTimeoutErroron Python 3.11, and thelambdatodefconversions and import moves are equivalent. - Hash-bound files: every listed file is byte-identical. The only
src/lexbench_webfetchedit isannotation_revisions.py, which is not inSCORING_SOURCE_FILESorcode-migration.json. The base SHA-256 of none of the 110 changed files appears in any tracked file, or in the local evidence JSON sampled (first 20,000 files under 2 MB; that search had a time limit, so it may not have finished). - Golden snapshots: only the
manifest.jsonroute oftests/golden/web-search.jsonchanges, as explained in the PR. - Local tests:
test_golden_reports,test_webmainbench_report,test_lexbench_cli,test_lexbench_report_runtimeandtest_public_report_language: 120 passed. - Scope of
Closes #89: the narrowed scope is otherwise met. The left-out packages are listed with reasons, andmake lint-checkenforces B023 and B905 across the repository. - Over-design: nothing to report.
- CI: all checks on the head pass, including "Tests and static checks" and "Installation and packaging".
|
Round 1 review: Fixed: the Disputed: nothing. |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Reviewed head bb347432 against main at 8f2232b7. This includes the fix for the scope crash reported in the earlier review of 45c7e117. I also did a trial merge with the latest main (23239677).
No P0, P1 or P2 defects found.
Findings
P3: src/lexbench_webfetch/annotation_revisions.py:123. This one-line edit has no effect on lint.
The PR adds B905 to the per-file ignore for src/lexbench_webfetch/*.py, so this strict=False isn't needed to pass the gate. It is also the only edit in a package the PR otherwise leaves out, while 15 other B905 findings there stay in place. The behaviour is unchanged, and the edit is disclosed in the PR body. The file isn't in SCORING_SOURCE_FILES or code-migration.json, and PR #239 doesn't change it.
Suggested fix: revert the line and drop the matching note from the "Left out" table, so the package has no edits. This is optional.
Verified
scopefix:test_anomaly_review_renders_in_both_languagesfails withTypeErroron thereport.pyfrom both8f2232b7and45c7e117, and passes on the head.scopeis no longer rebound ingenerate_webmainbench.- Lint:
F,TID252,F,TID252,B023,B905and plainruff checkall pass. An isolatedB023,B905run finds 35 findings (16 B023, 19 B905), all in the listed hash-bound files. This matches the PR body's counts. strict=Trueinsrc/: I read every site. Each has equal lengths by construction, or an earlier length check or equivalent guard, so none adds a new failure on valid input. The one changed outcome is the matched-latency check inwebmainbench_report_check.py:810, which now rejects a row with too few cells. This matches the gap the PR describes.strict=False: all are pairwisezip(x, x[1:]).- B023 default arguments: an AST pass over every closure changed in
src/andtests/found that each bound name has one assignment, made before the closure, so there is no stale or unbound capture. Therescoring.pylambda is called within its iteration.page.on('pageerror', ...)receives one event argument. - Other changes:
socket.timeoutis an alias ofTimeoutErroron Python 3.11. Thelambdatodefconversions, the import moves and the removedsumparentheses are equivalent. - Hash bindings:
- Every file named in the "Left out" table, including
lexbench/charts.py, is byte-identical to the base, exceptannotation_revisions.pyas disclosed. - The only
src/lexbench_*change is the line above. - I read the source-hash code in
collection_implementation,capture_source_identity,rescoring.pyandrenderer_sha256. The PR's description of the hash effects holds for the ones it lists. - No tracked file contains the base SHA-256 of a changed file.
- The entries in
research/initial-reference-audit.jsonforscripts/audit_initial_references.pywere already stale on the base, so this PR did not cause that. - I did not scan local evidence, so this covers tracked files and code only.
- Every file named in the "Left out" table, including
- Coverage claims: every top-level
src/harness/*.pymodule is now covered. The left-out list matches the tree, apart fromsetup.py, which is trivial. - Golden snapshots: only the
manifest.jsonroute oftests/golden/web-search.jsonchanges, as the PR explains. I did not repeat the normalized build diff for the claim thatrenderer_sha256is the single changed field. - Local tests on the head:
test_golden_reports,test_webmainbench_report,test_public_report_language,test_network_preflight,test_headless_review,test_result_review,test_run_certified_benchmarkandweb_search/test_runner: 174 passed. - Trial merge with
23239677: no conflicts, all three lint gates pass and the goldens pass (17 passed). - Scope of
Closes #89: it matches the issue as narrowed in its latest comment. - Over-design: the PR adds no new abstraction. The per-package ignores are configuration only.
- CI: all checks on
bb347432pass, including "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks".
bb34743 to
257d093
Compare
|
Fixes for review round 1:
Locally the lint gate, |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Reviewed head 257d0935 against base 23239677. No defects found.
Round 1's P3 is resolved: src/lexbench_webfetch/annotation_revisions.py is back to its base bytes, and the PR no longer touches src/lexbench_webfetch.
What I verified
strict=True sites. I read the context of each site in src/harness. Each one has equal lengths by construction, or an explicit length or identity check before the zip. In the report.py audit inventory, the rows are built per change. Both templates behind report_explainer.py's .evidence-compare emit exactly two articles. The WebMainBench matched-latency check is the one site where the guard is new, as the PR body says.
strict=False sites. The source sites are pairwise zip(x, x[1:]).
B023 default bindings. An AST pass over the self-named defaults added in changed files found:
- every name is bound before its closure's definition, so none can raise
NameErrorwhen the closure is defined; - two names are rebound later.
report_capabilities.py:120rowis rebound only by a comprehension variable, and thetests/benchmarks/test_pinning.py:381hit was not read beyond the AST result; - callers pass only the original arguments. The
re.subcallback and the Playwrightpageerrorhandler take one argument, so the extra default does not change the call.
anomaly_scope fix. Reverting the rename makes test_anomaly_review_renders_in_both_languages fail, so the test exercises the bug.
Other changes. socket.timeout is an alias of TimeoutError on Python 3.11, so removing it changes nothing. The E731 rewrites and the from error change keep the same behaviour.
Hash-bound sources.
- None of the sources I checked from the PR's table appear in the diff, including
SCORING_SOURCE_FILES,collection_implementation,cohort_reference_hashes, the worker and runner hashes, and the native and visual sources. - The base SHA-256 of every changed file appears nowhere in the tracked tree, so no committed binding moves.
research/initial-reference-audit.jsonnamesscripts/audit_initial_references.py, which this PR edits. Its stored hash already differed from the base bytes, and no code reads that file, so the PR breaks nothing there.
Counts and lint.
ruff --isolated --select B023,B905reports 36 findings (20 B905, 16 B023), split across files as the PR body says.ruff check --config 'include=["*.py"]' --select F,TID252,B023,B905 .andruff checkboth pass.make ci-testsrunslint-check, so CI enforces the new rules.
Tests. tests/test_golden_reports.py and tests/test_webmainbench_report.py pass locally (31 passed), with goldens unchanged and the tree clean. I did not run the full suite locally. The only golden changed is the web-search manifest.json route, and I did not separately re-diff it.
Scope. Closes #89 matches the issue's narrowing comment.
CI. All checks pass on this head: Tests and static checks, Installation and packaging, Rendered reference and report checks. main has moved to d905949c since the base, and GitHub reports the PR as mergeable. CI has not run against that newer main.
Bind every loop-variable closure and make every zip explicit outside hash-bound sources, and enforce both repo-wide in lint-check. Widen the Ruff include to the benchmarks, lexbench, reporting and web_search packages, the top-level harness modules, scripts and examples. Hash-bound sources stay byte-identical through per-file ignores.
…e helper generate_webmainbench rebound its local scope() function to the anomaly review's scope dict inside the language loop, so rendering with an anomaly review raised TypeError. Name the dict anomaly_scope and test it in both languages.
257d093 to
ca885b7
Compare
Issues
Closes #89 (as narrowed in its latest comment)
Summary
Fixes B023 and B905 by hand outside hash-bound sources, enforces both in
make lint-check, and widens the Ruffincludewhere that needed only small fixes.B905 (78 fixed). 74 are
strict=True: the lengths are equal by construction or already checked. 4 arestrict=False:zip(x, x[1:]), which is pairwise and differs in length on purpose.B023 (60 fixed). Each closure now binds the loop values it uses through a default argument, so rendering does not change. The one exception is the real bug below, which is fixed by a rename.
Real bugs: one report crash, one small validator gap.
generate_webmainbenchdefined a localscope()function, then reboundscopeto the anomaly review's dict inside the language loop.hcallsscope(), so rendering with ananomaly_reviewraisedTypeError: 'dict' object is not callablein both language modes onmain.build_webmainbench_reportalways passes one, and no test or golden did. The dict is nowanomaly_scope, andtest_anomaly_review_renders_in_both_languagescovers both languages.name=namedefaults added here looked for a rebinding after the closure's definition. Its two hits are a comprehension variable and a nested function's local, which are different variables.webmainbench_report_check.pychecked matched-latency rows withzip(cells[-3:], expected_times). A row with only two cells was compared as far as it went and could pass.strict=Truenow rejects it.strict=Truesites add a guard but fix no defect I could show.Ruff
includenow also covers:src/harness/benchmarks,lexbench,reporting,web_search, the 14 top-levelsrc/harness/*.pymodules,scripts/andexamples/.from error).src/onsys.pathbefore importing it.make lint-checkgainsB023,B905in its repo-wide pass, so packages outsideincludekeep these two rules.Left out
Hash-bound files, byte-identical in this PR. Findings are suppressed through per-file ignores where needed:
SCORING_SOURCE_FILES, code-migrationafter_sha256src/lexbench_webfetch/*(14 B023 and 16 B905 left)scoring_source_sha256, code-migrationsrc/lexbench_websearch/*(1 B905 left)worker_sha256web_fetch/providers/headless_worker.pyrunner_sha256web_fetch/webmainbench_runner.py,webmainbench_latency_diagnostic.py(1 B905 left),webmainbench_latency_correction.py(2 B905 left)cohort_reference_hashestrajectory_replay/{remote_execution,webarena_replay,retrieval_acceptance,webarena_corrections,remote_runtime}.py,scripts/run_remote_three_method_cohort.pylexbench/reproduction.py, the chart module copied beside it,lexbench/resource_matrix.py,lexbench/resource_profiles.py(I001 left)collection_implementationweb_search/{runner,core,profiles}.py(I001 left),web_fetch/config.py,env_file.py,record_io.py,distribution.py,benchmarks/data.pyreporting/visual.py(I001 left),web_search/visual.py(2 B023 and I001 left),web_search/pages.py,trajectory_replay/webarena_report_visual.pyweb_fetch/native_projection.pyThe 36 B023 and B905 findings left in these files were not audited for real bugs.
Packages left out of
includebecause they need a large rewrite. Approximate findings, not counting E501:src/harness/web_fetch: about 860, mostly one-lineE701/E702statements.tests/*.py: about 1,290.tests/benchmarks: about 230.tests/web_search: about 120..agents: one skill script with 18.src/lexbench_webfetch,src/lexbench_websearch: hash-bound.All of these stay under
F,TID252,B023andB905, apart from the per-file ignores above.Hash effects to check.
pyproject.tomlis part of Searchcollection_implementation, so a Search cohort in flight cannot resume across this commit. That is true of anypyproject.tomlchange.web_fetch/edits changeruntime_source_sha256for future runs only. It is compared between batches of one run, not against the current tree.webmainbench_diagnostics.pyandrescoring.pychange the source hash recorded in future audits. I found no code that compares a stored value with the current file.Golden changes
tests/golden/web-search.json: only themanifest.jsonroute changes. Diffing the normalized builds shows the single changed field isrenderer_sha256, becauseweb_search/report.pywas edited (import sort, UP034). All other routes and all other goldens are unchanged.Test plan
annotation_revisions.pyand rebasing on the newest main: the lint gate,tests/test_golden_reports.pyandtests/test_webmainbench_report.pypass (31 passed), goldens unchanged. The results below were not rerun for that commit.scopefix:tests/test_webmainbench_report.pyandtests/test_golden_reports.py: 31 passed, goldens unchanged. The new test fails with theTypeErrorwhen the fix is removed. The results below were not rerun for that commit.ruff check --config 'include=["*.py"]' --select F,TID252,B023,B905 ., the same command withF,TID252, andruff checkall pass.tests/test_golden_reports.py,tests/test_lexbench_cli.pyandtests/test_lexbench_report_runtime.py: 62 passed.-n 2), run before the last edit that restored the two latency files to their base bytes: 20021 passed, 28 failed, 1 collection error.test_optional_reports(3),test_packaging_hygiene(1),test_public_tree_privacy(1),test_report_software_versions(1),test_hf_inputs(1),test_run_webarena_catalog(5) and thepublic_webarena/test_diagnostics.pyimport error.test_lexbench_cli::test_maintained_template_supplies_every_file_the_report_copiesandtest_lexbench_report_runtime::test_template_source_without_the_template_stops_before_reading_evidence[profile]. Both pass in the worktree. In the copy, the first failed becausescripts/moli_reportexisted there; that directory is not on this branch. I did not find what created it or why the second failed there.test_network_preflight.pyfailures are local only: the worktree sits inside an older checkout whoseevaluation/lexbench-webfetch.jsonis found by the parent-directory walk. They do not occur in the copy or on the base export.