Skip to content

eegprep-lean: let the host choose the transport - #414

Merged
neuromechanist merged 3 commits into
developfrom
feature/issue-413-host-transport
Sep 22, 2026
Merged

neuromechanist merged 3 commits into
developfrom
feature/issue-413-host-transport

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Closes #413.

What changed

  • FetchTransport(fetch): a Transport over a client the host supplies, awaited as fetch(url, headers=...) and returning (status, body).
    It sends Range and nothing else, and applies the checks the built-in transports apply: a status of 400 or more is a TransportError, a range answered in full is refused, and a client that raises becomes a TransportError with no status.
  • set_default_transport(transport): the host that owns the interpreter chooses what default_transport() returns; None restores platform selection, and an explicit transport= still wins.
  • README: a short section on running inside a runtime that owns the network.
  • Version 0.1.0.dev1, in its own commit, so a host caching wheels by filename never serves the old bytes under the same name.

Why a module-level default

AGENTS.md asks for no hidden global state, so this deserves a word.
The default is environment configuration, set once by the host before any reader code runs, in the way zarr.config is; no processing function reads it except through default_transport(), and every reader still takes transport= explicitly.
The alternative, threading a transport through every call, would make NEMAR's python_browser recipe (await open_array(url)) wrong in exactly the runtime it is written for.

Tests

  • tests/conftest.py adds HostFetch, a host client that makes real HTTP requests with urllib and returns the status rather than raising, plus a fixture that restores the default after each test.
  • test_transport.py: FetchTransport against the existing loopback server (closed, open-ended and suffix ranges, only Range sent, a range answered in full refused, 404 carrying its status, a dead port with no status), and the default selection, including emscripten.
  • test_read_window.py: a sharded store read end to end with no transport= argument, through a registered FetchTransport, with the shard index and inner chunk shown to go through the host's client.
  • All four extra tiers pass locally, and the installed wheel passes the offline suite. ruff check, ruff format --check and ty check are clean.
  • Mutation-checked: removing the override, the status check, the full-answer check or the exception mapping, or adding a header, each fails a test.

FetchTransport reads through a client the host supplies, and
set_default_transport makes it the default, so a sandboxed runtime
without pyodide.http can still run reader code written with no
transport= argument. Tested against the real loopback servers,
all four extra tiers, ruff and ty.

Refs #413
A new wheel filename, so a host caching wheels by name never serves
the old bytes under it.

Refs #413

@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 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

A client that does not follow redirects hands back the 3xx, and an
opaque response reports 0; both were read as data. The Fetch contract
now says a refusal raises rather than answering 403, which the store
reads as absence. Shared transport tests are parametrized over both
implementations, the default resets after every test, and an explicit
transport= is shown to beat a registered one. All tiers pass.

Refs #413
@neuromechanist

Copy link
Copy Markdown
Member Author

🤖 Review round 1: five reviewers (code, tests, error handling, comments and types, simplification). Addressed in the latest commit:

  • 3xx and status 0 passed through as data. A host client that does not follow redirects hands back the 3xx, and a browser reports an opaque response as 0; zarr would have received an empty document with no error. FetchTransport now accepts only a 2xx. Tested with a real 302 from the loopback server (the test client no longer follows redirects) and a status-0 client.
  • A refusal dressed as a 403 would read as absence, since the store maps 403/404/416 to a missing key. The Fetch docstring and the README now say a refused request must raise.
  • The try covered the tuple unpacking, so a client breaking its own contract was reported as "request failed". Only the await is inside it now.
  • Duplicated tests. TestRanges and TestFailures are parametrized over UrllibTransport and FetchTransport, which also restores the [404] assertion the copy had dropped.
  • Leak risk. The default resets after every test (autouse), not only for tests that ask.
  • An explicit transport= beating a registered default is now tested end to end through read_window, and the host test uses the top-level eegprep_lean. names.
  • bytes(body) has a comment and a test with a memoryview body.
  • CORS wording. Range is safelisted only as bytes=N-M, so the suffix form still costs a preflight; the docstring says so.

Deliberately not changed:

  • A body that cannot become bytes raises TypeError rather than TransportError. That is a host breaking its own contract, and it should fail as itself (the error-handling review's point, which conflicted with the test review's).
  • _host_default is not None against truthiness: no transport here is falsy, and identity is the correct check.
  • Pre-existing and outside this diff: [tool.ty.rules] invalid-argument-type = "ignore" in the root pyproject.toml means ty cannot catch a wrong-shaped Fetch at a call site. Worth knowing; not changed here.

All four extra tiers pass locally (134 with both extras), plus ruff and ty. Each new check was mutation-tested (removing the override, loosening the status check to >= 400 or dropping its lower bound, dropping bytes()); each mutation fails a test.

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: let the host choose the browser transport

1 participant