Repository navigation
refactor(harness): share hash and JSON helpers through record_io - #137
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Head reviewed: 6602c7ef. I found no correctness, evidence or CI defects. There are two P3 findings. Both concern how the guard and the PR body describe what remains.
Findings
P3: the guard tells authors to replace a parser that this PR says differs from read_json
tests/test_shared_hash_json_helpers.py:70
_copied_primitive includes read_bytes in the forms it reports as copies read_json. I ran _violations on def f(path): return json.loads(path.read_bytes()), and it returned copies read_json. The PR body says json.loads(bytes) is a different parser, and that is why comparison_audit._read_json and webmainbench_certification._read_json stay. I confirmed the difference: a UTF-16 file parses with json.loads(path.read_bytes()) and raises UnicodeDecodeError in read_json. An author who follows the guard message on a bytes parser would change which inputs are accepted. No control exercises this branch either way.
Fix: limit the set to read_text, and add def f(path): return json.loads(path.read_bytes()) to test_guard_keeps_behaviorally_distinct_helpers.
P3: wrappers with no real difference remain, and the rewrite takes them out of the guard's reach
src/harness/browser_use/review.py:19:_attempts_sha256is onlyreturn file_sha256(path)and has one caller, at line 136.src/harness/trajectory_replay/retrieval_acceptance.py:39,src/harness/web_fetch/webmainbench_correction.py:455andsrc/harness/web_fetch/webmainbench_diagnostics.py:1023: three separatetext_digestdefinitions, eachbytes_sha256(<str>.encode()).
The PR body says the thin wrappers that remain have "a real difference". These do not. The guard flags hashlib.sha256(text.encode()), but it passes the same logic once it is written with bytes_sha256, so these copies now pass unnoticed.
Fix: inline _attempts_sha256. Then either give text_digest one shared owner or call bytes_sha256(x.encode()) at each call site. If you keep them for now, list them in the PR body and correct the sentence.
What I verified
Serialization. I read all 55 removed lines that contain json.dumps, json.loads or their options against their replacements.
ensure_ascii=Trueis kept at all four sites that used the default: rainbond,_proposal_digest,canonical_digestandprofile_digest.allow_nan=Falseis kept inwebarena_state.digestandretrieval_acceptance.digest._case_ids_sha256is unchanged in bytes, becausesort_keyshas no effect on a list of strings.- The Web Search forms with default separators stay as
bytes_sha256(json.dumps(...)), includingcollection_protocol_sha256,normalized_results_sha256andrequest_sha256.
File hashing. I listed all 76 helper definitions the PR removes.
- The optional
Nonebehaviour is kept where the old helper had it, including the tworeport_check.pysites that used the aliased optional helper. manifest_repair._sha256keeps its unlinked and missing-file checks as_checked_sha256.- I listed every
file_sha256andbytes_sha256argument insrc/harnessto catch bytes passed as a path or a path passed as bytes. The twofile_sha256(raw)calls inreport_build.pydo receive paths.
JSON reads and writes.
- No
json.loads(bytes)site moved toread_json. - Every old site that created parent directories now passes
parents=True. - No atomic write became non-atomic:
web_search/core.write_jsonstill usesatomic_write. _cleanis kept inwebarena_report.- No helper name is rebound as a local variable or parameter under
src/harness. publication.json_byteshas no remaining importers or qualified users, so nothing depends on a re-export.
Source-hash bindings.
- The base-commit hashes of the 84 edited
src/harnessfiles appear nowhere in the repository at the base commit, and not insrc/lexbench_webfetch. I did not repeat the data-home search ofevidence,reviews,report-builds,datasetsandimplementations, so that claim rests on the PR's own scan. - I traced the live source checks.
metric_implementation_bindinghashes onlyword_f1andsnippet_check, which this PR does not change.capture_source_identity,remote_executionandwcxb_latencycompare within a run. The latency certifier uses frozen source copies. - The exemptions in
FROZEN_SOURCE_COPIESmatch the checks inlexbench/resource_matrix.py,lexbench/resource_profiles.pyandreporting/visual.py. webarena_state.pyalso hashes its own source, inrule_identity. The file's docstring says existing profiles do not opt in, and the repository search found no binding of its old hash.
Golden snapshots. The only change is the web-search manifest.json route. That is consistent with the PR's explanation, because web_search/report.py feeds renderer_sha256 and is edited here. I did not rebuild the base and branch trees to compare them.
Tests. Each of the 30 removed assert lines in the test diff calls a removed helper name, which is what a rename produces. I did not pair each one with its replacement line.
Scope. "Part of #91" is accurate. Data-home, .env and redaction work is listed as remaining, and the unmigrated copies are disclosed.
Commands run
ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: pass.tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 42 passed.tests/test_webarena_state.py,tests/browser_use/test_report.py,tests/test_webmainbench_assembly.pyandtests/test_wcxb_contract.py: 136 passed.- I did not run the full suite locally. CI is the full-suite gate.
CI
All checks pass on 6602c7ef: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11". The PR is mergeable and its merge state is clean.
|
Review round 1: both findings are fixed, and none are disputed.
Wrappers I kept: three wrappers still only call Local checks at 2f39a06: lint passes. The guard, the golden test and every test file referencing a module edited in this round gave 1,369 passed, 3 skipped, with golden snapshots unchanged. I did not rerun the full suite locally; CI is the gate for that. Newly edited file: |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Head reviewed: 2f39a06ed7d8ce77b12370750057b5cf45ba0c69. Two P3 findings and no correctness defects.
Findings
1. P3: src/harness/trajectory_replay/webarena_report.py:192 and the "Named digest contracts" paragraph in the PR body
- Problem: The PR body says
task_definition_sha256,scoring_revision_history_sha256and_planned_actions_digestare each shared by the code that writes a digest and the code that verifies it. The guard comment intests/test_shared_hash_json_helpers.py:53gives the same reason. This holds only forscoring_revision_history_sha256(assembly.py:495writes,reference_lifecycle.py:1183verifies)._planned_actions_digesthas onesrccaller, the verifier atwebarena_report.py:206. Only tests use it to build fixtures. The writer path setsplanned_actions_sha256fromplan["bound_calls_sha256"](webarena_results.py:461) and does not call this helper.task_definition_sha256has one caller in the repository, atweb_fetch/config.py:50, which computes the current value to compare with the declared one. Nothing insrc,scripts,research,evaluationordocswrites through it.
- Fix: Inline
_planned_actions_digestascanonical_json_sha256(actions)and update its three test uses. It has the same shape as_attempts_sha256, which round 1 removed. Then correct the sentence: keeptask_definition_sha256because it names a public protocol, not because a writer shares it.
2. P3: src/harness/web_fetch/report_build.py:165 and src/harness/web_fetch/reference_lifecycle.py:1045
-
Problem: The semantics table says
sha256(path) if path.is_file() else Noneis replaced byoptional_file_sha256, but both files, which this PR edits, keep that exact form inline:input_sha256 = file_sha256(source) if source.is_file() else Nonereview_hash = sha256(review_path.read_bytes()) if review_path.is_file() else None
The digests are correct, so this is an incomplete migration and not a behaviour bug. The guard does not cover this conditional form.
-
Fix: Call
optional_file_sha256(...)at both sites.webarena_replay.py:91returns a dict rather than a digest, so it can stay.
What I verified
- Digest options: I checked every removed
json.dumpshash input against its replacement.- All have
sort_keysand compact separators, except_case_ids_sha256, which hashes a sorted list of strings, so the bytes are the same. - The five sites without
ensure_ascii=Falsenow passensure_ascii=True. - The two
allow_nan=Falsesites keep it. collection_protocol_sha256,normalized_results_sha256andrequest_sha256keep their non-compactjson.dumpsand change only the hash wrapper.
- All have
- Removed helpers: I read all of them and their call sites, including the round 1 fix commit.
- Optional helpers map to
optional_file_sha256and strict ones tofile_sha256, including both helpers inbrowser_use/report_check.py. parents=Trueis kept wherever the old helper created directories.webarena_report._write_clean_jsonkeeps_clean.- The
_json_file_sha256bytes are unchanged, and it hashes the indented document form throughjson_bytes.
- Optional helpers map to
- JSON read and write:
read_jsondecodes strict UTF-8 and leaves a BOM in place, as the UTF-8read_textform did.write_jsonwrites the same bytes on POSIX. - Source bindings:
- The base-commit hash of all 85 changed
srcfiles has no hit anywhere in the repository at this head. metric_implementation_bindinghashesword_f1andsnippet_check, which this PR does not touch.reporting/visual.py,resource_matrix.pyandresource_profiles.pyare unchanged.webarena_state.load_contractscompares a binding with the liverule_identity(), andwebarena_state.pyis edited here, but no profile underevaluationorresearchdeclaresobserved_state.- My own data-home scan was inconclusive, because a time-limited
grepoverevidence,reviews,report-builds,datasets,implementationsandreference-inputsreturned nothing and may have been cut off. I did not confirm or contradict the PR's data-home scan result.
- The base-commit hash of all 85 changed
- Imports: A static scan of
src,testsandscriptsfound no import of a removed helper from its old module. The attribute reports I reviewed were__file__lookups or local variables that share a module's name; the last 8 of the 48 reports were not displayed, and CI imports and runs the full suite. No new compatibility alias was added. A repository search finds no remaining use of the removed wrapper names checked outside the guard file. - Other wrappers: The remaining thin wrappers I found have a precondition, a keyword option or an input transformation, apart from the two named in finding 1.
Tests and CI
- Local:
- Both ruff gates pass.
tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 56 passed.- Six test files covering the round 1 fix and related modules: 256 passed.
- Golden snapshot: Only
tests/golden/web-search.jsonchanged, by one line. I did not rebuild the Web Search example to repeat the PR's route comparison. - CI at this head: Tests and static checks, Installation and packaging, Rendered reference and report checks, and OCR dispatch all pass. The PR is mergeable.
- Scope: "Part of #91" is the correct label, because the data-home,
.envand redaction work remains.
|
Round 2 findings are fixed. None are disputed.
Digests are unchanged and the golden snapshots did not change. The PR body's semantics table, contracts paragraph and test plan are updated. Local results are in the test plan; CI on the new head is the full-suite gate. |
There was a problem hiding this comment.
✅ Re-review complete · eb30a3d
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 3
Head reviewed: eb30a3ddaea195f34bd282bd27ae274829e2dd58. Two P3 findings and no correctness defects. Both are private helpers that this PR's scope covers and that its guard and PR body do not mention. Round 1 and 2 fixes are correct.
Findings
1. P3: src/harness/web_search/publication.py:35
- Problem:
saveisatomic_write(path, (json.dumps(value, ensure_ascii=False, indent=2) + "\n").encode()). That is the same operation asweb_search/core.write_json(atomic_write(Path(path), json_bytes(value))), and I confirmed the encoded bytes matchjson_bytes. The PR edits this file and sayscore.write_jsonis the atomic writer, anddelivery.pyandexample.pyalready import it, butpublication.pykeeps its own copy. The guard does not flag it. - Fix: Import
write_jsonfromharness.web_search.coreand replace the foursave(...)calls. Writes go to the same paths, so the bytes do not change.
2. P3: src/harness/web_fetch/report_package.py:558, src/harness/web_fetch/report_diagnostic.py:85, src/harness/web_fetch/reference_freeze.py:61
- Problem: Three more private copies remain. The PR body lists neither migrated nor deliberately kept for any of them, and I ran each form through
_violations: it returns[]._archive_identityisfile_sha256written withhashlib.file_digest, behind anexists()check. It is the same digest, and it is a private hash helper of the kind this PR retires.- The nested
encode(value)is exactlyjson_bytes. browser_observation_bytesis exactlyjson_bytes. Its docstring and four call sites may justify keeping the name as a retained-bytes contract, but then it should calljson_bytesor be listed.
- Fix:
_archive_identity: keep theexists()check, because a missing file must still returnNone, and callfile_sha256(path).optional_file_sha256is not the same: it returnsNonefor a directory, where this one raises.encode: usejson_bytesdirectly.browser_observation_bytes: make itreturn json_bytes(observation), or add it to the PR body's kept list with a reason.- Guard: add a rule and paired controls for the
(json.dumps(v, ensure_ascii=False, indent=2) + "\n").encode()helper form and thefile_digesthelper form. - None of these three source files is named by a source-hash check I could find. All three are under
web_fetch, so they already fall within theruntime_source_sha256note in the PR body.
Inline, non-helper uses of these forms remain elsewhere, including providers/headless.py:497, providers/moli.py:279 and many (json.dumps(...) + "\n").encode() expressions. The PR's scope is named helpers, so I am not raising those. safety.py:60 is a tree digest.
What I verified
- Round 2 fixes: I read the diff from
2f39a06edto head._planned_actions_digestis inlined, its three test uses are updated, and it is on the retired list.report_build.py:165,reference_lifecycle.py:1051andrunner.py:594now calloptional_file_sha256. All three arguments arePathvalues, and the old and new forms give the same digest orNone.reference_lifecycle.pyline 1054 still has its ownis_filecheck forreview_candidates, which returns a list rather than a digest.- The
dataset_sha256conditional atrunner.py:595stays, as the PR body says.
- Guard: The new optional-form rule and its negative controls behave as the PR body describes. Its check for inline conditionals returns no violation on the current tree.
- Remaining wrappers: I ran my own AST scan of short functions under
src/harnessthat hash or read and write JSON, and read each one.- Apart from the findings above, the ones left have a precondition, a shape check, a different parser, an option, a cache or another distinct behaviour.
review_execution.write_content_documentis a one-linewrite_json(path, value, parents=True)with five callers and a test import. The guard allows a fixed keyword option, so I am not raising it.
- Source hash checks: I traced the
__file__and source-file hashing sites.- Edited and hashed by live code:
webarena_state.py,webmainbench_runner.py,webmainbench_latency_diagnostic.py,webmainbench_diagnostics.py,review_execution.py,result_review.pyandweb_search/report.py. review_execution.pycompares its identity only inside a review workspace, and a changed one requires a new directory. That in-flight effect is like the ones the PR body discloses, though the body does not name it.- Not edited:
reporting/visual.py,web_search/visual.py,web_search/pages.py,browser_use/report_visual.py,trajectory_replay/webarena_report_visual.py,title_quality.py,rescoring.pyandproviders/cloudflare.py. - I did not repeat the data-home scan, so that claim still rests on the PR's own scan.
- Edited and hashed by live code:
- Golden snapshots: The only change across all tracks is the
manifest.jsonroute intests/golden/web-search.json, as the PR explains. I did not rebuild the base and branch trees to compare them. - Removed names: Outside the guard file, a repository search finds no use of
text_digest,_attempts_sha256,_parameters_sha256,write_agent_response,_planned_actions_digest,sha256_file,_sha256_file,json_digestorinput_digest. No importer ofjson_bytesfromreporting/publicationremains, andpublication.pyonly uses it internally. - Scope: "Part of #91" is accurate. Data-home,
.envand redaction work is listed as remaining.
Commands run
ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: pass.tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 63 passed, matching the PR body.tests/web_searchandtests/test_webmainbench_content_review.py: 502 passed.tests/test_reference_lifecycle.pyandtests/trajectory_replay/test_webarena_report.py: 134 passed.- I did not run the full suite locally. CI is the full-suite gate.
CI
All checks pass at this head: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks", "Python 3.11", "Select check scope", "OCR dispatch". The PR is mergeable, its merge state is clean, and main is still 27401304.
|
Round 3 findings, all fixed. Nothing disputed.
Tests: lint passes, and the affected test files plus the guard and golden test give 912 passed, 23 skipped, no failures. Golden snapshots did not change. CI on 9ee970e is the full-suite gate. The PR body also now states that inline |
There was a problem hiding this comment.
✅ Re-review complete · 9ee970e
No findings in this incremental review.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 4
Head: 9ee970ec. CI passes for this head (run 41404445616, conclusion success), including "Tests and static checks" and "Installation and packaging". No findings below are correctness or byte-stability defects.
Findings
P2, PR body, "Deliberately not migrated", Inline expressions bullet (and "Remaining for #91"). The body says the json.dumps(...) document expression remains inline "in about 30 places". An AST count of json.dumps(x, ensure_ascii=False, indent=2) + '\n' under src/harness finds 218, 144 of them in files this PR edits. The bullet also omits 113 inline hashlib.sha256(x.read_bytes()).hexdigest() (53 in edited files) and 841 inline json.loads(x.read_text(...)) (506 in edited files). The issue's acceptance is "no private re-implementations remain", so a reader relying on this list would underestimate what is left. The guard checks function definitions and does not cover these.
Fix: correct the count, add the two missing forms, and state under "Remaining for #91" or "Deferred" whether inline forms are in scope for #91. No code migration is requested by this finding.
P3, private JSON helpers left in edited files, neither migrated nor listed as kept. These have the same semantics as forms this PR did migrate (public_webarena/publication._read_json, webmainbench_case_correction._read_json, browser_use/report._read_json), and the guard does not flag them because of the added precondition or return value:
src/harness/trajectory_replay/diagnostics.py:56:write_diagnosticbuilds(json.dumps(payload, ensure_ascii=False, indent=2) + "\n").encode(), which is exactlyjson_bytes(payload).src/harness/browser_use/failure_cause_review.py:31:load_failure_cause_reviewsrc/harness/browser_use/publication.py:60:read_public_jsonsrc/harness/trajectory_replay/catalog_comparison.py:44:_readsrc/harness/trajectory_replay/remote_runtime.py:380:_read_frozen_inputsrc/harness/trajectory_replay/webarena_results.py:26and:234:_read,_read_cohort_inputsrc/harness/trajectory_replay/diagnostics.py:646: nestedread
Fix: use json_bytes and read_json at these sites and keep their preconditions, or list them as kept with a reason. Editing these files needs the same hash-binding scan as the other edited files; all of them are already edited by this PR, so the scan should already cover them.
Verified
- Every removed or changed hash and JSON helper in the 89 edited
src/harnessfiles, compared with its replacement:ensure_ascii,allow_nan,sort_keys, separators, trailing newline, optional versus strict digest (including thesha256 as file_sha256optional alias inbrowser_use/report.pyandreport_check.py), andparents=Trueon all 16browser_use/report.pywrites and on_write_clean_json. No byte or error-type difference found beyond those disclosed. webarena_corrections._digestused noallow_nan=False, socanonical_json_sha256is equivalent.- Hunks that remain after normalizing helper names are mechanical, apart from the wrappers the body describes.
word_f1andsnippet_check, bound bywcxb-metric-bindings.json, are not in thewcxb_scoring.pydiff.- All
from harness... importnames acrosssrc,scripts,tests,evaluationandresearchresolve. Retired names have no remaining references outside the guard. No caller importsjson_bytesthroughreporting/publication. - Guard: run against
eb30a3ddit flags exactly the four copies the body names, and it passes at the head. The BOM parity test exists. - Lint gate passes.
tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 83 passed. - No base-commit hash of an edited source file appears anywhere in the repository (git grep).
Not verified
- My independent scan of the data home for those base hashes did not complete, so I did not confirm the body's data-home scan results. This matters most for
webarena_state.py:rule_identity()includes its own source hash andload_contractsrejects a profile that binds a different one. I confirmed no repository file binds it, but not that no data-home profile does. - I ran no other local tests; the full suite rests on CI.
- Aggregated source digests (such as
runtime_source_sha256) cannot be found by a per-file hash search. The body discloses this for in-flight cohorts.
There was a problem hiding this comment.
✅ Re-review complete · 6abb2f9
No findings in this incremental review.
|
Round 4 review fixes, head Fixed
Short loaders that validate a schema or select a field, locale-encoded reads and Disputed: none. Local tests: lint passes. Guard, golden test and the 62 test files that reference a module edited this round: 1,175 passed, 4 skipped. Golden snapshots unchanged. |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 5
Reviewed head: 6abb2f9c, base 27401304.
No defects found. There are no findings at any severity.
What I verified
- CI at this head: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks", Python 3.11 and the OCR review all pass.
- Local gates: both ruff commands pass.
tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 97 passed.tests/trajectory_replay,tests/test_webarena_state.pyandtests/browser_use/test_failure_cause_review.pytogether with those two files: 2,200 passed, 5 skipped. I did not run the full suite locally; CI covers it. - Byte-level semantics: I extracted every function removed or changed in
src/harnessand compared old and new bodies. I also normalized helper names across the whole source diff and read every line that was not a plain rename.json.dumpsoptions match at each site, including theensure_ascii=Trueandallow_nan=Falsecallers._case_ids_sha256is unchanged because it hashes a sorted list of strings.parents=Trueis passed where the old writer created parents, and not where it did not._cleanis still applied through_write_clean_json.browser_use/report_check.pykeeps the optional-hashNonebehaviour.
read_jsonagainstjson.loads(read_text(encoding="utf-8")): a differential run gave the same value or the same error type for CRLF, bare CR between tokens, CR inside a string, non-ASCII text,NaN, an empty file and a BOM.- Call sites: an AST scan over
src,scriptsandtestsfound no helper shadowed by a local name, no undefined helper, no unresolvedfrom harness... import, and no import of a shared helper through a non-owner module.web_search.core.write_jsonis the named atomic owner, andreporting/visual.pyis a named exemption. No aliases were added. Removed test assertions were call-site renames. - Guard: I read each rule and its controls. My own scan of short functions found no remaining bare copy. The remaining functions have a real difference, such as chmod, schema checks, field selection, atomic replacement, a locale read or an
importlib.resourcesread. - Scope claim: "Part of #91" is accurate, and the remaining work and the owner decision on inline forms are stated. I reproduced the body's counts: 217 (150), 46 (25), 830 (515) and 3 for
file_digest. My count ofhashlib.sha256(x.read_bytes())is 115 (54) against the body's 113 (53), because my pattern does not require.hexdigest(). At least one extra is the.digest()form inwebarena_report_package.tree_sha256; I did not identify the other. - Hash-bound inputs:
- No base-commit hash of the 91 edited source files appears in
evaluation,research,configs,tests,scriptsorsrc. word_f1andsnippet_check, whichwcxb_scoringbinds throughinspect.getsource, are unchanged.- The
source_code_sha256checks inwebmainbench_diagnosticscompare retainedcorrection-sourcecopies, not live files.
- No base-commit hash of the 91 edited source files appears in
- Golden snapshots: only
web-searchmanifest.jsonchanged, as the body explains. I did not rebuild the base tree to reproduce that comparison.
Limits and one note
- Data-home scan incomplete: my own scan for the base hashes under
~/.browser-evaldid not finish within the time I allowed, so I did not independently reproduce the body's data-home result. It therefore rests on the author's scan. - Live gate not listed in the body:
webarena_state.load_contractscompares a profile'srules.source_sha256with the live source, and this PR edits that file. A form-state profile frozen before this PR would be rejected before a run. A search of the 29,906 JSON files under 2 MB in the scanned data-home directories found nowebarena_observed_form_state/1, and the repository has none either, so nothing here is affected. This is not a finding.
Replace private SHA-256, canonical JSON digest and JSON file helpers under src/harness with harness/record_io.py. Options that differ from the shared defaults stay explicit at the call site so every bound digest keeps its bytes. Guard the fully migrated names with a test.
Inline _attempts_sha256, _parameters_sha256 and write_agent_response, and replace the three text_digest copies with bytes_sha256(x.encode()) at each call site. The guard now rejects wrappers that only forward to a shared helper, so these forms cannot return unnoticed. Digests are unchanged.
_planned_actions_digest had one verifier caller and only tests used it to build fixtures, so it named no shared contract. Call canonical_json_sha256 directly and retire the name in the guard. Correct the guard's reason for keeping canonical digest names: task_definition_sha256 names a public protocol, and only scoring_revision_history_sha256 is shared by a writer and a verifier. Digests are unchanged.
Replace the three remaining digest-if-file-else-None expressions in report_build, reference_lifecycle and runner, and extend the guard to reject that form with negative controls for other returns, paths and readers. Digests are unchanged.
6abb2f9 to
bd6cb63
Compare
|
Rebased onto main at b951a7c (#133 to #138). The only golden snapshot this PR changes is still |
Issues
Closes #91. This PR covers hashing and JSON file I/O only. Data-home,
.envand local-path redaction helpers landed separately in #136.Remaining work, moved to #150:
Summary
Private SHA-256, canonical JSON digest and JSON read/write helpers under
src/harnessnow useharness/record_io.py.record_io.pygainsbytes_sha256,optional_file_sha256,read_json,write_json(parents=)andjson_bytes(moved fromreporting/publication.py, callers migrated, no re-export).canonical_json_sha256gains explicitensure_asciiandallow_nanoptions. Defaults are unchanged. Callers whose digests were ASCII-escaped or strict name that choice at the call site.tests/test_shared_hash_json_helpers.pybans the fully retired names and rejects new bare copies by structure, with paired negative controls. It is an AST test rather than ruffTID251, becauseTID251bans imports, not local definitions.Semantics compared before each swap
json.dumps(sort_keys, compact, ensure_ascii=False)canonical_json_sha256(v)allow_nanwas already thejson.dumpsdefaultensure_ascii=False(_proposal_digest,canonical_digest,profile_digest, rainbond)canonical_json_sha256(v, ensure_ascii=True)allow_nan=False(webarena_state.digest,retrieval_acceptance.digest)canonical_json_sha256(v, allow_nan=False)_case_ids_sha256(nosort_keys)canonical_json_sha256(sorted(ids))sort_keyshas no effect on a list of stringsfile_sha256OSErrortypessha256(path) if path.is_file() else None, as a helper or inlineoptional_file_sha256Noneis kept, including inbrowser_use/report_check.py, which used both a strict and an optional helper.webarena_replay.pykeeps its conditional because it returns a dict, andrunner.py'sdataset_sha256keeps its own because it reads throughread_dataset_bytesjson.loads(read_text(encoding="utf-8"))read_json(dumps(ensure_ascii=False, indent=2) + "\n").encode()as a helper (report_diagnostic.encode,browser_observation_bytes)json_bytesatomic_write(path, <same document bytes>)(web_search/publication.save)web_search/core.write_jsonatomic_write, same byteshashlib.file_digestbehindexists()(report_package._archive_identity)exists()check kept, thenfile_sha256optional_file_sha256was not used because it returnsNonefor a directory, where this raiseswrite_text(dumps(indent=2) + "\n")write_jsonreview_execution.write_content_document,webmainbench_correction.write)Deliberately not migrated
comparison_audit._read_jsonandwebmainbench_certification._read_jsonusejson.loads(bytes), which also accepts UTF-16/32.web_fetch/config.load_jsonandrefresh_assembly._read_jsonread throughread_dataset_bytes.web_search/core.write_jsonstays atomic, sharesjson_bytes, and is the one atomic JSON document writer the guard allows.rainbond._atomic_jsonis unchanged.lexbench/resource_matrix.py,lexbench/resource_profiles.pyandreporting/visual.pykeep their copies, because editing them changesorchestrator_sha256or visual-proofchecker_sources. They are named exemptions in the guard.lexbench/reproduction.pyalso stays: it is published asreproduction/run.py.checked_file_sha256,_checked_sha256,_revision_file_sha256),str | bytesinput (reference_lifecycle.sha256), named frozen options (webarena_state.digest), and a cache (reporting/locales._catalog).task_definition_sha256andscoring_revision_history_sha256only callcanonical_json_sha256, but each name states a contract.task_definition_sha256names a public protocol: thetask_definition_sha256field that a retrieval contract declares.scoring_revision_history_sha256is shared by the code that writes the digest (assembly.py) and the code that verifies it (reference_lifecycle.py).reference_freeze.browser_observation_bytesnow returnsjson_bytes(observation)and stays for the same reason: its writer and its verifier share those bytes._attempts_sha256,_parameters_sha256,_planned_actions_digest,write_agent_responseand the threetext_digestcopies are replaced at their call sites, using thebytes_sha256(x.encode())form the harness already uses elsewhere.evaluator_transition.load_transition,remote_runtime.validate_remote_reset_receiptandrainbond.validate_receipt.read_jsoncannot replace:json.loads(x.read_text())without an encoding follows the locale (lexbench/verification.resource_document,local_execution_contract.read,local_execution_legacy.read,report_version._profile_binding,report_interfaces.method_provenance).public_webarena/diagnostics._official_datasetandwebarena_dataset._official_evaluator_namesread animportlib.resourcesobject, which is not always a filesystem path.src/harnessat the current head, excluding therecord_io.pyowner, with the count in the 91 files this PR edits in parentheses:json.dumps(v, ensure_ascii=False, indent=2) + "\n": 219 (150), of which 46 (25) add.encode()and so equaljson_bytesexactly. The others are mostlywrite_text(..., encoding="utf-8").hashlib.sha256(x.read_bytes()).hexdigest(): 113 (53).json.loads(x.read_text(...)), with or without an encoding: 833 (515).hashlib.file_digest: 3 outsiderecord_io.py, insafety.pyand two providers.read_jsonl,write_jsonl) andpublication_verify's networkdigestare out of scope.The names
digest,sha256,shaand_read_jsonare not banned because distinct definitions remain; the structural rule still rejects bare copies under those names. It also rejects wrappers that only forward their parameters tobytes_sha256,file_sha256,read_jsonorwrite_json, the inline<digest of path> if path.is_file() else Noneform, thejson_byteshelper form, thehashlib.file_digesthelper form (with or without a leadingreturn Nonecheck), and a body that only callsatomic_writewith one JSON document. Run against the previous head, the new rules flag exactly the four copies migrated in round 3. It does not flagjson.loads(path.read_bytes()), because that parser accepts inputsread_jsonrejects.Round 4 added two structural rules. The first rejects a function of up to five statements that returns
json.loads(<path>.read_text(encoding="utf-8"))after preconditions, directly, as a tuple element, as the true branch of a conditional, through a one-argument wrapper, or after anot isinstancecheck. The second rejects a function of up to two statements that passes thejson_bytesexpression to an output call. Both have negative controls for a locale read, a constant input, schema validation, field selection and a writer that also uses the bytes. Those rules flagged the sites below, and each now callsread_jsonorjson_byteswith its preconditions unchanged:failure_cause_review.load_failure_cause_review,browser_use/publication.read_public_json,catalog_comparison._read,remote_runtime._read_frozen_input,webarena_results._readand_read_cohort_input,diagnostics.write_diagnosticand its nestedread.evaluator_transition._regular_json,webarena_report._load_artifact,web_fetch/evidence._readandweb_fetch/local_audit._read_bound_receipt.Hash-bound evidence
src/harnessfiles edited by the first commit at the base commit and searched for those hashes in the repository and inevidence,reviews,report-builds,datasetsandimplementationsunder~/.browser-eval. The repository had none, and the only data-home hits wereharness_filesinventories in 10 pre-call files underevidence/research/webfetch-430-refresh-20261014/. In the one inventory I compared in full, 211 of 246 entries already differ from the base commit, so it is a historical snapshot and not a live gate.public_webarena/runner.py, first edited in the round 1 fix, was checked the same way and its base hash has no hits.web_search/publication.py,web_fetch/report_package.py,web_fetch/report_diagnostic.pyandweb_fetch/reference_freeze.pyhave no hits inevaluation,research,configsor those data-home directories (JSON files only).web_fetch/evidence.pyandweb_fetch/local_audit.py, have no hits inevaluation,research,configsor those data-home directories (JSON files only).src/harnessfiles as they stand on main and searchedevaluation,research,configs,tests,src,scripts,docsand those data-home directories (JSON files only). The repository has no hits, and the data-home hits are the same 10 pre-call inventories described above.wcxb_metrics.py, the module refactor(wcxb): bind the metric module by normalized AST #133 binds, is not edited.wcxb_scoring.pyis edited, as it was before the rebase: its hash is recorded asscorer_sha256and watched for changes during a WCXB latency collection, so like the other modules under "In-flight work" it should not change during an unfinished collection. Nothing compares that hash to a frozen value.build-cache,builds,runtimeandtoolchainsunder the data home, and any evidence on other machines.web_search.validate_resume_implementationand the Web Fetchruntime_source_sha256continuation checks compare live source. As with any edit to these modules, an unfinished cohort started before this PR cannot resume and needs a new cohort.Golden snapshot
One route changed:
web-searchmanifest.json. I built the Web Search example from the base commit and from this branch and compared the trees. Onlymanifest.jsonandbrowser-eval-version.jsondiffer, and the manifest differs only inrenderer_sha256,browser_evaland the matchingbundleentry.renderer_sha256is the hash ofweb_search/report.py, which this PR edits. The other two come frombrowser-eval-version.json, which my comparison left unpinned; the golden test pins the builder identity, and that route's snapshot is unchanged. Sorenderer_sha256is what moves the snapshot. No HTML route changed, and no other track's snapshot changed.Rechecked after rebasing onto #133 to #136: with the builder identity pinned, the 19 normalized routes built from main at that point and from this branch differ only in
manifest.json'srenderer_sha256, which equals the SHA-256 of each side'sweb_search/report.py. #138 does not touch that module or the snapshot, and the golden test passes on the final rebase.Deleted files
None, so no reference scan was needed for deletions. For removed helper names, I resolved every
from harness... importand module attribute access acrosssrc,scripts,tests,evaluationandresearchby importing the modules. No import was missing. The nine attribute reports were local variables that share a module's name. Dynamic lookups by string and non-Python files were not covered by that check.Deferred
Test plan
Local, Python from the shared locked environment:
ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: pass.ruff check --config 'include=["*.py"]' --select F,TID252 .andruff check: pass.tests/test_golden_reports.pyandtests/test_shared_hash_json_helpers.py: 97 passed, in a run of 200 withtest_documented_paths.py,test_report_methods.py,test_packaging_hygiene.pyandtrajectory_replay/test_hf_inputs.py.test_packaging_hygiene.py::test_documented_make_commands_name_the_required_profileandtest_hf_inputs.py::test_default_catalog_output_is_private_and_only_created_after_validation[None], also fail in a scratch export of main before refactor(research): move adoption survey into harness and fix stale doc paths #138 and pass in the git worktree, because the export has no.git.from harness... importundersrc,scripts,tests,evaluation,researchandexamplesresolves.tests/web_search, the Web Fetch package, freeze, reference, privacy and publication test files, the guard and the golden test: 912 passed, 23 skipped, no failures. Golden snapshots are unchanged by this round.webarena_report,report_build,reference_lifecycle,web_fetch.runner): 2,381 passed, 7 skipped, 4 failed. All 4 are on the known local macOS list.test_optional_reports.py(3),test_report_software_versions.py(1) andtest_hf_inputs.py(1).Historical benchmark source is not recorded in the dataset lock.reference_inputs.pywalks up to the parent checkout's olderevaluation/lexbench-webfetch.json. This is a local path artifact: the failures unique to that location passed from the scratch copy, and CI is the gate.CI results are in the checks on this PR.