Repository navigation
Split Stage 12 coordination and the execution contracts under the file-length limit - #933
Merged
Merged
Conversation
2 tasks done
anth-volk
force-pushed
the
file-length-split-stage12-coordination
branch
from
October 27, 2026 13:45
45c5ed8 to
2057f26
Compare
anth-volk
force-pushed
the
file-length-split-stage12-coordination
branch
2 times, most recently
from
October 27, 2026 14:48
45c5ed8 to
dd13bbf
Compare
…modules stage12_runtime/coordination.py (1,091 lines) and the contract's stage12_execution.py (929 lines) were over the file-length limit. The code moves unchanged. coordination.py keeps coordinate_report and re-exports every public name. The coordinator class, ReportCoordination, its dataclasses and the polling constants move to report_coordination.py, the child simulations' records, failures and cancellation to coordinated_simulations.py, and the parent report's checks and claim to parent_claim.py. Child failures still log under the coordination module's logger, now named explicitly. Private names another module uses are public: _ReportCoordination, _cancel_pending_simulations, _cancellation, _child_failure_detail, _child_record and _simulation_failure_attributes (both with a new docstring), _record_child_failure, _validate_dispatch_context, _validate_submitted_parent and _claim_parent. stage12_execution becomes a package with the same import path, whose __init__.py re-exports every name: base.py holds the field types, the strict contract base and the simulation execution input; report_inputs.py the report input and output plans; result_artifacts.py the artifact descriptors and payloads; comparison_runs.py the invocation context and the comparison-run records. The models in the other modules subclass StrictContractModel and SimulationExecutionInput through the package path, which ruff.toml already lists as runtime-evaluated, so ruff keeps their annotation imports at runtime with no settings change; base.py sorts first, so the package binds those bases before the other modules import them. Every model's JSON schema is unchanged. The coordination tests' fixed clock patches datetime in each of the three modules that read it, and uuid4 and resolve_report_output_plan in report_coordination.py, where the coordinator looks them up. The file-length baseline drops both files (count 10 to 8). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
file-length-split-stage12-coordination
branch
from
October 27, 2026 16:17
dd13bbf to
4afab74
Compare
anth-volk
marked this pull request as ready for review
October 27, 2026 16:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #932
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Summary
Fourth of nine stacked PRs; it builds on #930. It splits Stage 12 report coordination and the contract library's Stage 12 execution contracts without changing behaviour, and removes both from the file-length baseline (count 10 to 8). For each file, a script compared every top-level statement of the old module with the new modules: all appear exactly once and unchanged, apart from the renames below and one logger line, in their original order.
stage12_runtime/coordination.py(1,091 lines)coordination.pycoordinate_report, and re-exports of every public name, in__all__report_coordination.pyCoordinatorInvocation,CoordinatorDependencies, the polling constants, and the coordinator class, which runs one claimed reportcoordinated_simulations.pyparent_claim.pyreport_coordination.pyis above the 400 lines the split aims for, because the coordinator class itself is 491 lines; dividing a class is not a move, so it stays whole.policyengine_simulation_executor.stage12_runtime.coordination, which the runtime tests'caplogchecks filter on;coordinated_simulations.pynames it explicitly, the one statement that isn't verbatim._ReportCoordinationtoReportCoordination;_cancel_pending_simulations,_cancellation,_child_failure_detail,_child_record(docstring added),_record_child_failure,_simulation_failure_attributes(docstring added),_validate_dispatch_context,_validate_submitted_parentand_claim_parentdrop their underscore.policyengine_simulation_contract/stage12_execution.py(929 lines)The module becomes a package with the same import path; its
__init__.pyre-exports every name, including the two UK geography types it re-exported before.stage12_execution/__init__.py__all__stage12_execution/base.pyStrictContractModel, and one simulation's execution input with its dataset, population, geography and provenance modelsstage12_execution/report_inputs.pystage12_execution/result_artifacts.pystage12_execution/comparison_runs.pyruff.tomllistspolicyengine_simulation_contract.stage12_execution.StrictContractModeland.SimulationExecutionInput. A model in a new module that imported its base frombase.pywould name an unlisted path, so ruff would move its annotation imports underTYPE_CHECKINGandsim.quality.runtime-evaluated-models-resolvewould fail; listing the new path would change a ruff setting, which this work doesn't. As a package, the models subclass those bases throughpolicyengine_simulation_contract.stage12_execution, the path already listed.__init__.pyimportsbase.pyfirst (its name sorts first), so the bases are bound in the package before the other modules import them; a comment in each module says so.PopulationInputalias's representation.# noqa: PLC0414suppressions on the UK geography re-exports are gone:__all__now marks them as re-exports.Tests
tests/test_stage12_coordination.py: thefixed_clockfixture patchesdatetimeincoordinated_simulations,parent_claimandreport_coordination, the three modules that read the clock, anduuid4inreport_coordination;test_default_output_plan_resolver_measures_its_own_stagespatchesresolve_report_output_planinreport_coordination, where the coordinator calls it.tests/test_stage12_runtime.pystill patchesruntime_storeincoordination, wherecoordinate_reportreads it.Environment variables
No change: the moved code reads no environment variable, and no workflow, image or deployment file changes. The Modal images copy the contract package and
stage12_runtimewhole, and the image smoke's path filter covers both directories.Testing
test_runtime_evaluated_annotations.pyin the executor and the entrypoint (thesim.quality.runtime-evaluated-models-resolveguard): passed.projects/policyengine-apis-integ, which needs the generated clients (./scripts/generate-clients.sh) to install and isn't touched here.python scripts/run_quality_guards.pyandpython -m scripts.rules guard --base-ref origin/file-length-split-gateway-endpoints: passed;python -m scripts.rules renderleaves no diff.Only the lowest PR in the stack runs full CI, so this PR's
CI completecheck fails by design until the PRs below it merge.🤖 Generated with Claude Code