Repository navigation
refactor(web-fetch): select providers and headless engines through registries - #184
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 1
Head reviewed: af99f1d6. Two findings, both about what the change pins or documents. I found no behaviour regression in the code.
Findings
P2: tests/test_headless_engine_routes.py:140 does not pin native CDP server argument order
- Problem:
_server_commandsonly exercises one option at a time, so no scenario has two optional arguments together. The relative order of the server template slots is therefore unpinned, though #180 asks to pin every command line and the PR body lists CDP servers as covered. - Evidence: I swapped these slots in
ENGINES, one engine at a time. Each mutant passed the route snapshot and seven other headless and native test files (323 passed, and the only failure is on the known local list):- Moli:
_LOG_LEVEL, _BLOCK_PRIVATE_NETWORKS, _CA_CERT, _PROXY - Lightpanda:
_CA_CERT, _PROXY, _PROJECTION_IFRAMES - Obscura:
--quiet, _PROXY, _PRIVATE_NETWORK
- Moli:
- Fix: Add an all-options variant to
_server_commands, as_cli_commandsalready does withall-network. It should set proxy, CA certificate, private network, block private networks, log level andoutput_mode: resource. Record its snapshot lines from the base commit's code, so the pin still proves the old order. The current order is correct (see below), so only the pin is missing.
P2: docs/provider-contract.md:89-92 overstates what ENGINES owns
- Problem: "Add or change engine behaviour there" is not yet true.
headless_worker.pystill selects routes by engine name (lines 233, 258, 281, 299, 353, 357, 386 and 423). For example, line 281 only runs the CLI route formoli,obscuraandlightpanda.task_outputs.py:183rejects any other engine, andnetwork_preflight.py:78testskitesurfby name. Someone adding an engine from this paragraph would get a command line the worker never runs. The PR body and #183 disclose this, but the permanent doc does not. - Fix: Say that a new engine still needs matching changes in those three files until #183 lands, and that editing the worker means rebuilding the declared resource images.
Verified with no defect
-
Old against new behaviour: I loaded the base commit's
headless.pynext to the new one and compared results, including error type and message:Function or path Inputs compared Differences cli_command124,131 sampled combinations 0 native_cdp_browserargv and environment, with all option combinations960 0 completion_metadata432 0 output_mode_for_case2,880 0 fetch, complete metadata, worker request and Cloudflare config5,940 0 _resolve_binary60 0 validate1,792 16 -
The 16
validatedifferences: All haveengine: Nonewithnative_metadata: {}. The old code raisedTypeErrorand the new code reportsengine. This is harmless, though the PR body does not mention it. -
Snapshot provenance: The route test passes on the first commit, which has the unchanged code, and the second commit changes neither the snapshot nor that test.
-
Mutation check: 19 of 21
ENGINESfield mutants fail the route test. The other two are the Moli slot order above andretain_cdp_server_log, whose removal is caught bytest_native_cdp_port.py. -
Provider registry: All 19 types resolve to
Providersubclasses, and modules still load on demand. The unknown-type error is unchanged. I read the mapping against the removed if-chain and it matches. -
Frozen bindings:
headless_worker.pyis byte-identical, and the worker imports only functions that still exist.- No file under
evaluation/orconfigs/, and no report snapshot, changed. runtime_source_sha256does change for new runs, because it hashes the source tree. The PR discloses this.- Request fields sent to resource containers match the old code, so existing images stay compatible.
-
Scope:
Closes #180holds. No engine-name branch remains inheadless.py, and the items left over are outside the two files the issue targets or are bound by the worker hash. #183 tracks them. -
Local checks: Both ruff commands pass.
tests/test_golden_reports.pygives 10 passed. New and neighbouring headless tests pass, apart from two failures on the known local macOS list. The snapshot contains no private paths.
CI
All checks on af99f1d6 pass: Tests and static checks, Installation and packaging, Rendered reference and report checks, Python 3.11, Select check scope, OCR dispatch and ocr-review. main has not moved from the PR's base f877f6a6.
|
Review round 1 follow-up. Both findings are fixed; none are disputed.
Local checks: ruff passes. |
There was a problem hiding this comment.
ℹ️ Review skipped · 2cc44a8
No reviewable content was selected for this run.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review, round 2
Head reviewed: 2cc44a88, on base f877f6a6, which is still the tip of main. No defects found. Both round 1 findings are fixed.
Round 1 fixes
- CDP server argument order: the
all-optionsvariant is in_server_commands. Its snapshot lines match the if-chain code (see the base-commit run below). docs/provider-contract.md: the paragraph now names the worker,task_outputs.pyandnetwork_preflight.py, and all three claims hold. The engine-set check is attask_outputs.py:183, thekitesurftest is atnetwork_preflight.py:78, and the resource image worker check is inContainerResourceRunner.validate.
What I verified
- Snapshot against the old code: I copied the head's test file and
headless-engine-routes.jsonlonto the unmodified base commit. All 8 tests pass, so the snapshot does describe the if-chain behaviour, including the all-options lines. - Old and new code compared directly: I loaded both versions of
headless.pyside by side and found 0 differences across 403,072 randomized or enumerated comparisons.cli_commandandcompletion_metadata, including error type and message.output_mode_for_case, including unregistered names and a third provider type.- Inputs included frame selectors, delays around the whole-second boundary, an empty proxy string and fractional timeouts. This was a one-off check and is not committed.
- Line-by-line reading: the
wait_untilandextractorchains, the subdocument interface and support values,validate,implementation_identity, the hosted Kitesurf fields and the native CDP server arguments all match the old branches. Every template slot is supplied on the route that uses it, so no placeholder can reach a command line. - Do the tests catch changes? I made 16 one-off changes to the
ENGINESdata. The route snapshot caught 15. The other, turning offretain_cdp_server_log, is caught bytests/test_native_cdp_port.py. - Disclosed behaviour change:
fetchnow raises for an unregistered engine.validate()already rejected those engines, and the only other caller I checked,providers/moli.py, passesengine: moli. - Frozen bindings:
headless_worker.pyis byte-identical to base. The PR changes nothing underevaluation/orresearch/, or the report data undersrc/harness/web_fetch/data/. The only golden file touched is the new route snapshot.tests/test_golden_reports.pypasses with no snapshot changes. - Scope: #180 names
build_providerand the branches inproviders/headless.py. The only engine-name check left in that file isengine in ENGINES, and the registry now owns the rest. The remaining branches in other files are tracked in #183, and the worker's hash binding is disclosed as the issue requires.Closes #180is accurate. - Public repository check: I found no local usernames, paths or credential values in the golden file. The only hit is the
api_tokenfield name in a validation error list.
Test runs
- Both ruff gates pass.
- Local targets:
test_headless_engine_routes,test_provider_registry,test_golden_reports,test_headless,test_headless_completion,test_headless_files,test_headless_cancellation,test_native_cdp_port,test_native_task_outputsandtest_report_method_registry. Result: 201 passed, 11 skipped, 1 failed. The failure,test_headless.py::HeadlessTests::test_converter_shared_and_nonzero_not_converted, is on the known local macOS list. - I did not run the full suite locally. CI on this head is the full-suite gate, and all checks pass, including "Tests and static checks" and "Installation and packaging".
Issues
Closes #180
Remaining engine branches outside this scope are tracked in #183.
Summary
PROVIDER_TYPESinproviders/base.pyreplaces thebuild_providerif-chain. A new provider is one entry. Modules still load on demand.ENGINESinproviders/headless.pynow maps each engine name to aHeadlessEnginedefinition. It holds command-line templates, CDP server arguments, completion semantics, task routes, recorded metadata and the hosted backend. All engine-name branches in that file are gone.tests/golden/headless-engine-routes.jsonlfrom the unchanged if-chain code. The second commit does the refactor and leaves that snapshot untouched. A later test commit adds an all-options CDP server variant that pins argument order; those lines were also recorded from the if-chain code. The snapshot covers CLI commands, CDP servers, completion metadata, output modes, fetch routes, validation, implementation identity and cancellation.Frozen bindings
headless_worker.pyis deliberately unchanged, and its SHA-256 is the same. It is recorded asworker_sha256andexecution_sha256on every call and asadapter_input_sha256in the cohort comparison.ContainerResourceRunner.validatealso rejects a resource image whose worker bytes differ from the host, so editing it means rebuilding every declared image. Its engine branches therefore remain; Move remaining headless engine branches into the engine registry #183 tracks them, along with the literals intask_outputs.pyandnetwork_preflight.py.runtime_source_sha256. It hashes all ofweb_fetch/**/*.py, so any source edit changes it. A cohort already in flight must finish on its frozen source, as with any other change here.One behaviour change
HeadlessProvider.fetchnow raisesValueErrorfor an unregistered engine. Before, an unvalidated provider continued, recorded made-up metadata such asmoli_cdp_response, and launched the binary through Playwright.validate()already rejected such a configuration withengine, so a validated run never reached this path. Unregistered names stay accepted byoutput_mode_for_case, because reports use them as labels.Test plan
ruff check --select F,TID252andruff check: pass.tests/test_headless_engine_routes.py: pass on both commits, with the same snapshot.tests/test_provider_registry.py(new): pass.tests/test_golden_reports.py: pass, with no snapshot changes.cli_commandgave identical results on 221,184 combinations of engine, mode, plan, native metadata, timeout and options..git: 19,636 passed, 60 skipped, 27 failed.test_optional_reports,test_packaging_hygiene,test_public_tree_privacy,test_report_software_versions,trajectory_replay/test_hf_inputsandtrajectory_replay/test_run_webarena_catalog.test_optional_reportstests still fail, with a dataset lock error. The worktree sits inside an older checkout, and dataset path resolution finds that checkout's binding. The 4test_headless_runnerandtest_selected_native_policyfailures seen only in the worktree have the same cause, and those two files pass on an extracted copy of the base commit.