Repository navigation
Run each year of a US nationwide budget window in segments, at most 4 years at once - #1199
Merged
Merged
Conversation
… 4 at once Tests that fail before the change: a plain US nationwide year of a budget window asks for the geographic split (segmented: true), and a window whose years split runs at most 4 years at once, also when the gateway stored the requested 20. State, UK, segmented: false and labour-supply-reform windows keep one container per year and the requested number at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…4 at once A budget-window year no longer forces segmented: false. It follows the rule a single-year request does (should_run_segmented_national), and its request states the outcome, as the gateway's does for a single-year request. A window whose years split runs at most 4 years at once (max_running_years): create_initial_batch_state stores that limit, so the gateway's submit-time record and the batch runner's state hold it, and the runner lowers a seed that a gateway deployed before this change stored with the requested number. The stored request keeps the number the caller asked for. State, UK, segmented: false and labour-supply-reform windows keep one container per year and the requested number at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egments Keeps main's report_type on every budget-window year and drops the forced segmented: false, so each year follows the split rule a single-year request follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gateway README describes how budget-window years split and the limit of 4 split years running at once. The batch test helper returns the stored state typed and asserts it exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The year-request docstring says which plain nationwide years stay whole, the progress reporter's docstring counts the per-region-group writes of a year that splits, and the changelog names segmented: false windows. The test payload helpers declare their return types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The section now names all the cases the split rule keeps in one container: places, non-macro scope and labour-supply responses in the baseline as well as the reform. The contract test helper types its overrides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
December 3, 2026 21:17
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 #1198
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed.Summary
In the 30 days to 2026-12-01, every US nationwide budget window API v1 sent failed: 8 of 9 batches stopped at the batch function's 3,600 s time limit. Each year ran in one container (1,284 to 2,341 s), because
build_child_simulation_requestsetsegmented: falseon every year. A single-year US nationwide request splits into region-group segments instead (median 156 s).build_child_simulation_requestno longer forcessegmented: false; it setssegmentedon every year toshould_run_segmented_nationalof the year's request. A plain US nationwide year (no labour-supply responses, nosegmented: false) now runs as region-group segments; state, UK,segmented: falseand labour-supply-reform years run in one container, as before. Every year keepsreport_type: budget_window_yearfrom Name the report type in every run_simulation record #1183.max_running_yearsin the contract library'sbudget_window_statereturnsmin(max_parallel, 4)when the window's years split, and the requested number otherwise.create_initial_batch_statestores it as the record'smax_parallel, so the gateway's submit-time record holds it;request_payloadkeeps the requested number (20 from API v1). The batch runner'sload_or_create_batch_statealso lowers a record that a gateway deployed before this change stored with the requested number._job_progress_reporter's docstring counts the per-region-group progress writes of a split year.The status response has no
max_parallelfield, so API v1 sees no difference apart fromrunning_yearslisting at most 4 years for a US nationwide window.Testing
Run by pytest node ID only (no full suite), Ruff 0.15.22 (CI's version) lint and format check on the changed files, and Pyright through
python3 -m scripts.rules pyright --syncfor the contract library and the executor.8f644a0d). New tests in the contract library'stest_budget_window_state(a split window stores 4 and keeps 20 inrequest_payload; asking for 2 keeps 2; state, UK,segmented: false, labour-supply-reform and non-macro windows keep 20), the executor'stest_budget_window_context(a plain US nationwide year sayssegmented: true; state, UK,segmented: falseand labour-supply years sayfalse; replaces the test that pinned every year tofalse) andtest_budget_window_batch(a 6-year split window whose record was stored with 20 runs at most 4 years at once and stores 4; a state window runs 6 at once and stores 20). On8f644a0d: 3 failed on assertions (20 == 4,False is True,6 == 4), 14 passed (the cases that must not change, and 3 existing tests whose helper changed).6b62e5fd). The same 17 passed.main(0e7bbc15) and the review fixes (head436d982b). The new tests, Name the report type in every run_simulation record #1183'sreport_typetest (now through the shared helper) and the existing tests whose helpers changed: 13 executor and 7 contract cases passed. Ruff and Pyright pass. Each review round also re-ran the new tests before and after the change.Review
Three rounds of adversarial review before opening this PR.
6b62e5fd): all claims verified. One medium bug: the gateway would store 4 for a window routed to an app of an older .py version that still runs each year in one container. Dropped: older apps are out of scope (API v1 routes only to the app of its own .py version). Code-quality fixes: the test helper's return type, the year-request docstring, the README section.5fbd7260): all claims verified, including that the merge ofmainkept Name the report type in every run_simulation record #1183. One medium bug (50% confidence): a window of more than 4 years can still overrun the batch's 3,600 s limit, and its status then readsrunninguntil API v1 drops it after 24 hours. Not fixed here: the status route and the batch's time limit are unchanged by this PR, and the same happened before (November's failures ran 20 years at once). Windows long enough to overrun even at 4 years at once are assigned to a later tracker task. Code-quality fixes: docstrings, the changelog fragment, test helper types.df076f2c): no bugs. Code-quality fixes in436d982b: the README now lists every kind of year the rule keeps in one container (places, non-macro scope, labour-supply responses in the baseline), and the contract test helper types its overrides. Left: the executor's two test payload helpers differ in whether they drop unset fields, which does not change what the tests check.Bugs left, by priority
running, and its running years and their segments are not cancelled (exists before this PR; long windows belong to a later task).max_parallelhas no field description of its two meanings; no gateway endpoint test of the stored number; no deployed check runs a split year (the integration window isstate/ut).What the merge waits for
825d15f2), and this branch contains it. Its deployment is not needed first: this PR's merge deploysmain, its code included.No workflow, image, Terraform or environment-variable change.
🤖 Generated with Claude Code