Skip to content

Pass the Web Fetch render context explicitly instead of through a context variable - #392

Merged
lanyue-llk merged 1 commit into
mainfrom
refactor/explicit-render-context
Nov 25, 2026
Merged

lanyue-llk merged 1 commit into
mainfrom
refactor/explicit-render-context

Conversation

@lanyue-llk

Copy link
Copy Markdown
Contributor

Purpose

This is the last part of #389. Web Fetch render state now moves through arguments instead of a context variable, as spec rule 4 requires ("No stage passes state through globals, context variables or undeclared keys"). Before this change, report_model._RENDER_CONTEXT (a ContextVar) carried the participants, suites, banner, score audit, coverage plan, result views and measured methods. Renderer helpers in report.py and the method helpers in methods.py read it implicitly. #390 removed the other context variable in Web Fetch.

New structure

flowchart TD
    PS["page set entry<br/>(render_report → _model_pages / _diagnostic_pages / _research_pages,<br/>WCXB render_pages, WebMainBench sample_pages)"] --> W["with_measured_method_labels<br/>derives scope: MethodScope"]
    W -->|scope=| RM["_render_model(..., scope)<br/>ctx = model_render_context(model, methods=scope)<br/>ctx = replace(ctx, banner=…, score_audit=…)"]
    RM -->|ctx=| R["report.py helpers<br/>write, hero, ranking, overall_ranking, provider_label, …"]
    RM -->|ctx=| X["report_explainer / interfaces / capabilities /<br/>methods pages / pricing / changes"]
    R -->|scope=ctx.methods| M["methods.py<br/>report_method, method_access, browser_method_label,<br/>native_browser_engine, method_version, …"]
    X -->|scope=ctx.methods| M
    O["code outside a render<br/>(release checks, rescoring, storage)"] -->|"RenderContext() / MethodScope()"| R
    O --> M
Loading

What changed

  • report_model.py: _RENDER_CONTEXT, render_context(), set_render_context(), reset_render_context(), rendering(), method_scope() and with_method_scope() are removed. RenderContext and MethodScope are unchanged. The new model_render_context(model, *, methods, descriptive_ranks, result_views) builds the context that rendering(model) used to install.
  • Every helper that read the context now takes it as a required keyword argument: ctx (a RenderContext) in report.py and the other report modules (51 functions in report.py, 22 elsewhere), and scope (a MethodScope) in methods.py (10 functions). An argument left out raises a TypeError; nothing falls back silently.
  • Each page set builds its context where it starts. _render_model builds it from the model and the measured scope and replaces the banner, score audit, coverage plan and scope presentation in place, at the same point where the context variable was set before. The diagnostic, research, WCXB and WebMainBench page sets start from an empty context, which is what they used to read. _scoped_render is removed.
  • with_measured_method_labels passes the scope it derives to the function it wraps as scope=. A wrapped function called inside another render receives the enclosing scope (render_explainer passes ctx.methods). A page set starts from an empty scope.
  • Code outside any render (release checks, rescoring, packaging, storage, native task routes) passes RenderContext() or MethodScope(). These are the defaults it read from the context variable before.
  • The call sites were rewritten mechanically by an AST pass over the call graph. The page-set entries, the decorator and the saved-composition views were edited by hand.
  • Check: tests/architecture/scan.py::context_variable_modules() and test_track_modules_pass_state_explicitly fail when a track module imports contextvars. It has 0 findings and no allowlist. A negative control (adding the import to a track module) fails the test as expected.

reporting/publication_privacy._STAGED_EVIDENCE is the one context variable left in src/. It lives in a shared package and is outside the scope of #389.

Allowlists

Instance-literal 0 → 0; layering 0 → 0; the new context-variable check has 0 findings and no allowlist.

Baselines

Every baseline in tests/baselines/ is byte-identical, with no refresh. Scorer hash unchanged: 0fe8931734e1ba7282e1e9c8303eea958d20fdcee83d84e87cdc7e08cd08169e.

Verification

  • uv run --frozen --all-extras python -m pytest -q -n 8 --dist worksteal tests: 21652 passed, 78 skipped, 2 xfailed. The one failure, test_playwright_backend_executes_portable_and_snapshot_ref_calls, is timing-dependent and passes on its own.
  • make lint-check: passed
  • uv run --frozen lexbench-webfetch version: same scoring-source hash

Breaking changes

None to commands. Python API:

  • report_model.render_context, set_render_context, reset_render_context, rendering, method_scope and with_method_scope are removed. model_render_context() is added.
  • Renderer helpers in harness.web_fetch.report and the other report modules take a required keyword ctx. The helpers in harness.web_fetch.methods take a required keyword scope. A function wrapped by with_measured_method_labels receives scope=.

Closes #389

…text variable

RenderContext and MethodScope stay as they are, but nothing installs them in
module state any more. Every renderer helper that reads the render context
takes it as ctx; the methods helpers (report_method, method_access,
browser_method_label, native_browser_engine, ...) take the measured-method part
as scope. Page sets build their context at their own entry: _render_model from
its model and the measured scope, diagnostic and research pages and the WCXB
and WebMainBench page sets from an empty one, and the saved-composition views
with model_render_context(). with_measured_method_labels passes the scope it
derives to the render function it wraps.

Code outside a render (release checks, rescoring, storage) passes an empty
RenderContext()/MethodScope(), which is what it read from the context variable
before. A new architecture check keeps context variables out of track modules.

Every baseline is byte-identical.

Closes #389

@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 · 6ae4a19

No findings in this review.

@lanyue-llk
lanyue-llk merged commit e631211 into main Nov 25, 2026
10 checks passed
@lanyue-llk
lanyue-llk deleted the refactor/explicit-render-context branch November 25, 2026 08:47
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.

Remove the last instance knowledge and hidden render state from shared code

1 participant