Skip to content

fix(qed): keep spawned verifier imports lightweight - #1491

Merged
burtenshaw merged 5 commits into
mainfrom
fix/qed-verifier-startup
Oct 26, 2026
Merged

burtenshaw merged 5 commits into
mainfrom
fix/qed-verifier-startup

Conversation

@burtenshaw

Copy link
Copy Markdown
Collaborator

Summary

Spawned QED verifier workers eagerly imported the client and complete server, including Gradio and datasets, inside the five-second request deadline. Cold startup can exhaust both attempts and turn correct answers or wrong-answer penalties into neutral timeout rewards (seen in CI on #1469 and #1270).

 worker import
-  client + OpenEnv/Gradio + server/datasets/OpenAI
+  math verification dependencies only
 public package exports
+  resolve lazily, preserving class identities

Only the two QED package initializers change. Request deadlines, retries, grading, and existing fixtures are unchanged.

Evidence

  • Before: Python 3.11 cold worker import: 13.907s. Injecting an 11s delay into datasets import reproduces test_correct_gives_max_reward: score 0 instead of 7, with two 5s timeouts; workers subsequently finish. The new subprocess regression fails because the worker imports openenv.
    After: worker import: 0.216s. All three originally failing tests pass with that same delay; 149 QED tests pass (5 integration tests deselected). Regression verifies isolated imports, real spawned correct/wrong grading, and public export identity.

  • Relevant dependency versions match failing CI: math-verify 0.9.0, SymPy 1.14.0, latex2sympy2-extended 1.11.0, ANTLR 4.13.2. Reproduction is local macOS Python 3.11; CI itself has not been instrumented.

  • Changed-file formatting/import sorting and repository ruff check src/ tests/ pass. Global formatting hook reports existing issues (including grid-world/Julia import ordering and 47 unrelated formatting files). The test hook requires unavailable GNU timeout; its pytest command was run directly.

  • Full Python 3.11 suite: 3,882 passed, 135 skipped, 66 deselected; 1 unrelated failure. Harbor port-binding test expects "already in use" but gets a startup timeout on macOS; the identical failure reproduces independently on unchanged main (cad76b7a).

Merge Danger

Door: two-way

Blast Radius: QED

Public imports remain available, but application dependencies now load when their exported classes are requested. No API signatures or architecture change; no RFC needed. Independent review and CI required before merge.

@burtenshaw burtenshaw added bug Something isn't working environment size: small Small pull request labels Oct 26, 2026 — with Cursor

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alignment Review Report

Automated Checks

  • Lint: FAIL (minor) — usort wants from typing import Any, TYPE_CHECKING (alphabetical) in both touched __init__.py files; they currently read TYPE_CHECKING, Any. ruff format/ruff check are clean. Note CI's lint job (test.yml) only runs over src/ and tests/, so this won't fail CI, but it's a one-line fix for consistency with the rest of the repo (e.g. atari_env/client.py, openspiel_env/client.py, sync_client.py all sort Any before TYPE_CHECKING).
  • Debug code: CLEAN — no prints/breakpoints/TODOs introduced by this diff.

Open RFCs Context

Scanned rfcs/000–012. None reference QED-Math, math_verify, process pools, or lazy imports, so there's no overlap with any open RFC (several are Draft/In Review, e.g. 010 echo-env-token-world-model and 011 ard-catalog-discovery, but they're unrelated to this change).

Tier 1: Fixes Required

  • envs/qed_math_env/__init__.py:10 — usort import-order: from typing import TYPE_CHECKING, Any → from typing import Any, TYPE_CHECKING.
  • envs/qed_math_env/server/__init__.py:9 — same usort import-order fix.

Tier 2: Alignment Discussion

Principle Conflicts

None identified. The __getattr__/TYPE_CHECKING lazy-export pattern this PR adds to qed_math_env/__init__.py and qed_math_env/server/__init__.py matches the existing convention already used in browsergym_env/__init__.py, thinkingbox_env/__init__.py, calendar_env/__init__.py, and finqa_env/server/__init__.py (same globals() caching + __dir__ shape), so it's consistent with prior art rather than introducing a new pattern. It doesn't touch the client/server boundary, reward computation, or the Gym-like/MCP dual API, so no invariant is at risk.

RFC Conflicts

None identified.

Verification

  • New tests pass: tests/envs/test_qed_math_worker_imports.py::test_spawned_verifier_does_not_import_application and ::test_public_package_exports_keep_their_identity (2/2 passed).
  • Existing suite: tests/envs/test_qed_math_environment.py — 147 passed; the 5 failures are the pre-existing @pytest.mark.integration tests that need a live server on localhost:8000 (excluded by CI's -m "not integration and not network and not docker"), unrelated to this change.

Summary

  • 2 mechanical issues to fix (import-sort order, non-blocking for CI but easy to clean up)
  • 0 alignment points for human review
  • 0 RFC conflicts to discuss

Nice, well-scoped fix — the lazy-export pattern is well-tested and matches the convention already used elsewhere in the repo.

Open in Web View Automation 

Sent by Cursor Automation: Pre-review

@burtenshaw

Copy link
Copy Markdown
Collaborator Author

Addressed review 5656435359 in 04d3172: reordered typing imports in the two QED init.py files. Installed usort check, ruff format --check, and ruff check all pass (no formatter disagreement). QED tests: 149 passed, 5 integration tests deselected, including spawned-worker isolation and public-export identity regressions. No main merge needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working environment size: small Small pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant