Skip to content

Consolidate copy-pasted hashing, JSON I/O, data-home, dotenv and redaction helpers #91

Closed

Description

@lanyue-llk

Problem

Shared helpers already exist but are re-implemented across the tree:

  • sha256 / JSON digest: about 56 files define a private _sha256 / _json_sha256 / digest, although harness/record_io.py already has file_sha256 and canonical_json_sha256.
  • JSON read/write: _read_json / write_json / atomic_write are redefined in about 20 modules, plus 7 or more test files. harness/reporting/publication.py already has atomic_write, atomic_create and json_bytes.
  • Data-home resolution appears 6 times with different semantics. storage.py:18 expands and resolves the path. webmainbench_runner.py:571 and lexbench/report.py:25 do neither, and the latter runs at import time.
  • Three .env parsers disagree. trajectory_replay/catalog_runner.py:138 uses .strip("\"'"), which also strips mismatched quotes. The other two are public_webarena/config.py:12 and web_fetch/config.py.
  • Local-path redaction regexes are separate in anomaly_review.py:184, webmainbench_assembly.py:41, web_search/comparison.py:34 and webarena_report.py.

Proposal

  • One module per concern, reusing what exists: harness/record_io.py for hashing and JSON, harness/web_fetch/storage.data_home promoted to shared, one .env loader, and one redaction module.
  • Migrate callers in small per-package PRs.
  • Before swapping each copy, check its json.dumps options (sort_keys, separators, ensure_ascii), so that bound digests stay byte-identical.

Acceptance

  • No private re-implementations remain (enforced by a grep test or ruff TID251 banned-api).
  • Golden snapshots and every hash-bound receipt verify unchanged.

Risk: low. Depends on: golden snapshots.


Part of the refactor roadmap: #87

Activity

  1. added
    refactor
    on Oct 29, 2026
  2. lanyue-llk commented on Nov 3, 2026

    @lanyue-llk
    ContributorAuthor

    Resolved by #136, #137. Remaining work is tracked in #150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions