Skip to content

Web Fetch report model, variant registry and track template - #375

Merged
lanyue-llk merged 7 commits into
mainfrom
refactor/fetch-report
Nov 24, 2026
Merged

lanyue-llk merged 7 commits into
mainfrom
refactor/fetch-report

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Web Fetch report builds had no input schema: generate() took dicts plus nine keyword flags, the saved-matrix adapter set renderer ContextVars (_REPORT_PROVIDER_LABELS, _REPORT_SUITES) from outside, the renderer imported back from the saved-matrix module, and scripts/build_report.py chose among ~10 modes with hand-written exclusion lists. This PR implements steps 1–3 of #328 (spec: Report templates, rules 3, 4, 7, 10): one validated report model, a variant registry that every entry point reads, and Web Fetch on the shared track template.

New structure

flowchart TB
    CLI["scripts/build_report.py (thin)<br/>--profile / --variant / --input"] --> REG
    CHK["scripts/check_report.py<br/>--variant saved-matrix"] --> REG
    subgraph REG["report_variants.py: VARIANTS registry"]
        direction LR
        V1["certified"] --- V2["webmainbench-sample"] --- V3["wcxb"] --- V4["webmainbench-full"]
        V5["local-audit"] --- V6["diagnostic-cohorts"] --- V7["published-snapshot-audit"]
        V8["public-benchmark-research"] --- V9["saved-matrix"] --- V10["refresh-presentation / refresh-review"]
    end
    REG -- "accepts / requires / languages /<br/>comparison_kinds / check / render_evidence" --> B["report_build · report_check · report_package"]
    B --> M["report_model.py<br/>ReportModel: participants, suites, records,<br/>manifests, RenderOptions, source admission"]
    SM["report_saved_matrix.py<br/>(adapter, owns generate_saved_matrix)"] --> M
    M --> R["report.generate(out, model)<br/>one entry; rendering(model) scope"]
    R --> T["template.py: TrackTemplate webfetch/1<br/>page sets → base roles; variants"]
    T --> OUT["pages: main[data-page-role]<br/>manifest.template = base, track, variant + versions"]
    OUT --> RC["release checks: check_template_pages → shared check_page"]
Loading

What changed

  1. Report model (report_model.py). generate(out, model) takes a ReportModel validated on construction: dataset with cases, result rows, manifests, declared participants (with labels; a participant without results still gets its route), report-only suites (must partition the cases), RenderOptions (scoped-refresh rules and unknown attempt/case ids checked here), and the saved-matrix source admission (a final_saved_results dataset renders only with the projection hash its source validation admitted). The _REPORT_PROVIDER_LABELS and _REPORT_SUITES ContextVars are removed; renderer state is derived from the model by rendering(model) only. generate_saved_matrix moves into report_saved_matrix.py (its adapter), which removes report.py's reverse imports; the uncalled-participant pages it used to patch in afterwards are written by generate from the model. report_saved_composition.py uses rendering(model) instead of setting three ContextVars.
  2. Variant registry (report_variants.py). Each build mode is a ReportVariant declaring accepted/required arguments, supported languages, the comparison kinds that select it, and its input adapter; optional check, render_evidence, canonical_inputs, reliability_record and renders hooks replace kind comparisons in report_build.build_report (WebMainBench sample dispatch), report_check.check / check_revision (sample release check) and report_package (reliability requirement). scripts/build_report.py is a 40-line entry: the profile selects the variant (variant, else comparison_kind), or one --variant; contradictions are usage errors. configs/report-templates.json lists the registered variants (a test keeps them equal).
  3. Track template (template.py). TrackTemplate("webfetch", 1) maps the standard page set and the complete-cohort page set to base roles, with one template variant per build variant (refreshes render local-audit; the snapshot audit adds audit/ to review; webmainbench-full declares review absent). Every page writer (write, the WCXB, WebMainBench sample/full and research writers) marks main[data-page-role]. Certified, local-audit, diagnostic and snapshot-audit manifests record base/track/variant versions; their release checks run check_template_pages (recorded variant, page roles, slot order via shared check_page).

Removed: report._REPORT_PROVIDER_LABELS, report._REPORT_SUITES, report.generate_saved_matrix, report_saved_matrix.render_saved_with_standard_generator and _require_final_projection, all mode flags and exclusion lists in scripts/build_report.py, the WebMainBench kind branches in report_build, report_check (2) and report_package.

Breaking changes

  • scripts/build_report.py: --local-audit, --diagnostic-cohorts, --webmainbench-full → --variant local-audit|diagnostic-cohorts|webmainbench-full; --saved-matrix SPEC, --public-benchmark-research FILE, --refresh-presentation BINDING, --refresh-review BINDING → --variant <name> --input <file>; --wcxb removed (the WCXB profile selects the variant; --variant wcxb still asserts it).
  • scripts/build_report.py --check-saved-matrix REPORT [--source-spec SPEC] → scripts/check_report.py REPORT --variant saved-matrix [--source-spec SPEC].
  • harness.web_fetch.report.generate(out, dataset, records, manifests, **flags) → generate(out, report_model(dataset, records, manifests, **flags)); generate_saved_matrix is imported from harness.web_fetch.report_saved_matrix.
  • Web Fetch report manifests now record base, base_version, track_template, track_version, variant, variant_version; certified/local-audit/snapshot-audit reports built before this change fail check_report.py ("no recorded variant; rebuild it"), as any registry change already required. Diagnostic reports without a recorded variant keep their previous check.
  • The WebMainBench sample check now prints one generic PASS line.

Allowlists

Instance-literal: 1 → 1 entry (harness.reporting.visual, untouched). Layering: 0 → 0. No shared module changed.

Baselines

web-fetch.json, wcxb.json, webmainbench-sample.json, webmainbench-full.json: route digests only. The sole byte change is data-page-role="…" on the <main> of each template page: with role_attribute() stubbed to "", all four baseline tests pass against the old snapshots unchanged. Headings, table cells, records and summaries are identical. Other tracks' baselines are unchanged. lexbench_webfetch scoring sources are untouched.

Verification

  • uv run --frozen --all-extras python -m pytest tests -n 8 --dist worksteal — 21596 passed after the follow-up fix (2 failures in the first run: a private JSON reader flagged by test_shared_hash_json_helpers and a manifest assertion; both fixed)
  • uv run --frozen --all-extras python -m pytest tests/baselines tests/test_architecture_layering.py tests/test_architecture_instance_literals.py tests/test_report_template_contract.py -n 8 — passed
  • New tests/test_web_fetch_report_variants.py: profile selection (declared variant, comparison kind, explicit conflict), undeclared/missing arguments, one variant per comparison kind, registry ↔ template ↔ configs/report-templates.json, and negative controls for the release check (wrong role, reordered slots, version drift, unrecorded template, missing page).
  • make lint-check — passed.

Not in this PR (remaining)

  • Web Fetch: one report model and a mode registry for report builds #328: the WCXB, WebMainBench sample/full, cohort-diagnostic and public-research generators are still separate functions in report.py; they now share the template page roles, but are not yet views() hooks on the benchmark adapters with one renderer path. Kind branches for risk_control_100_moli, uniform_native_local_measurement, headless_* and synthetic_browser_report remain in report_build/report_check. methods.py keeps three label/record ContextVars around generate, and report.py keeps one internal render scope (now derived only from the model).
  • WCXB, WebMainBench and research manifests do not record a template variant yet, so their checks do not run check_template_pages; Web Fetch does not yet go through reporting.release_check.validate_release.
  • Move report-instance prose and numbers out of renderers, checks and translation maps #330 (Web Fetch part) is not started: measured-value entries in report-translations.json, one-report regex rules in report_i18n.py, messages.json defect prose, and the hardcoded provider labels/slug pattern in report_saved_composition._model_fetch_badges. Moving them needs each published report's bound content (outside Git) updated first.

Part of #328, #337, #331

@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 · 8b47099

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

Comment on lines +805 to +809
if args.variant:
print(VARIANTS[args.variant].check(args.root, source_spec=args.source_spec,
authority_root=args.authority_root,
profile_path=args.profile))
return

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
The variant branch silently ignores --visual-receipt, --presentation-binding and --source-dataset. These options are still accepted by argparse, but this return bypasses both receipt generation and the validation that consumes the bindings/source dataset, so a command can report success without performing explicitly requested checks. Reject these combinations with parser.error if the variant checker cannot support them, or execute/forward the requested checks. Add a CLI regression test for combined options.

Comment on lines +120 to +121
selected = (variant(declared) if declared in VARIANTS
else variant_for_kind(profile.get('comparison_kind')) if request.profile else None)

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
An explicitly declared but unregistered profile variant is silently ignored here. For example, {"variant": "certifed"} selects certified, and --variant certified is accepted despite contradicting the profile declaration. This can run a different build adapter instead of reporting the configuration error. Resolve any non-null declaration through variant(declared) so unknown names raise VariantUsageError; use the comparison-kind fallback only when no variant is declared. Add coverage for an unknown declaration both with and without an explicit CLI variant.

generate() takes a ReportModel (participants, report-only suites, result rows,
manifests, render options and source admission) validated on construction.
The participant-label and suite ContextVars are gone; the renderer derives its
scope from the model through rendering(). The saved-matrix generator moves to
its adapter module, removing the renderer's reverse import.
Each build mode is a ReportVariant in report_variants.py declaring the
arguments it accepts and requires, its languages, the comparison kinds that
select it, and its input adapter. scripts/build_report.py is a thin entry:
the profile (variant, else comparison_kind) or one --variant selects the
build. The evidence-kind dispatch in report_build, the sample check in
report_check and the reliability rule in report_package read the registry
instead of comparing kinds. The saved-matrix check moves to check_report.py.
template.py declares the Web Fetch page sets as base-template roles and
registers one template variant per build variant (refreshes render the local
audit). Every page writer marks its route's role; certified, local-audit,
diagnostic and snapshot-audit manifests record base, track and variant
versions, and their release checks verify page roles and slot order through
the shared check_page.
@lanyue-llk
lanyue-llk force-pushed the refactor/fetch-report branch from 8b47099 to ae48485 Compare November 24, 2026 15:09

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

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

Comment on lines +805 to +809
if args.variant:
print(VARIANTS[args.variant].check(args.root, source_spec=args.source_spec,
authority_root=args.authority_root,
profile_path=args.profile))
return

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
The new variant branch silently skips explicitly requested checks: --visual-receipt, --presentation-binding, and --source-dataset are neither forwarded nor rejected before returning. For example, a valid sample report checked with --variant webmainbench-sample --source-dataset <different-dataset> can report PASS without checking the supplied frozen dataset, unlike the normal path. Reject unsupported option combinations (including --source-spec for variants that ignore it), or run the requested validations before returning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 91e1a9a with a regression test.

Comment thread src/harness/web_fetch/report_check.py Outdated
Comment on lines +806 to +808
print(VARIANTS[args.variant].check(args.root, source_spec=args.source_spec,
authority_root=args.authority_root,
profile_path=args.profile))

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
Resolve a relative --profile against --authority-root before dispatching the variant check, as check() does. _check_webmainbench_sample forwards this path unchanged to check_sample_report, which reads it relative to the working directory and derives its authority directory from profile_path.parent.parent. Consequently, --variant webmainbench-sample --authority-root /external/bundle --profile evaluation/current-report.json reads the local profile/history (or fails with FileNotFoundError) instead of checking against the requested bundle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 91e1a9a with a regression test.

Comment thread src/harness/web_fetch/report_model.py Outdated
Comment on lines +73 to +75
if (self.dataset.get('comparison', {}).get('publication_state') == 'final_saved_results'
and self.source_admission != canonical_json_sha256([self.dataset, self.records])):
raise ValueError('Final saved results require source-backed admission')

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
The admission check only protects the inputs at construction time. dataset and records (including nested dictionaries) are retained by reference despite frozen=True, and generate() only checks the model's type. A caller can construct an admitted model, change a saved verdict through the original records list, and render it without the projection hash being checked again. This loses the previous render-boundary integrity check for final_saved_results. Revalidate the admission against the current inputs at the start of generate() before any renderer mutations, or retain a deeply immutable validated snapshot. Add a regression test that mutates a result after model construction and verifies rendering rejects it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 91e1a9a with a regression test.

Comment on lines +120 to +121
selected = (variant(declared) if declared in VARIANTS
else variant_for_kind(profile.get('comparison_kind')) if request.profile else None)

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
An explicit but unregistered profile variant is silently discarded here. For example, {"variant": "diagnostic-cohort"} selects certified rather than raising a usage error, so a typo can route the request into the wrong build mode. Only fall back to comparison_kind when no variant is declared; otherwise resolve it through variant(declared) and add a regression test for an unknown declaration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 91e1a9a with a regression test.

@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 · 91e1a9a

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

Comment on lines +80 to +82
if (len({suite.id for suite in self.suites}) != len(self.suites)
or len(grouped) != len(set(grouped)) or set(grouped) != case_ids):
raise ValueError('Report suites must partition every case exactly once')

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
Declared suite membership is validated here but is not used to select ranking populations. active_tracks() uses Suite.case_ids, whereas saved_suite_ranking() and the overview select cases with report_family(case) == suite.id. Thus a model with cases in the web family and a valid custom suite containing those cases passes validation but renders an empty suite ranking. Either derive the renderer's report-family mapping from the declared suites or reject mismatches at this boundary; partition validation alone does not guarantee correct results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e2595a7 with a regression test.

Comment thread src/harness/web_fetch/report.py Outdated
Comment on lines +2266 to +2267
entry=_render_model(Path(out),model.dataset,model.records,model.manifests,model=model)
_write_uncalled_participants(Path(out),model)

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
Write the uncalled-participant routes before English generation and language-contract finalization. _render_model() already calls write_english_report(), which discovers the Chinese HTML files present at that point. On a fresh build with include_english=True, participants without records therefore get only a Chinese provider page, while the English tables and language switch link to a nonexistent English counterpart. On a rebuild, an old provider page can instead be translated before this code replaces it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e2595a7 with a regression test.

language=f'''<a href="{safe_href(counterpart)}">{('中文' if english else 'English')}</a>'''
footer=(report_text('en' if english else 'zh')('scores_apply_to_the_frozen_inputs_and', 'Scores apply to the frozen inputs and methods declared in this report. They do not represent the live web or the official WebMainBench leaderboards.'))
page=f'''<!doctype html><html lang="{('en' if english else 'zh-CN')}"><head><meta name="webstone-report" content="1"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{esc(title)} · Web Fetch</title><link rel="stylesheet" href="{base}assets/style.css"><script src="{base}assets/report.js" defer></script></head><body><header class="top"><nav class="wrap">{brand}{nav}{language}<button class="theme-toggle" onclick="theme()">{report_text('en' if english else 'zh')('toggle_theme', 'Theme')}</button></nav></header><main>{body}</main><footer class="wrap source-note"><p>{footer}</p></footer></body></html>'''
page=f'''<!doctype html><html lang="{('en' if english else 'zh-CN')}"><head><meta name="webstone-report" content="1"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{esc(title)} · Web Fetch</title><link rel="stylesheet" href="{base}assets/style.css"><script src="{base}assets/report.js" defer></script></head><body><header class="top"><nav class="wrap">{brand}{nav}{language}<button class="theme-toggle" onclick="theme()">{report_text('en' if english else 'zh')('toggle_theme', 'Theme')}</button></nav></header><main{role_attribute(path)}>{body}</main><footer class="wrap source-note"><p>{footer}</p></footer></body></html>'''

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 new attribute breaks the WebMainBench sample release gate. validate_sample_content() in webmainbench_report_check.py extracts the bound guide with re.search(r'<main>(.*)</main>', page, re.S), and check_sample_report() calls it unconditionally. This writer now emits <main data-page-role="interpretation"> for guide/index.html, so extraction returns None and newly generated sample reports fail with “Sample guide differs from bound content”. Update the extraction to accept attributes while preserving the exact inner-content comparison, and add a generated-guide validation regression test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e2595a7 with a regression test.

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

No findings in this incremental 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.

1 participant