Skip to content

refactor(web-extract): method, engine, benchmark and report-shape adapters - #348

Merged
lanyue-llk merged 5 commits into
mainfrom
refactor/extract
Nov 24, 2026
Merged

lanyue-llk merged 5 commits into
mainfrom
refactor/extract

Conversation

@lanyue-llk

Copy link
Copy Markdown
Contributor

Purpose

Move Web Extract instance knowledge out of shared branches and into registered adapters (docs/spec.md, "Extension points"): methods and self-hosted engines become adapter objects, benchmarks declare their fields, schema, review prompts and analysis controls, and the report has one build and one check entry with task-shape hooks.

flowchart LR
    subgraph Methods["pipeline.METHODS (Registry[ExtractMethod])"]
        M["ExtractMethod<br/>request · project · usage<br/>options · input · capabilities()"]
    end
    subgraph Engines["self_hosted.ENGINES (Registry[Engine])"]
        E["Engine<br/>version · extract · identity<br/>attest · failure · unavailable"]
    end
    subgraph Benchmarks["dataset.BENCHMARKS (Registry[ExtractBenchmark])"]
        B["ExtractBenchmark<br/>profile · module · fields · schema<br/>valid_value · reference_controls<br/>review_prompts · capabilities"]
    end
    subgraph Report["report.REPORT_SHAPES (Registry[ReportShape])"]
        R["product · record cohort · suite<br/>build + check hooks"]
    end
    PC["provider_call / normalize"] --> M
    M -- "self-hosted route" --> E
    W["worker / health / native_failure"] --> E
    P["prepare / validate / certify / review / analysis"] --> B
    BLD["report.build"] --> R
    CHK["report.check"] --> R
Loading

What moved or was removed

  • METHODS dict of dicts → Registry[ExtractMethod] (conforms to harness.adapters.MethodAdapter). Each adapter carries its request builder, envelope projection (project), post-call usage hook and request_settings. The elif method == chain in normalize, the method branches in provider_call and the method checks inside request builders are gone (shared builders were split per method around small shared helpers). available_methods() removed; callers use METHODS.
  • Self-hosted engines: ENGINES → Registry[Engine] with version, extract, identity, attestation, failure and availability functions. validate_input, local_runtime_identity, runtime_identity, native_failure, worker and /health contain no engine names.
  • BENCHMARKS → Registry[ExtractBenchmark]. The product benchmark declares fields, derived_fields, schema, default instructions, valid_value, reference_controls and its two review prompts; record benchmarks declare the record review prompts. PRODUCT_FIELDS/SCHEMA/PROFILE in pipeline.py, FIELDS in review.py and the reference controls in analysis.py now come from the adapter. Name branches replaced: prepare default benchmark, validate_dataset records evaluator (exported_evaluator capability), benchmark_config default and records profile (profile is None), certification SWDE instruction default (implicit_record_instructions capability), model-comparison SWDE scoring (record reference shape), CLI --benchmark default.
  • report.py: build and _check_rendered_report dispatch through REPORT_SHAPES, keyed by the content/manifest mode; the product shape remains the default for content without a registered mode, as before. The record cohort self-check goes through the single check path. rendered_files replaces two copies of the file inventory.
  • New tests/web_extract/test_registry_contract.py iterates all three registries.

Kept in place on purpose: method registrations stay in pipeline.py and engine registrations in self_hosted.py, because pipeline.py is the frozen execution snapshot (execution/pipeline.py, pipeline_sha256) and self_hosted.py is hashed into the runtime implementation_sha256; moving them would leave request and engine code outside those bindings.

Remaining (not in this PR)

  • Web Extract: benchmark-declared fields and one renderer #324: the product and record-cohort renderers are still two bodies (~830 and ~870 lines) behind one dispatch; they share no copied blocks, so merging them is a rewrite of the product pages into the record layout with a three-field schema. report.py and analysis.py still spell product field names (OutOfStock, table columns).
  • Define the benchmark adapter interface and the pipeline skeleton each track follows #338: ExtractBenchmark does not yet expose the cases/inputs/score/populations hooks of BenchmarkAdapter; the Extract pipeline still calls the task module's prepare/probe_cases/score directly.
  • pipeline.check_projection_controls / check_record_projection_controls still name the method whose projection they exercise.

Breaking changes

No command is renamed or removed. webstone web-extract prepare --benchmark keeps its choices; its default is no longer spelled out as a name but still selects the single-schema product benchmark, so the behaviour is unchanged.

Python API changes inside harness.web_extract (all callers migrated in this PR):

  • pipeline.available_methods() removed; use pipeline.METHODS (a Registry[ExtractMethod], attribute access instead of dict keys).
  • pipeline.valid_product_value moved to dataset.valid_product_value (also PRODUCT.valid_value); pipeline.SCHEMA is now the product adapter's schema.
  • analysis.REFERENCE_CONTROLS moved to dataset.PRODUCT_REFERENCE_CONTROLS (PRODUCT.reference_controls).
  • dataset.BENCHMARKS is a Registry[ExtractBenchmark]; benchmark_config() also returns the adapter under "benchmark".
  • self_hosted.ENGINES is a Registry[Engine].
  • report.build_record_cohort takes the shared hook signature (adds run).

Scorer identity unchanged: uv run --frozen lexbench-webfetch version prints scoring_source_sha256 0fe8931734e1ba7282e1e9c8303eea958d20fdcee83d84e87cdc7e08cd08169e. No HF dataset content or card config is touched.

Allowlists

  • Layering: 9 → 9 entries (no Extract change in scope).
  • Instance literals: 3 → 3 (Web Extract track modules are outside the scan's shared scope; the scanner now reads METHODS.names()).

Baselines

tests/baselines/ unchanged for all four Web Extract modes (and the other tracks). Behaviour notes: unknown method/benchmark names now raise the registry's ValueError instead of KeyError; /health lists engines in registry (sorted) order.

Verification

make lint-check                                            # passed
uv run --frozen --all-extras python -m pytest tests/web_extract tests/baselines \
  tests/test_architecture_layering.py tests/test_architecture_instance_literals.py \
  tests/test_adapters.py tests/test_reporting_reader_contract.py -n auto   # 1751 passed, 15 skipped
uv run --frozen --all-extras python -m pytest tests/benchmarks/test_publication.py   # 77 passed

Closes #320
Part of #324
Part of #318
Part of #338

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

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +48 to +52
PRODUCT = fixed_field_benchmark()
PROFILE = Path(__file__).resolve().parents[1] / "benchmarks/cards" / PRODUCT.profile
PRODUCT_FIELDS = PRODUCT.fields
FIELDS = (*PRODUCT_FIELDS, *PRODUCT.derived_fields)
SCHEMA = PRODUCT.schema

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
Moving these declarations and the default request instructions into dataset.py leaves product executions outside the frozen implementation boundary. task_bindings() returns {} for the product benchmark, and both probe collection and certification only add the dataset registry hash for record datasets. Consequently, changing PRODUCT_SCHEMA or PRODUCT.instructions without changing pipeline.py can pass resume/preflight implementation checks while sending different requests within the same product run (the probe resume comparison also does not compare schema). Bind and verify the benchmark registry for product runs too, and include the dependency in the execution snapshot so the frozen pipeline retains its original declarations.

@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 · 3dd6ba2

This review found 1 issue(s), including 1 blocking issue(s).

Comment on lines +48 to +52
PRODUCT = fixed_field_benchmark()
PROFILE = Path(__file__).resolve().parents[1] / "benchmarks/cards" / PRODUCT.profile
PRODUCT_FIELDS = PRODUCT.fields
FIELDS = (*PRODUCT_FIELDS, *PRODUCT.derived_fields)
SCHEMA = PRODUCT.schema

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · high
The product request semantics now depend on dataset.py, but product runs do not bind that file: task_bindings() returns {} for this benchmark, and _probe_unlocked() only adds those bindings for task adapters. Consequently, changing PRODUCT.schema or PRODUCT.instructions without changing pipeline.py passes the existing resume/preflight implementation checks and can mix different requests into the same frozen cohort. Although the schema is recorded in the contract, it is not compared during resume, and the product instructions are not bound there. Include the benchmark declaration source (or a complete resolved semantic identity) in product execution contracts and enforce it in resume/preflight validation.

Each Web Extract method is an ExtractMethod in a harness.adapters.Registry
carrying its request builder, envelope projection and post-call usage hook.
provider_call and normalize dispatch through the adapter; request builders
no longer branch on method names. Self-hosted engines register version,
extract, identity, attestation, failure and availability functions.
… on adapters

BENCHMARKS becomes a registry of ExtractBenchmark objects. The product
benchmark declares its fields, schema, default instructions, value rules,
reference controls and review prompts; record benchmarks declare theirs.
Name branches on the default benchmark give way to declared capabilities
(exported evaluator, implicit record instructions) and to the single-schema
benchmark owning manifests without a benchmark name.
…e hooks

build and _check_rendered_report dispatch through REPORT_SHAPES keyed by
the content or manifest mode; product, record cohort and suite renderers
become hooks. A shared rendered_files inventory replaces two copies.
Product request declarations moved to dataset.py, so every run contract and
certified plan now records dataset_registry_sha256; resume and certified
collection reject a changed registry. Plans recorded before this field
still verify.

@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.

✅ Re-review complete · d8343e6

No findings in this incremental review.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Rebased on main after #345, #349, #351 and #346 (head d83f41d).

  • Conflicts: pipeline.py imports (kept harness.http_client.request from refactor: shared HTTP/privacy/style modules and uniform webstone <track> <stage> verbs #345 and this PR's dataset declarations). tests/architecture/scan.py registered_names now combines PROVIDERS.names(), ADAPTERS.names() and this PR's METHODS.names().
  • OCR (3dd6ba2) product runs not binding the registry: fixed. Probe contracts and certified plans now record dataset_registry_sha256 for every benchmark, including product. Resume already compares it, and certified collection and frozen verification now reject a changed registry. Plans written before this field still verify.
  • The earlier secondary-shard failure (KeyError: 'identity_patterns' in web-search tests) does not touch Web Extract code, and the same tests pass on sibling PRs on the same base. I'm treating it as a flake and watching the new run.
  • No golden or baseline refreshes, allowlists unchanged, scorer hash unchanged.

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

No findings in this review.

…ng definitions

default_patterns() is cached per process. When this test was a worker's first
caller, the stubbed definition_path cached the test dataset as the patterns, and
later factual-acceptance tests failed with KeyError: 'identity_patterns'.
@lanyue-llk

Copy link
Copy Markdown
Contributor Author

The secondary shard failed three times in a row (KeyError: 'identity_patterns' in web-search acceptance tests). Root cause: the order-dependent test bug below, which already exists on main. This PR's test set changes how the shard is scheduled, which is why it shows up here.

  • lexbench_websearch.evidence_quality.default_patterns() is @cached per process.
  • When test_simpleqa::test_locked_dataset_repair_updates_gold_for_all_saved_methods is the first caller in a worker, its stubbed definition_path makes the cache hold the stub dataset in place of the patterns.
  • I found it by recording, per xdist worker, which test first filled the cache.

Fix (81c19f4): the test resolves the real patterns before stubbing. Run in that order, the pair fails 5 tests without the fix and passes with it. No scorer source changed (hash 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 skipped · 81c19f4

No reviewable content was selected for this run.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

All required checks pass on 81c19f4. The one primary-shard failure on the first run was test_run_webarena_catalog::test_remote_setup_recovery_retries_connection_before_evidence, a 1 s timing-sensitive trajectory test unrelated to Web Extract; it passed on rerun. OCR on the latest head found nothing. Merging.

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 Extract: replace per-method chains with adapter objects

1 participant