Repository navigation
Conversation
The budget-window store's tests, and the simulation service's window creation test, expect the earliest four years started and at most four under way, so they fail while BUDGET_WINDOW_MAX_RUNNING_YEARS is 5. The capacity test keeps the v2 functions' container limits and gives the coordinator's 25 as three windows of four years and 13 other reports, which fails while a window may run five. New tests start a later year of a US national window as a coordinator does, plan its two simulations with resolve_simulation_output_plan and apply should_segment_simulation: both are split into region groups; a labour-supply-response reform runs whole beside a split baseline; and a window marked segmented: false keeps the mark and runs whole. These pass before the change: they record what the code already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BUDGET_WINDOW_MAX_RUNNING_YEARS drops from 5 to 4. The simulation service starts a new window's first four years, and each year's coordinator starts the next waiting year only while fewer than four are under way. The v2 functions' container limits stay at 25 coordinators, 50 calls of each simulation worker and 1,000 US segment calls; the comment on the coordinator's limit now gives its 25 as three windows of four years and 13 other reports. Docstrings, route descriptions, READMEs and the Stage 12 worker document that said five now say four or name the constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rerun_report OpenAPI description still said a new budget-window run has its first five years started at once. The segment tests' reforms now end where the simulation service ends an open-ended value, in 2200, and the changelog fragment says each coordinator starts waiting years until four are under way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_an_advance_starts_the_earliest_waiting_years and test_concurrent_advances_start_each_year_once still expected a seven-year window's first advance to start 2026 to 2030; with at most four years under way it starts 2026 to 2029. The segment tests' docstring now says the simulation service starts a window's first years and a coordinator the later ones, and the changelog fragment names API v2's Modal functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A window whose coordinator calls started a fifth year under the old limit of five has more years under way than the new limit; its next advance starts none until fewer than four are under way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The over-limit store test puts one year more than BUDGET_WINDOW_MAX_RUNNING_YEARS under way, so it keeps testing a window over the limit if the limit changes. A re-run's window starts up to its first four years, since a shorter window has fewer and a later year Modal doesn't confirm in time is deferred. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 #1184
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. (changelog.d/budget-window-four-years.changed.md)Summary
API v2 runs at most four years of a budget window at once instead of five. This is tracker task 1.9 · 2 of "14. Report runtimes", whose substage makes budget windows run each year in segments, at most four years at once, in API v1 and API v2.
BUDGET_WINDOW_MAX_RUNNING_YEARS(policyengine-stage12-persistence) drops from 5 to 4. The simulation service starts up to a new window's first four years, and each year's coordinator, when its year ends, starts the earliest waiting years until four are under way (running, or started with a Modal call recorded). No caller overrides the default.coordinate_report25,run_single_simulation_usandrun_single_simulation_uk50 each,run_single_simulation_segment_us1,000. The capacity test now gives the coordinator's 25 as three windows of four years and 13 other reports, and the comment on the limit inv2_app.pysays so.budget_window_schedulingandbudget_window_submissions, the create and re-run routes' descriptions (both appear in the simulation service's OpenAPI document), both READMEs, and the Stage 12 worker document.During the deployment
A merge to
maindeploys the v2 Modal application (deploy_stage12_v2) before the simulation service receives traffic (promote_entrypoint), and coordinator calls already running keep the old code. A window that spans the deployment can briefly have five years under way. Its next advance then finds no free place and starts nothing until fewer than four are under way; a new store test covers this. The container limits, sized for five years per window before this change, have room for it.Environment variables
The changed code reads and declares no environment variables. The only change in deployment code is a comment in
projects/policyengine-simulation-executor/src/modal/v2_app.py.Testing
Commits:
60a239b5adds tests that fail before the change;bc112a84makes the change;02ef2b2e,ced94ab0,216329b0andfe03cc9bare fixes from review. Every test below was run on its own by pytest node ID. The persistence tests ran against a local PostgreSQL 17, with the API's tables built at the pinned commit aspr.ymlbuilds them.Changed tests, which fail before the change and pass after it:
test_budget_window_store, six tests now expect the first advance to start the four earliest years, at most four under way, and one free place when three are under way:test_the_window_runs_at_most_four_years_at_oncetest_the_first_advance_starts_the_four_earliest_yearstest_an_advance_fills_only_the_free_placestest_a_start_that_fails_after_its_call_claimed_the_year_keeps_the_yeartest_two_advances_at_once_start_each_year_oncetest_a_reports_later_window_run_starts_only_its_own_yearstest_budget_window_sessions, two tests (fixed after review round 2) now expect 2026 to 2029 started:test_an_advance_starts_the_earliest_waiting_yearstest_concurrent_advances_start_each_year_oncetest_budget_window_submissions::test_a_window_is_created_with_a_run_per_year_and_its_first_four_started.test_stage12_budget_window_capacity::test_the_coordinator_holds_three_windows_at_their_cap_and_other_reports. Before the change it failed with25 == 3 * 5 + 13.New tests, which pass before and after the change because they record existing behaviour:
test_stage12_budget_window_segments, each test starts a later year of a US national window with the realModalYearStarter, whose input comes fromyear_calculation. It plans each side withresolve_simulation_output_plan, the plan a report run's coordinator gives each worker, using the installed US model, and appliesshould_segment_simulation. The three cases:test_both_simulations_of_a_later_us_national_year_run_in_segments: a plain year, where both sides split.test_a_labour_supply_response_reform_runs_whole_beside_a_split_baseline: the reform runs in one piece and the baseline still splits.test_a_window_marked_unsegmented_keeps_the_mark_in_its_later_years: sides markedsegmented: falsein the first year keep the mark in the later year, and neither splits. No API v2 request can send this option.test_budget_window_store::test_an_advance_with_more_years_under_way_than_the_limit_starts_none.Results:
60a239b5; the two session tests at02ef2b2e), every changed test failed on its assertions and the three segment tests passed.Review
There were three rounds of adversarial review before this PR opened:
rerun_reportdescription still said "first five started at once". Fixed in02ef2b2e.test_budget_window_sessionstests still expected five years started; they would have failed the "Public API schema" job. Fixed inced94ab0. The over-limit store test was added after this round (216329b0).fe03cc9b: the over-limit test derives its years from the constant, and the re-run descriptions say "up to" four.No bugs are left open.
What the merge waits for
This PR builds on
main, not on another task's branch. In the tracker, the substage's PRs merge in order. Before this one merges, each of the following must be merged; neither needs to be deployed, because this PR uses nothing either one creates or deploys:Then it waits for this PR's own checks.
🤖 Generated with Claude Code