Skip to content

eegprep-lean: send only Range from PyfetchTransport - #420

Merged
neuromechanist merged 1 commit into
developfrom
fix/issue-419-pyfetch-user-agent
Sep 25, 2026
Merged

neuromechanist merged 1 commit into
developfrom
fix/issue-419-pyfetch-user-agent

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #419

What

PyfetchTransport.get sent a User-Agent: eegprep-lean header on every request. Chrome
drops a script-set User-Agent, so requests there stayed simple; Safari and Firefox send
it, which turned every read into a CORS-preflighted request. zarr.nemar.org allows only
Range in Access-Control-Allow-Headers, so the preflight was refused and every read
failed in those two browsers.

PyfetchTransport now builds its request through FetchTransport, over a small adapter
around pyodide.http.pyfetch (_pyfetch in transport.py), instead of keeping a second,
separate implementation of the header rule. FetchTransport already sent Range only,
and nothing at all for an unranged read, for exactly this reason (its docstring). Sharing
the implementation also means PyfetchTransport now goes through the same
TransportError-on-failure, ranged-request-answered-in-full, and 4xx/5xx handling as
FetchTransport, which previously carried three # pragma: no cover - browser only
markers because they could not be exercised outside a browser.

UrllibTransport keeps sending USER_AGENT, since the NEMAR hosts refuse the default
Python-urllib agent. The comment above USER_AGENT claimed browsers "set their own and
ignore this," which is true of Chrome only; corrected it to say so and to point at
FetchTransport for why the browser transports send neither header value.

Why

Filed as #419, from OpenScience-Collective/osa#496: measured in headless WebKit 26.6 and
Firefox 155 (Playwright 1.63) against zarr.nemar.org, with Chrome 153 as the control.
Without the User-Agent header, the same request answers 200 unranged and 206 ranged in
all three browsers; with it, WebKit and Firefox refuse the preflight and the read fails
(a hang in WebKit specifically, worked around separately in
OpenScience-Collective/osa#502, then a TransportError). Allowing User-Agent on the
NEMAR hosts instead would add a preflight to every chunk read in Safari and Firefox, so
the client-side change is the one the issue asks for.

Tests

Added coverage in packages/eegprep-lean/tests/test_transport.py and
tests/conftest.py. PyfetchTransport.get itself is now exercised off Pyodide: a fake
pyodide.http module is installed at sys.modules (conftest.FakePyfetch), whose
pyfetch makes a real request over urllib against the same loopback http.server the
other transport tests already use, and records the headers actually sent. This is a
stand-in for the browser's network boundary, not a mock of business logic, the same kind
of thing as an HTTP response fixture.

  • PyfetchTransport is now a third parametrization ("pyfetch") of the shared
    transport fixture, so it runs through the existing TestRanges and TestFailures
    classes: whole body, closed range, suffix range, open-ended range, a ranged request
    answered in full refused, an unranged 200 not refused, an HTTP error status carrying
    its status, and a connection failure carrying no status but naming the URL.
  • Added TestPyfetchTransport.test_only_range_is_sent_and_never_user_agent, asserting on
    the headers the fake pyodide.http.pyfetch actually received: Range only for a
    closed and a suffix range, and no headers at all for an unranged read.
  • Removed the module docstring line saying PyfetchTransport "cannot be exercised here";
    it now can be, and is.

34/34 tests in test_transport.py pass, 10 of them covering PyfetchTransport (the eight [pyfetch] parametrizations of TestRanges and TestFailures, the header test, and the platform-selection test).

Mutation check (put back, ran, restored, ran again):

  • Restoring the User-Agent header in the adapter: 1 test failed
    (test_only_range_is_sent_and_never_user_agent).
  • Dropping the Range header in the adapter: 4 tests failed (the three ranged
    TestRanges cases for pyfetch, plus the same header test).

Both mutations restored; the full suite is green again.

Full suite, via uv, matching .github/workflows/test.yml's four tiers:

  • Base (PYTHONPATH=src uv run --no-sync --project ../.. pytest tests -m "not network"):
    114 passed, 2 skipped.
  • zarr extra: 120 passed, 1 skipped.
  • plot extra: 114 passed, 2 skipped.
  • Both extras: 149 passed, 3 skipped.

(-m "not network" throughout; the network tier hits the live zarr.nemar.org and runs
in lean-live.yml on a schedule.)

Lint and types, matching the repo's lint CI job:

  • uv run --no-sync ruff check .: all checks passed.
  • uv run --no-sync ruff format --check .: all files already formatted.
  • uv run --no-sync ty check .: no diagnostics in anything touched by this change (3
    pre-existing unresolved-import: torch diagnostics elsewhere in the repo, unrelated to
    this PR and untouched by it).

After merge

eegprep-lean has no PyPI release path of its own (see its README and ADR 0069); OSA picks
this fix up by re-vendoring the wheel by commit (src/assistants/nemar/runtime/ in
OpenScience-Collective/osa, per that directory's README), not through a PyPI release.

Safari and Firefox send a script-set User-Agent header, unlike Chrome,
which drops it. That made PyfetchTransport's User-Agent header turn
every read into a CORS preflight, and zarr.nemar.org allows only Range
in Access-Control-Allow-Headers, so the preflight was refused there.

PyfetchTransport now builds its request through FetchTransport, over
an adapter around pyodide.http.pyfetch, so the header rule (Range
only, nothing at all for an unranged read) has one implementation
instead of two. This also picks up FetchTransport's existing coverage
of the failure paths (connection failure, HTTP error status, a ranged
request answered in full) for PyfetchTransport, which previously
carried three "browser only" no-cover pragmas.

Kept USER_AGENT for UrllibTransport, where it is still needed, and
corrected its comment: browsers dropping a script-set User-Agent is
true of Chrome only.

Tests install a stand-in pyodide.http module at sys.modules (real
requests over urllib against the same loopback server the other
transport tests use), so PyfetchTransport.get is exercised directly
instead of only documented as untestable outside Pyodide.

Tested: uv run pytest across all four eegprep-lean CI tiers (base,
zarr, plot, both extras), ruff check/format and ty check clean.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, reopen this pull request to trigger a review.

@claude

claude Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

1 similar comment
@claude

claude Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@neuromechanist
neuromechanist merged commit 240229b into develop Sep 25, 2026
10 of 12 checks passed
neuromechanist added a commit that referenced this pull request Sep 25, 2026
#420 changed PyfetchTransport's bytes without moving the version, and
OSA vendors the wheel by file name, which it serves as immutable, so
new bytes need a new name before they can be re-vendored.

Tested: eegprep-lean tests, base tier (114 passed, 2 skipped);
eegprep_lean.__version__ reads 0.1.0.dev3.
neuromechanist added a commit to OpenScience-Collective/osa that referenced this pull request Sep 25, 2026
sccn/eegprep#420 makes PyfetchTransport send only Range; its
User-Agent made every notebook read in Safari and Firefox a CORS
preflight zarr.nemar.org refuses (#496). Built reproducibly from
50c50879 (#423); the runtime and the notebook site serve it.

Tested: two builds give sha256 12a07ac4...; build_runtime_lock
--check current; nemar runtime, notebook site and drift pytest (127);
test-data-lane.js 93/93; chrome.js ok; drift watcher current.
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.

eegprep-lean: PyfetchTransport's User-Agent header fails every read in Safari and Firefox

1 participant