Skip to content

refactor(reporting): share one publication client across track publishers - #144

Merged
lanyue-llk merged 2 commits into
mainfrom
refactor/shared-report-publish-client
Nov 3, 2026
Merged

lanyue-llk merged 2 commits into
mainfrom
refactor/shared-report-publish-client

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #102. This is the first step only: the shared publication HTTP client and archive helpers.

Remaining work, moved to #156:

  • Moving the publish orchestration itself (web_fetch/report_publish.publish) into a shared owner. Track flows stay track-owned here; only their HTTP, multipart, decoding and receipt code moved.
  • One reviewer subprocess runner.
  • One release-check base.
  • One esc() helper.
  • One HAR recorder (needs paired replay tests).

Also not changed: web_fetch/publication_verify.py, the read-only verifier, keeps its own urlopen calls. It is not one of the publish modules the issue lists.

Summary

harness/reporting/publication.py, the existing owner of the shared publication primitives, now also owns:

  • PublicationClient: the request and its headers. User-Agent, timeouts, header order and HTTP failure handling are data.
  • response_json
  • multipart_archive
  • write_receipt

Each publisher declares only what is specific to it:

Publisher User-Agent Timeout (PUT) HTTP failure Header order
Web Fetch WebFetch-Report-Publisher/1.0 240 s (90 s) raised Authorization first
Web Fetch rename none (urllib default) 30 s raised Authorization first
WCXB WCXB-Report-Publisher/1.0 240 s raised User-Agent first
Browser Use Browser-Use-Report-Publisher/1.0 240 s returned Authorization first
Browser Use public checks same 60 s raised no credential
Browser Trajectory Replay Trajectory-Replay-Artifact-Site-Publisher/1.0 240 s (1200 s) returned User-Agent first

Multipart boundary seeds, prefixes and filenames stay per track, so a retried in-flight operation replays the same bytes.

Corrections to the issue, checked against the current code:

  • web_search/publication.py and public_webarena/publication.py have no HTTP client. They already adapt web_fetch/report_publish.publish, so there were four clients to swap, not six.
  • tree_sha256 already has one implementation, in reporting/visual.py. It stays there because that file is a bound source (see below). The two copies in the report_package.py modules are removed in favour of the framing wrapper each track's publisher already has.

Behaviour changes

Requests are unchanged. These differences remain:

  • Nested secrets in receipts: Browser Use and Replay receipts now drop token, editToken and claimToken at every depth, as Web Fetch already did. They previously dropped them at the top level only.
  • response_json wording and types: there is now one version, the Browser Use one.
    • Replay's "without valid JSON" and "non-object JSON" messages use the shared wording.
    • Web Fetch and WCXB now raise RuntimeError instead of ValueError or JSONDecodeError on malformed or non-object JSON, and include up to 500 characters of the response body on a non-2xx status.
    • Nothing catches those exception types. These two publishers raise real HTTP failures before decoding, so a non-2xx response only reaches this path through a fake transport or a recorded operation status.
  • Symlinks in package digests: the digest in both report_package.py modules now goes through the shared tree_sha256, which rejects symlinks. Digest bytes are unchanged for a tree without symlinks.
  • Browser Use public share check: it now reads the response body. The request itself is the same.

Hash-bound sources

No bound file is edited:

  • reporting/visual.py, browser_use/report_visual.py, trajectory_replay/webarena_report_visual.py, web_search/visual.py and web_search/pages.py (the checker_sources and visual source bindings) are untouched.
  • I searched the repository for the file names of the edited modules. The only hit is a descriptive mention in docs/architecture.md, so no profile or binding names them.
  • Golden report routes are unchanged.

Test plan

  • Wire comparison (local script, not committed): I drove the publish flows against a fake site on both an untouched b02de7ad archive and this branch. Flows covered:

    • Web Fetch: update, staged, sharing, reuse and rename.
    • WCXB: staged.
    • Browser Use and Replay: create and update, plus direct failure and PUT calls.
    • Replay: staged create and update.

    All 76 requests match on method, URL, ordered headers, body hash and timeout. Saved receipts and journals match too, except for the nested token removal above. No real site was contacted.

  • New test file: tests/test_reporting_publish_client.py pins per-track headers and timeouts, failure handling, exact multipart bodies, receipts and tree digests. Boundary and digest values were computed from the b02de7ad code.

  • Existing tests: only fixtures changed. Fake transports stay; load_token and atomic_write patches now target the shared owner, and fake responses gained headers. Replay's timeout test now reads CLIENT.timeout_for, and its response_json test uses the shared wording.

  • Lint: both ruff gates pass.

  • Publish and golden tests: the publish, reporting and CLI scope targets plus tests/test_golden_reports.py gave 442 passed in the worktree.

  • Full local suite on an archive of this branch: 29 failed, 19238 passed, 60 skipped.

    • No publication test is among the failures.
    • 28 of the 29 fail the same way on the b02de7ad archive. The comparison covers every failing test file, run on both archives.
    • The other one, test_moli_provider.py::test_zero_exit_empty_markdown_is_an_empty_response, failed once under the full run and passed on its own on both archives.
  • Local caveats:

    • Tests ran with pytest's -o pythonpath='src .' rather than a PYTHONPATH environment variable, so subprocess tests can import a different checkout. That explains local failures such as a missing harness.web_search.cli.
    • The full suite run inside the git worktree reported 68 failures across 64 test IDs, and 42 of those IDs did not fail on the archive of the same commit. The ones I inspected fail with "Historical benchmark source is not recorded in the dataset lock"; I did not find why this happens only in that location.
  • CI: Linux CI is the full-suite gate for this PR.

…hers

Move request, response_json, multipart_archive and receipt writing into
harness/reporting/publication.py. Web Fetch, WCXB, Browser Use and Browser
Trajectory Replay select their User-Agent, timeouts, header order and HTTP
failure handling through a PublicationClient value, so their requests stay
byte-identical.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review complete · 643d146

No findings in this review.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 1

Reviewed head 643d1460 against base b02de7ad. One finding (P2). I found no behavioural regression.

Findings

P2: the committed tests pin the client values, not the adapters' use of them (tests/test_reporting_publish_client.py:40, wiring at src/harness/web_fetch/wcxb_publication.py:146, src/harness/web_fetch/report_publish.py:153, src/harness/web_fetch/report_publish.py:366, src/harness/browser_use/report_publish.py:103, src/harness/trajectory_replay/webarena_report_publish.py:102)

The new test file calls web_fetch.CLIENT.request(...) and the other client constants directly. The Web Fetch and WCXB publish tests pass transport=, which bypasses the client, or (rename) check only the URL and receipt. The PR's wire comparison, which is what proves byte equality, is a local script that was not committed, so nothing guards these lines after merge.

I mutated each line below and ran 12 publication test files (255 tests: test_reporting_*, test_wcxb_publication, test_webfetch_report_publish, test_webarena_publish, web_search/test_publication, browser_use/test_publish, test_published_snapshot_report, public_webarena/test_trajectory_release). All 255 still passed for every mutation except the last row:

Mutation Effect on a real publish Result
WCXB: drop authenticated=auth Bearer credential sent on the anonymous share check all pass
WCXB: drop extra_headers=extra_headers No Idempotency-Key on start and commit all pass
Web Fetch send: drop extra_headers No Idempotency-Key on package submission all pass
Web Fetch send: use RENAME_CLIENT No User-Agent, 30 s timeout all pass
Web Fetch rename: use CLIENT Adds a User-Agent, wrong client all pass
Browser Use request: use PUBLIC_CLIENT HTTP failures raised instead of returned, 60 s timeout all pass
Browser Use share check: use CLIENT HTTP failures returned, 240 s timeout all pass
Replay request: drop authenticated=authenticated Credential sent on public share requests all pass
Browser Use share check: drop authenticated=False Credential loaded 8 fail (caught)

The credential and idempotency rows matter most. A later edit could send a token to a public route, or lose retry safety, with CI green.

Suggested fix: add one committed test that goes through each adapter's real path with urllib.request.urlopen faked and asserts ordered headers and timeout:

  • browser_use.request and replay.request, including authenticated=False.
  • web_fetch.publish(config) without transport, in single-request and staged modes.
  • wcxb.publish(...) without transport, including the /v/public-token request.
  • rename_main.

The existing Service and Site fakes work for this behind a small urlopen adapter. I drove them that way for the comparison below, so it needs no new fake site.

What I verified

  • Wire comparison: I wrote my own script and ran it on an archive of b02de7ad and on this head with urlopen faked. It covered the following:

    • WCXB full publish, including the public share and PATCH.
    • Web Fetch create and update, both single-request and staged.
    • Browser Use and Replay request, including the 429 path, multipart bodies, package tree digests (with assets/x next to assets.json to exercise sort order) and receipts.

    Method, URL, ordered headers, body hash and timeout match. The only difference is PUT order in one staged update run, which comes from the existing max_workers=4 thread pool, not this change.

  • By reading only: the Browser Use share and preview checks, the Replay public requests and rename_main. I did not run these through the comparison.

  • Exception type change: there is no except ValueError or JSONDecodeError around response_json in the publishers or CLI entry points, so the PR's claim holds. The except ValueError blocks in web_fetch/publication.py handle Retry-After parsing only.

  • Nested receipt secrets: no code reads a token field back from a saved receipt.

  • Hash-bound sources: no edited file appears in producer_sources or checker_sources, or by name under evaluation/, configs/, research/ or .agents/.

  • Duplicates: there is no other response_json, multipart or editToken receipt implementation in the publish stack. web_search/publication.py and public_webarena/publication.py have no HTTP client, as the PR says.

  • Scope: "Part of #102" is accurate, and the remaining list covers the runner, release-check base, esc(), HAR recorder and orchestration.

  • Local checks: both ruff gates pass. tests/test_golden_reports.py and the publication tests gave 238 passed. I did not run the full suite locally.

  • CI on 643d1460: all checks pass, including "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks".

Drive browser_use.request, replay.request, every track's publish flow and
rename_main with only urlopen faked, and assert the ordered headers, URL and
timeout of each physical request. The expected requests also pass against the
implementations these adapters replaced.
@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1: fixed in 79d4dcc. Nothing disputed.

P2, adapter wire behaviour was not pinned. tests/test_reporting_publish_client.py now drives each adapter's real path with only urllib.request.urlopen faked, and asserts the URL, method, ordered headers and timeout of each physical request. The existing Service and Site fakes sit behind a small urlopen adapter.

  • browser_use.request and replay.request, including authenticated=False and X-Artifact-Share
  • browser_use.main and replay.main create flows, including the public share and preview checks
  • web_fetch.publish without a transport, in single-request and staged modes (staged PUTs after index.html are compared sorted, because the thread pool does not fix their order)
  • wcxb.publish without a transport, including the public share request
  • rename_main

Checks

  • Mutations: I applied 14 single mutations to the adapters, and each one fails the new tests. They cover the ones in the finding (dropped authenticated=auth and authenticated=authenticated, dropped Idempotency-Key forwarding in WCXB and Web Fetch, swapped clients in Web Fetch send, Web Fetch rename, Browser Use request and the Browser Use share check), plus the Browser Use preview client, Browser Use and Replay extra_headers, and authenticated=False on the share and preview requests.
  • Old-versus-new: the 8 new tests also pass unchanged against the pre-refactor code at b02de7a, with only the credential stub redirected to the old modules. This was a local run; that harness is not committed.
  • Local: 235 passed across the publication test files and tests/test_golden_reports.py, and golden hashes are unchanged. The lint gate passes.

This commit changes one test file and no source, so rendered output and hash-bound source lists are unaffected.

@lexmount-ocr lexmount-ocr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Review skipped · 79d4dcc

No reviewable content was selected for this run.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review, round 2

Reviewed head 79d4dcc5 against base b02de7ad. No defects found.

What I verified

Round 1 finding. It is fixed.

  • I ran the 8 new real-path tests against the b02de7ad publish code, in a throwaway checkout with only the credential stub redirected to the old modules. All 8 pass, so they pin the old wire behaviour and not just the new code.
  • I reapplied six single mutations on this head, and the new test file fails on each:
    • dropping authenticated=auth in WCXB
    • dropping authenticated=authenticated in Replay
    • using the wrong client in Web Fetch rename
    • using the wrong client in the Browser Use share check
    • changing the Replay PUT timeout
    • keeping nested token values in receipts

Old and new semantics, read from the diff.

  • Requests: User-Agent, header order, Content-Type and extra-header order, timeouts and PUT overrides, and raised versus returned HTTP failures all match for each track, including the urllib default User-Agent on rename.
  • WCXB: fake transports still get no credential, and the real path sends none on public requests.
  • Multipart: boundary seeds, prefixes, filenames and body layout match.
  • Tree digests: reporting/visual.py uses the same sort and serialization as both removed report_package.py copies. The only difference is the symlink rejection the PR discloses, and package_archive already rejected symlinks on the same report tree.
  • Receipts: nothing in src/harness reads a nested token, editToken or claimToken from a receipt, so dropping them at every depth is safe.
  • response_json: no publish path catches ValueError or JSONDecodeError around it, so the new RuntimeError changes no control flow.

Removed code and duplicates.

  • No references remain to request_timeout, _safe_receipt or the per-module load_token patches.
  • The only remaining Artifact Site HTTP calls outside the shared client are in publication_verify.py, which the PR discloses, and artifact_auth.py, which handles authorization.
  • There is no other copy of the multipart, response_json or receipt-writing helpers. reporting/visual.py has a same-named write_receipt; that file is bound and was not edited.

Hash-bound sources.

  • checker_sources and producer_sources bind only the visual modules, web_search/pages.py and reporting/visual.py, and none of those are edited.
  • A search of src, scripts, evaluation, configs, docs and .agents finds no binding of an edited module.
  • No evidence, profile or receipt file is changed.

Scope. "Part of #102" is accurate. The remaining list covers the shared publish() owner, reviewer runner, release-check base, esc() and HAR recorder. The PR adds none of these.

Local runs.

  • Both ruff gates pass.
  • 215 tests passed across the new test file, tests/test_golden_reports.py, the upload and recovery tests, the WCXB, Web Fetch and Replay publish tests, the Web Search publication tests, the public WebArena release tests and the published-snapshot report tests.
  • Golden snapshots are unchanged.
  • I did not run the full suite locally, and no real site was contacted.

CI on 79d4dcc5. All checks pass, including "Tests and static checks", "Installation and packaging" and "Rendered reference and report checks".

Note, not a defect. The PR body's local test counts (442 passed, and the full-suite totals) don't mention the 8 tests added in 79d4dcc5. That commit changes only the test file, and CI covers it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify the report publish/package stack and reviewer-subprocess orchestration

1 participant