Repository navigation
refactor(lexbench): split report validate into named typed checks - #232
Conversation
There was a problem hiding this comment.
Independent review, round 1
Reviewed head be6dcd27. No P0, P1 or P2 defects found. There are two P3 inaccuracies in the PR description; neither affects behaviour.
Findings
P3, src/harness/lexbench/verification.py:1228 (main). The ruff format pass also collapsed the --profile parser.add_argument call in main onto one line. The description says the formatting only touched the new checks, that the rest of the file keeps its formatting, and that the command-line entry is not part of this change. The AST is unchanged, so this is harmless. Suggested fix: restore the three-line form, or say in the description that this one line changed. Everything else after validate is byte-identical.
P3, PR description, "Across all of these runs, 95 of the 132 constant rejection messages were reached". The saved results give 96 of 132, leaving 36 unreached. locale shell is listed as an unreached example, but the fixture seed 31 result records it as reached. The summary appears to have been computed before that result was written. Suggested fix: change to 96 and 36, and use a different example. The error understates coverage, and the statement identity covers these messages either way.
What I verified
- Statement identity. My own inliner, separate from the draft's script, expands every stage back into
validate. All 84 top-level statements match the base function, and the nested helper body matches. All 132 constant messages are still present. - Scope changes the AST comparison cannot see:
- Each stage's parameters match the names passed by its caller.
- No stage reads a module global where the old function read a local, and no stage rebinds a parameter.
- A definite-assignment pass finds no stage local that relied on a value left over from another stage.
- Stage locals that would have overwritten a caller's variable in the old shared namespace are rebound before the caller reads them (
summary,mode), or are returned to the caller (layouts,summary). - Conditionally bound variables (
profiles,summary,method_id,candidate) are only passed inside the branch or loop that binds them, so no newUnboundLocalErroris possible.
- Module-level changes. The only differences before
validateare theAny, NoReturnimport, theJsonandModeCallaliases, and annotations onnearandfail. Annotations are lazy underfrom __future__ import annotations. Every stage parameter and return is annotated, and the return types match what the stages return. - My own differential. Old and new
validateran on the test fixture with a fresh seed: 338 mutated models (delete, null, empty, bump or retype) out of 1,495 planned, cut off by a time budget, plus 50 file removals or truncations. Outcomes: 37 accepted, 242ValueError, 109 other errors, 69 distinct messages, 0 mismatches. - Reported differential numbers. The saved results match the table (91/3,322, 278/27,419 and 1,521/11,155, with the same outcome counts and 0 mismatches), and the 834 earlier inputs also match. The table is correctly described as a partial shuffled sample.
- Frozen bindings. The base file's SHA-256 appears in no tracked file and no JSON, JSONL, Markdown or text file in the data home on this machine. The path appears in the
harness_filesmap of exactly the three pre-call contract versions described. No code undersrc,scripts,tests,evaluationorconfigsreadsharness_files, which is consistent with PR #211. No contract or evidence was changed. - Scope. The PR meets each item in #219, so
Closes #219is justified. The split stays in the same file, no compatibility alias or parallel implementation was added, and only this one file changed. - Tests and lint at this head:
tests/test_golden_reports.pywith the Lexbench tests: 156 passed. Golden snapshots are untouched.tests/test_explicit_utf8_io.pyandtests/test_moli_report_render_contract.py: 64 passed.- Both
ruff checkgates pass.
- CI at this head. "Tests and static checks", "Installation and packaging", "Rendered reference and report checks", and "Python 3.11" all pass. Main has moved on by #228, which does not touch this file.
be6dcd2 to
b81e999
Compare
|
Round 1 review findings, both fixed. Nothing disputed.
The branch is rebased onto main with #228, which does not touch this file, so the split commit is now bd09027. The description also notes which evidence predates the formatting restoration, and its test plan lists the rerun on the current head. CI fix added after this reply was first posted: "Tests and static checks" failed twice on the rebased head, in |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Head reviewed: 7bcb275. No P0, P1 or P2 defects found. There is one P3 finding, which does not block this PR.
Finding
P3: src/harness/web_fetch/providers/headless.py:998 and tests/test_native_cdp_port.py:347. The new comment and the Linux-only test probably describe a different state from the one CI hit.
- Problem: The fix itself is sound. However, in a fully exited, unreaped child, the kernel has already released the namespaces, so
open('/proc/<pid>/net/tcp')should raiseFileNotFoundErrorbeforelistdirruns. If so,test_exited_unreaped_server_is_not_reported_as_listeningpasses with or without the fix. - What CI showed: The reported
PermissionErroron/proc/<pid>/fdmeansnet/tcpopened successfully. That points to a process partway through exit: memory already released, so root ownsfd, but namespaces still present. - Confidence: This comes from reading the kernel's behaviour. I could not run it on Linux here because no Linux host or container was available.
- Coverage: The two mocked denied-lookup tests do guard the fix, and the PR description already says the cause was not reproduced.
- Suggested fix: Reword the comment to "a process that is exiting", and keep or drop the Linux test knowing that it does not exercise this branch.
What I verified
Split of validate
- I reran the statement-identity script against base 0051691. All 84 top-level statements are identical and the nested helper body is identical. The only module-level additions are the
typingimport,JsonandModeCall. - That script cannot see scope changes caused by moving statements into functions, so I checked those separately with
astandsymtable:- No check rebinds or mutates one of its parameters.
- No name in a check resolves to a module global where the old function had a local of that name.
- No name is undefined.
- A definite-assignment pass over all 37 checks and
validatefound no read that could have relied on a stale local left by an earlier stage. - Names assigned more than once in the old function (
summary,chart,modeand others) reach each check with the same binding.
- All 37 checks and
validatehave annotations on every parameter and return. - Everything from
validate_releaseto the end of the file is byte-identical to the base, so round 1's--profilefinding is fixed.
PR description
- The results for fixture seed 31, macOS seed 21 and minimal seed 21 match the table: inputs, planned counts, accepted,
ValueError, other errors, 0 mismatches and distinct messages. I did not rerun the differential. - Frozen bindings claim:
- The base file's SHA-256 is in no Git-tracked file and in no JSON, JSONL, Markdown or text file under this machine's data home.
- The only structured binding of the path is
harness_filesin one pre-call contract and its two later versions, with a different, older hash. - No code under
src,scriptsortestsreads that field. - The only other JSON mentions are prose in two private GitHub text backups.
CDP fix
- Treating
PermissionErroras "listener not proved" fails closed: no connection is made, and the poll loop still sees the exit or hits the deadline.
Scope and rules
Closes #219holds: the split is in the same file, messages and order are preserved, and the before/after proof is present.- No evidence or profile changed, there are no aliases or parallel implementations, and the new text is in English.
Checks run on this head
ruff check(both invocations) passed.tests/test_golden_reports.pyandtests/test_native_cdp_port.py,-n 2: 35 passed, 1 skipped (the Linux-only test). Golden snapshots were not regenerated.tests/test_lexbench_verification.py,test_lexbench_cli.py,test_explicit_utf8_io.py,test_moli_report_render_contract.py,test_moli_resource_matrix.pyandtest_lexbench_report_runtime.py,-n 2: 141 passed, 5 subtests passed.- CI on this head: all checks pass, including "Tests and static checks" and "Installation and packaging".
|
Round 2 review finding, fixed in 1f7ecdc. Nothing disputed.
The new wording rests on reading kernel behaviour. It was not run on Linux here. The change is comments only, and the PR description now uses the same wording. |
There was a problem hiding this comment.
✅ Re-review complete · 1f7ecdc
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 3
No defects found at head 1f7ecdc. The two earlier findings are fixed, and I am raising no new ones.
What I verified
Statement identity (my own script, not the author's).
- I inlined all 37 checks and the nested helpers back into
validateand compared the result with the base function's AST. All 84 top-level statements are identical. - The body of
_resource_documentis identical to the nestedresource_document, which was only called from inside the Linux block. near,fail,validate_release,verify_evidence,verifyandmainmatch once annotations are ignored. The only module-level additions are thetypingimport and theJsonandModeCallaliases.- Two altered copies, one with two checks swapped and one with a changed message, both failed this comparison.
Differences that inlining cannot show. I checked these separately:
- Every call-site argument is a plain name, so no expression is evaluated earlier than it was in the base.
- No helper has an early return, rebinds a parameter, has an unused parameter or reads a local before assigning it.
- No variable written inside a check is read by a later check unless it is returned. Only
cost_by_id,fullandcommoncross between checks this way, and each is returned. I ran this analysis at the top level ofvalidate; for the checks nested inside_check_platform_resourcesand the mode loop, I relied on the parameter and local-read checks above and on reading the code.
PR description.
- The table matches
result-fixture-31.json,result-macos-21.jsonandresult-minimal-21.json, all with 0 mismatches. The earlier 834-input total also matches the saved draft results. - The line counts and the check count are correct. The base file's hash appears in no Git-tracked file, and nothing under
src,scriptsortestsreadsharness_files. - I did not rerun the differential, the negative controls on the author's script or the data-home hash search.
Scope. Issue #219 asks for named typed checks in the same file, the same messages and order, a before/after run on altered inputs, and a statement on frozen bindings. All four are present, so Closes #219 holds. The runs are a sample cut off by a time budget, and the description says so. The statement identity covers the rest.
CDP fix.
- With
PermissionErrorremoved from both handlers, both denied-lookup tests fail. - With the fix in place, a lookup that stays denied ends in the existing startup
TimeoutErrorrather than a connection, so it fails closed. - The Linux-only test is skipped on macOS, so only CI runs it.
Local runs on macOS.
tests/test_golden_reports.py,tests/test_lexbench_verification.py,tests/test_native_cdp_port.py,tests/test_explicit_utf8_io.pyandtests/test_data_home.py,-n 2: 132 passed, 1 skipped. Golden snapshots are unchanged.- Both
ruffcommands pass.
CI at 1f7ecdc. All checks pass, including Tests and static checks, Installation and packaging, and Rendered reference and report checks. The base is still the newest main.
Issues
Closes #219
Part of #104 and #87
Summary
validateinsrc/harness/lexbench/verification.pywas one function of about 780 lines. It is now a 56-line sequence of 37 named, typed checks in the same file, plus one module-level helper (_resource_document, previously nested). The only other additions are theJsonandModeCallaliases and annotations onnearandfail.Check bodies are moved, not rewritten, so every rejection keeps its message and order. Rendered reports do not change: the golden route hashes are untouched.
verify_evidence,validate_releaseand the command-line entry are not part of this change, andverify_evidenceremains long (178 lines).CI fix outside the split
7bcb275 is a separate fix that this PR needs to pass CI; it does not touch
verification.py. After the rebase onto #228, "Tests and static checks" failed twice in a row ontests/test_native_cdp_port.py, in different tests, each withPermissionError: [Errno 13]on/proc/<pid>/fdfrom_linux_listens_on. Both tests have a server that exits while it is being polled. Main passed the same tests on its own run, so the failure depends on timing.The likely cause is that Linux makes root the owner of that directory for a process that is exiting, while its socket table can still be read. That reading comes from kernel behaviour. The lookup caught only
FileNotFoundErrorandProcessLookupError, so the error ended the call instead of letting the poll loop see the exit.PermissionErrornow means the listener is not proved, so no connection is made on that basis. This was not reproduced on Linux locally; CI is the Linux check.Frozen bindings
Nothing current binds this file's bytes, so the issue's stop condition does not apply.
harness/lexbench/verification.pyis named in theharness_filesmap of one Web Fetch pre-call contract and its two later versions, with a hash from an earlier revision. As PR fix(lexbench): write chart SVGs as explicit UTF-8 #211 established,harness_filesin private pre-call contracts is a point-in-time record of the source tree, not a frozen binding. No code undersrc,scriptsortestsreads that field, and the contracts were not edited.Before/after evidence
Statement identity. A script inlines every check back into
validateand compares the result with the base function's AST. All 84 top-level statements are identical, the nested helper body is identical, and the only module-level differences are the three additions above (annotations ignored). Because this compares every statement, it also covers the rejections the runs below did not reach. This is the strongest evidence here and was rerun on the final file.Differential runs. Each altered input ran through both versions, once normally and once with
failrecording and continuing, so later checks also ran. A run compares the outcome, the failure sequence and a trace of calls and file reads. Inputs alter the model, report files or language metadata.ValueErrorThese runs were cut off by a time budget, so they are a shuffled sample and not the full plan. Limits to read them by:
main. Formatting left the AST unchanged.fixed functional methodsanddenominator. The accepted evidence is therefore 8 inputs in this table.highlight contract,correction scopeandunsafe evidence target.Negative controls. Four altered copies of the new file were all caught by both the differential and the statement comparison: two checks swapped, one message changed, one check dropped, and two checks swapped inside a check.
Test suite comparison. Running the Lexbench tests with both versions called on every
validatecall gave 113 calls and 0 differences.The negative controls and this comparison ran on the commit before the last formatting restoration in
main, and gave the same results on the draft's bytes. That restoration leaves the AST unchanged.Review changes to the draft
Reviewed as someone else's draft and rebased onto current main. The only edit is
ruff formatapplied to the new checks, which fixes over-long lines the move left behind. The rest of the file keeps its existing formatting.Test plan
Run locally on macOS with the locked environment. CI covers the current head.
pytestontests/test_golden_reports.py,tests/test_explicit_utf8_io.pyand the Lexbench and Moli report, resource and verification tests,-n 2: 260 passed, 26 subtests passed. Golden snapshots were not regenerated.tests/test_moli_provider.py,tests/test_golden_reports.pyandtests/test_data_home.pyon the rebased head,-n 2: 106 passed, 63 subtests passed.tests/test_moli_provider.pyrun on the draft commit failed 1 subtest,test_answer_capacity_does_not_limit_native_resource_downloads, with a provider time budget timeout while other work loaded the machine. It passed alone and in the run above. That test exercises the provider, not this file.ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: all checks passed on the current head.tests/test_golden_reports.py,tests/test_explicit_utf8_io.pyand the Lexbench and Moli report tests,-n 2: 218 passed. The statement identity script was rerun, and the code aftervalidateis byte-identical to the base.tests/test_native_cdp_port.py,tests/test_explicit_utf8_io.pyandtests/test_golden_reports.pywith the CI fix,-n 2: 97 passed, 1 skipped. The skipped test is the Linux-only unreaped-child test, which only CI runs. It probably does not reach thePermissionErrorbranch, because a fully exited child likely has no socket table left; the two mocked denied-lookup tests guard that branch. With the fix removed, both denied-lookup tests fail withPermissionError.ruffcommands passed.