Skip to content

Move Web Fetch provider projection and routing into registered adapters - #349

Merged
lanyue-llk merged 3 commits into
mainfrom
refactor/fetch-methods
Nov 24, 2026
Merged

lanyue-llk merged 3 commits into
mainfrom
refactor/fetch-methods

Conversation

@lanyue-llk

Copy link
Copy Markdown
Contributor

Purpose

Adding a Web Fetch provider no longer edits shared modules. Each adapter declares its answer selection policy, evidence capabilities and optional hooks; shared code resolves adapters through one registry and reads declared capabilities instead of provider types.

flowchart LR
  R["PROVIDERS registry<br/>type -> (module, class), lazy import"] --> C["Provider class<br/>(MethodAdapter)"]
  C --> H1["native_answer_selection(selection)"]
  C --> H2["capability_flags"]
  C --> H3["implementation_identity / recorded_implementation_identity"]
  C --> H4["preflight_capacity / capacity_credits_for_cases"]
  C --> H5["call_diagnostics"]
  P["native_projection.py<br/>dispatch + policy identity"] -->|registry| H1
  N["native_routes.py<br/>saved-evidence replay"] -->|provider_capabilities| H2
  U["runner.py / call_boundary.py / risk_control.py"] --> H3
  U --> H4
  U --> H5
  HF["hosted_fetch.py<br/>HostedFetchProvider flow"] --> V["7 vendor subclasses:<br/>endpoint, body, answer fields, envelope rules"]
Loading

What moved or was removed

  • PROVIDER_TYPES dict → harness.adapters.Registry PROVIDERS in providers/base.py (type → module/class, still loaded on demand), plus provider_class() and provider_capabilities(). The route-baseline test, the registry test and the architecture scan derive their type lists from it.
  • Provider conforms to MethodAdapter: capabilities() (from capability_flags), implementation_identity() with a neutral default, recorded_implementation_identity(), preflight_capacity() / capacity_credits_for_cases() no-op defaults, a declared call_diagnostics attribute and a native_answer_selection hook. runner.py, call_boundary.py and risk_control.py call these instead of getattr probing; risk_control.implementation_identity is removed.
  • native_projection.py: the 240-line if-chain over 19 provider types becomes one native_answer_selection(selection) hook per adapter (Lexmount, Claude, Tavily, Exa, Firecrawl, Cloudflare, JSONL worker/CowAgent, Moli, fixture, hosted vendors), dispatched through the registry. Shared helpers stay.
  • native_routes.py: the provider-type set and three special cases become capability flags: malformed_envelope_is_evidence, raw_answer_bytes, raw_stdout_evidence, raw_http_evidence, legacy_markdown_output_label.
  • providers/hosted_fetch.py: 35 self.type branches → HostedFetchProvider (shared call, evidence and failure flow) plus seven small vendor subclasses declaring endpoint, request body, answer fields and envelope rules. Its answer selection is derived from the same description. ENDPOINTS is removed (tests read provider_class(kind).endpoint).
  • native_projection.py and native_routes.py now name no provider (19 and 11 names before → 0).

Breaking changes

No command is renamed or removed. Python API changes, with every in-repository caller migrated:

  • providers.base.PROVIDER_TYPES → PROVIDERS (Registry), provider_class(), provider_capabilities().
  • providers.hosted_fetch.ENDPOINTS removed; each vendor class declares endpoint. HostedFetchProvider is now the shared base, and each hosted type maps to its vendor subclass.
  • risk_control.implementation_identity(provider) removed; use provider.implementation_identity().
  • provider._call_diagnostics → declared provider.call_diagnostics.
  • native_projection.native_projection_source() → native_projection_source(provider_type).

The scorer identity is unchanged (lexbench-webfetch version: scoring_source_sha256 0fe89317…169e); src/lexbench_webfetch/ and dataset content are untouched.

Policy identity (hash-frozen source)

Before, a policy's source_sha256 was the hash of native_projection.py alone, written beside evidence as native-answer-policies/<sha256>.py. Historical versions (1–7) are accepted only through an externally approved registry (digest → version) and replayed by the current code with policy_version=N; saved bytes are hash-checked and never executed.

Now the policy source of a provider type is native_projection.py followed by the module that defines that type's native_answer_selection (each part prefixed by a # native answer policy source: <path> line). The frozen file format, path, version numbers and approval mechanism are unchanged, and every policy_version branch is kept in the adapter hooks, so historical approvals keep verifying. As with every earlier edit of native_projection.py, evidence frozen under main's digest (0fc54974… for all types) verifies through an approved-registry entry {source_sha256, version: 7}; no repository profile binds that digest. The bundle also closes a gap: Moli's selection depended on moli._route_for_case, which was outside the hashed bytes.

Allowlists

  • Instance literals: 3 → 3 (scope unchanged; see below).
  • Layering: 9 → 9.

I did not extend the instance-literal scan to Web Fetch shared modules: it would add 56 entries across 23 modules, mostly in runner, certification, WebMainBench, WCXB and report code owned by other lanes.

Baselines

tests/baselines and tests/golden unchanged. tests/fixtures/native-route-baseline.json is regenerated: every cell binds the policy digest, which changes with any edit of the policy source, and it now covers every registered type with a fixed-native route (19 types, was 13), derived from the registry. Before regenerating, I compared all route cells, endpoints and normalized parameters for all 22 registered types × defaults/configured × 192 synthetic cases between main and this branch with the digest masked: identical.

Behaviour-equivalence checks (scratch, not committed)

  • native_answer_projection: main vs branch over 24 types (22 registered, unknown, None) × 60 payloads × 51 cases × 4 interfaces × 4 statuses × 8 policy versions: 7.5M comparisons, 0 differences (including error messages).
  • Hosted fetch: main's HostedFetchProvider vs the vendor subclasses over 7 vendors × 5 configs × 20 cases × 23 response bodies × 6 HTTP statuses (fetch results with metadata order, request arguments, routes, validation): 93,870 comparisons; the only difference is the order of validate() messages when a Browserbase or Crawl4AI config has both an invalid option and an invalid dns_mode (same set).
  • _expected_native_declaration: main vs branch over every type × raw bodies × output-contract/interface variants: 0 differences.

Remaining provider/engine names (not cheap; left)

  • task_outputs.py: headless engine contract checks (moli, chromium, lightpanda, obscura, kitesurf) — would move into the headless ENGINES definitions.
  • network_preflight.py / local_execution_contract.py: GUARDED_NATIVE_TYPES includes retired types (openclaw_builtin, langchain_webbase, …) that historical local-runner contracts still verify; not representable as capabilities of registered adapters.
  • assembly.py:634, refresh_assembly.py:77: keyed by the configured provider name in historical evidence; a type capability would change which records qualify.
  • comparison_audit.py: a Moli-only audit.
  • failure_diagnosis.py: matches vendor error-message text, not an adapter identity.
  • native_routes.normalized_http_parameters: recognizes three vendor request shapes (Claude messages, Lexmount extract, Browser Use session header) structurally; a per-adapter normalizer hook would remove it.

Verification

  • uv run --frozen --all-extras python -m pytest -q -n 8 tests — 12 failures, the same set that fails on main a0b5b56 in this environment (missing node_modules/benchmark data); no new failures. A Mock provider exposed a regression in the first run (recorded identity must be a dict); fixed.
  • Targeted: provider registry, native route/projection/policy, hosted fetch, saved-matrix evidence, Moli, runner, risk control, architecture and baselines tests: all pass.
  • make lint-check: pass.

Closes #319
Part of #318

@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 · e0b428c

No findings in this review.

…red adapters

Replace PROVIDER_TYPES with a harness.adapters Registry, declare the
MethodAdapter hooks on Provider, move native answer selection into each
adapter, read evidence capabilities instead of provider types, and split
the hosted fetch adapter into vendor subclasses.
…cy sources

Every registered fixed-native type is now covered; route cells are unchanged
apart from the answer selection policy digest.
@lanyue-llk
lanyue-llk force-pushed the refactor/fetch-methods branch from e0b428c to d7aa45e Compare November 24, 2026 08:05
@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Rebased on main after #345. Conflicts were import-only (harness.call_diagnostics.emit, harness.http_client). tests/fixtures/native-route-baseline.json is refreshed in its own commit: the route cells hash each adapter's policy source, and #345 changed the import lines in those provider modules. Route cells are otherwise unchanged. Scorer hash is unchanged (0fe89317…).

@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 · d7aa45e

No findings in this review.

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.

Web Fetch: move per-provider projection and routing into adapters

1 participant