Repository navigation
test(qed): cover worker import isolation and busy-worker recovery - #1492
Conversation
There was a problem hiding this comment.
Alignment Review Report
Automated Checks
- Lint: PASS —
uv run usort check/ruff format --check/ruff checkall pass on the three files this PR touches (envs/qed_math_env/__init__.py,envs/qed_math_env/server/__init__.py,tests/envs/test_qed_math_environment.py). (Note: a full-reporuff format --checkreports 47 files needing reformatting, but none of them are touched by this PR — pre-existing drift, not introduced here.) - Debug code: CLEAN — no
print/breakpoint/pdb/TODO/FIXME in the diff.
Verification performed
- Installed the env's own deps (
math-verify,datasets,fastmcp,trackio) and rantests/envs/test_qed_math_environment.py: 151 passed, including the two new tests (TestVerifierImports::test_worker_import_does_not_load_environment_dependencies,TestVerifierImports::test_public_exports_preserve_identity) and the newtest_busy_worker_deadline_and_cancellationcases. The 5 errors inTestQEDMathServerIntegrationare pre-existing (that class predates this PR) and only fail here because no live server is running in this sandbox — unrelated to this change. - Confirmed the actual fix in a fresh interpreter:
import qed_math_env.server.math_verify_serviceno longer pulls inqed_math_env.client,qed_math_env.models,datasets,fastmcp, oropenai— exactly the problem aspawn-contextProcessPoolExecutorworker hits on re-import. - Confirmed the lazy
__getattr__/__dir__(PEP 562) pattern preserves the public API:from qed_math_env import QEDMathEnv,qed_math_env.server.QEDMathEnvironment, anddir(qed_math_env)all behave as before; identity checks in the new test confirm the lazily-loaded objects are the same objects as direct submodule imports. - Checked for the same risk elsewhere: no other environment under
envs/usesProcessPoolExecutor/mp.get_context("spawn"), so this fix is correctly scoped toqed_math_envalone per the self-contained-environments guidance (no sibling copies need the same fix).
Open RFCs Context
Scanned all RFCs in rfcs/ (000, 001, 002, 003, 004, 005, 006, 008 — status In Review; 010, 011 — status Draft). None reference qed_math_env, process-pool verifier workers, or package __init__.py/lazy-import conventions, so there is no active design discussion this change intersects with.
Tier 1: Fixes Required
None — mechanical checks are clean on the changed files.
Tier 2: Alignment Discussion
Principle Conflicts
None identified. This is an internal import-ordering fix inside a single self-contained environment:
- No change to the Gym-like API signatures or MCP tool surface (Invariant: API Invariants).
- No crossing of the client/server boundary —
envs/qed_math_env/__init__.pystill only re-exports client/model symbols, andserver/__init__.pystill only re-exports the server Environment class; both via lazy attribute access rather than eager imports (Invariant: client-server separation, git-blamed to @Darktex, who authored this section ofINVARIANTS.md). - No change to reward computation or where it lives (Principle: rewards inside environment).
- Pattern is isolated to
qed_math_envand doesn't change the canonicalopenenv initscaffold inPATTERNS.mdfor other environments.
RFC Conflicts
None identified.
Summary
- 0 mechanical issues to fix
- 0 alignment points for human review
- 0 RFC conflicts to discuss
This is a narrow, well-tested fix: it correctly diagnoses that ProcessPoolExecutor(mp_context=mp.get_context("spawn")) re-imports qed_math_env.server.math_verify_service in each spawned worker, which previously eagerly pulled in datasets, fastmcp, openai, and the full QEDMathEnvironment/QEDMathEnv stack on every worker start. The TYPE_CHECKING + __getattr__/__dir__ (PEP 562) lazy-export pattern keeps the public API identical while avoiding that cost, and the new tests lock in both properties (lightweight worker import, and preserved public export identity/AttributeError behavior).
Sent by Cursor Automation: Pre-review


Summary
Add regression coverage for QED worker import isolation and busy-worker cleanup. Main now contains the lazy-export production fix from #1491; this PR adds tests only.
Retains public export identity and fresh-process import coverage. Request deadlines, rewards and lifecycle implementation are unchanged.
Evidence
68060a4391573a3d024af8a779d2c3a3933d2c28, both QED test files pass: 153 passed, 5 deselected on macOS/Python 3.11. Four fresh-process import probes and scoped Ruff/usort checks pass.Merge Danger
Door: two-way; revert the added tests.
Blast Radius: tests. No production behavior changes.