Repository navigation
Find or create a report and its simulations by key without a run - #1167
Merged
Merged
Conversation
API v1's one-time migration (D4 · 1) creates each saved report's report with no run, and app v3 starts its first run when it is opened. These tests describe sim's new POST /reports/without-run, the persistence functions behind it, and the re-run of a keyed budget window that has no window run, which today has no years and is refused. The test that a window whose report no longer matches its own key gets no years passes already; it guards the key lookup the fix adds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v1's migration sends POST /reports/without-run through the generated policyengine-api-simulation-client. These hermetic tests check the client sends POST /reports' bodies to the new route and reads its answer and errors. A client generated before the route has no create_report_without_run, so they fail on its import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /reports/without-run takes POST /reports' body and reads the version
manifest and the catalog as POST /reports does, then finds or creates the
report and its simulations (a budget window's: every year's) by the same
keys, creating no run and starting no Modal call. API v1's one-time
migration (D4 · 1) creates its reports this way; app v3 starts a report's
first run when someone opens it.
- The persistence library's find-or-create of each report kind is split
into the report part, now a create of its own, and the run part.
- The submission services share a step that reads and checks a request
before anything is written.
- A keyed budget window with no window run has each year's simulations
found by key when it is re-run, so POST /reports/{report_id}/runs gives
it its first window run instead of answering 409.
Fixes #1166
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1's bug 1: a re-run's definition read looked for a runless window's years, then for any window run, then for its years by key, each in its own statement. A window run another request commits between the first two reads leaves the window with no years, and the re-run answers 409. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A re-run's definition read now decides first whether the window has any window run: with one, its years come from its newest; with none, by key. A window run another request commits after that read is joined by the re-run's write, which finds it on the same years, so the re-run no longer answers 409 (review round 1's bug 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The services that create reports without a run are built apart from the services that create runs, by their own factories, and the route uses those (removing the route later then touches only its own modules). - A budget window without a run is refused before writing when its first year's calculation input cannot be built, as POST /reports refuses it; the economy service gets the call's request ID for that check. - A window's proposed and found years use the re-run read's WindowYearDefinition. - The by-key window read is tested on a window created without a run, with and without an SPM selection; the route's permission is in the authorization table (those two cases pass already). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The services that create reports without a run are built by their own factories (economy_reports_without_run_for and household_reports_without_run_for) and registered by one call in create_app; the re-run services, their protocols and the economy routes' wiring are as they were on main, so removing the route later touches only its own modules. - A budget window's shared preparation builds its first year's calculation input on the proposed run IDs, so both POST /reports and POST /reports/without-run refuse a window that cannot be calculated before writing; the route passes the call's request ID for it. - WindowYearDefinition is the one window-year type for proposed, found and re-run years, and REPORT_SIDES the one side-name tuple. - The entrypoint README documents the route and the by-key re-run, and the re-run docstrings name the by-key years. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- WindowYearDefinition is defined with the window creates (keyed_window_records) and imported by the re-run read, so re-runs depend on creates and not the other way round. - Every by-key re-run test builds its window with find_or_create_budget_window_without_run, and a new test shows a re-run whose definition was read before another request's window run joins that window run. - The authorization table's comment is back above the table, and the economy_requests docstring names the prepared request types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
December 1, 2026 15:16
anth-volk
added a commit
to PolicyEngine/policyengine-api
that referenced
this pull request
Dec 1, 2026
The pinned policyengine-api-simulation-client lacks create_report_without_run until the release published after PolicyEngine/policyengine-sim-api#1167 deploys, and API v1 fails to load its simulation modules without it, which fails every test shard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added a commit
to PolicyEngine/policyengine-api
that referenced
this pull request
Dec 1, 2026
policyengine-api-simulation-client 0.20261201.454 is the first release published after PolicyEngine/policyengine-sim-api#1167 deployed; it has create_report_without_run, which the migration command's report submitter calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #1166
What
API v1's one-time migration of saved reports to API v2 (PolicyEngine/policyengine-api#4359) creates each saved report's report in the simulation service with no run. App v3 starts a migrated report's first run when someone opens it, through
POST /reports/{report_id}/runs. Until now,POST /reportsalways found or created a run and started its calculation, so the migration had no way to create a report alone.POST /reports/without-run(operationcreate_report_without_run, permissionsimulation:submit) takesPOST /reports' body unchanged: economy, budget window or household. It reads the v2 version manifest and the catalog for the default worker's .py version, asPOST /reportsdoes, through the same code. It also runs the checksPOST /reportsruns before writing: a budget window's first-year calculation input, and a household report's household contract requests. It then finds or creates the report and its simulations (for a budget window, every year's) by the same keys, in one transaction. It creates no run, no cliff calculation and no Modal call. A report it finds keeps whatever runs it has. It answers 201 withReportWithoutRunCreated:report_id,report_type,baseline_simulation_id,reform_simulation_id(null only for a household report of the baseline alone) and, for a budget window,years.include_cliffs: trueis refused with 422cliffs_not_available.find_or_create_economy_report,find_or_create_budget_windowandfind_or_create_household_reportare each split into a report part and a run part. The report part is also a create of its own (find_or_create_*_without_run), so both creates write the report and its simulations the same way. A laterPOST /reportsof the same body finds them and creates the run.POST /reports/{report_id}/runsanswered 409 for one, because a window's years came only from its newest window run. The re-run's definition read now checks first whether the window has any window run. If it has none, each year's simulations are found by their keys, provided the report's stored key still matches the key its stored fields give. The read checks for a window run before looking for years, so a window run another request creates meanwhile is joined rather than answered with 409.create_app. The services that create runs don't depend on them. The route is temporary: a later task removes it once the migration's last run is done. The re-run change stays, since migrated windows have no window run until someone opens them.policyengine-api-simulation-clientgainscreate_report_without_runandReportWithoutRunCreated. Hermetic tests inpolicyengine-apis-integcheck its wire shapes.Design decisions (the user, 2026-12-01)
POST /reports, soPOST /reports' answer union stays as it is and the client gets a function with one answer type.POST /reportsof the same body, uses.Tests
Red-green: failing tests were committed before each change (
2bcd63e4and519f3bb2before3046dc6a;2767ada5before5b66cef7;5ae7dafbbefore4a1a59ea). Every added or changed test was run by node ID:Ruff, the rules render, the quality guards (file length included), the uv lock checks and Pyright on the persistence library, the entrypoint and
policyengine-apis-integpass. Two review rounds: the first found one concurrency bug, now fixed; the second found none. Both rounds' quality findings are fixed.Deployment
No workflow, image, Terraform or environment variable changes. The route needs what
POST /reportsalready needs: the simulation database and the v2 Modal environment, whose version manifest it reads.🤖 Generated with Claude Code