Repository navigation
Conversation
…failing) A report run's cliff impact comes from its two simulation runs' cliff_impacts rows, not from report_runs' four cliff columns, and an economy report read says how far each side's cliff calculation has got (cliffs). The fixtures store a result's cliffs as each simulation run's succeeded calculation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An economy report run's cliff impact is its two simulation runs' succeeded cliff_impacts rows, and no read uses report_runs' four cliff columns any more, so C1 · 41 can drop them. Each side reads its run's calculation that hasn't failed, else its newest failed one. Economy report reads (get, and the create and re-run answers) gain cliffs: an overall status and each side's status and error message, for a run in any status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /v2/reports/{id}/runs takes include_cliffs and passes it to the
simulation service, sending it only when asked; a household report's or
budget window's re-run asking for cliffs is refused with 422 before the
service is asked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /v2/reports/{id}/runs takes include_cliffs and sends it to the
simulation service only when true, so a re-run that doesn't ask still runs
on a simulation service that doesn't take the field yet. A household
report's or budget window's re-run asking for cliffs answers 422 before the
service is asked or anything recorded. The create body's include_cliffs now
says what it starts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stored_reports.services reached its 800-line limit. The code that reads reports as the requesting user sees them (their saved report's label and their newest requested run) moves unchanged to stored_reports.requester_views.services; _requesters_view is renamed requesters_view there, since the report service now imports it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1's quality findings: the economy read moves into _economy_report, as household reports and budget windows have theirs; the result's cliff_impact, the read and create routes, and a re-run of a run on older versions now say how cliffs read and start, and that a simulation service that doesn't calculate cliffs per simulation run yet refuses include_cliffs with 422; get_report names the reform check for a run in any status. The golden test that couldn't fail is replaced by one that fails if the report run's result columns hold a cliff column again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2plan/c1-37-cliff-results #4329 +/- ##
==============================================================
+ Coverage 93.19% 93.63% +0.43%
==============================================================
Files 408 409 +1
Lines 23297 23366 +69
Branches 3648 3657 +9
==============================================================
+ Hits 21711 21878 +167
+ Misses 985 874 -111
- Partials 601 614 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The simulation service keeps refusing include_cliffs until it calculates cliffs per simulation run, so the OpenAPI document must say so wherever it tells callers to ask for them. Two client tests pin that service's own 422 bodies, which the Public API already reads and answers as 422. Test wording stops saying the report run writer has already stopped storing cliffs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A simulation service that doesn't calculate cliffs per simulation run refuses include_cliffs with 422 and creates or starts nothing, and that can stay true for some time. The create and re-run routes, their 422 answers, the re-run body, cliffs and the changelog fragment now say so, and that each side stays not_calculated meanwhile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The OpenAPI text must name include_cliffs: true, since false is accepted, and say that a side with no calculation stays not_calculated, since a side with a stored calculation keeps its status. Test support stops describing sim's writers as if they had already changed: the fixture says it leaves out the report run's cliff columns, which sim's writer can still fill. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The API text names include_cliffs: true, which is what such a service refuses, and says only a side with no calculation stays not_calculated. A re-run's request docstring no longer implies that every re-run without the field runs: a stored report can still be refused for its own stored options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fixture and its callers say what they store rather than what sim's writer stores, so the text holds before and after that writer changes, and the create 422 keeps its sentence about the message beside the causes it refers to. No behaviour changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v1 no longer uses report_runs' four cliff columns, but every whole-row load of a report run still names them in its SQL. The release serving while a later revision drops them would then fail each report read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReportRun leaves baseline_cliff_gap, baseline_cliff_share, reform_cliff_gap and reform_cliff_share out of its mapper, so API v1 neither selects nor writes them. The table keeps the columns, their check constraint and their grants, so there is no revision, and a release of this code keeps serving report reads while a later revision drops them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unmapped columns declared as typed fields still look usable: a loaded report run returns a Column object for them, and a value passed to the constructor is dropped without an error. The table keeps them through a documented direct SQLAlchemy category until a revision removes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The four columns move from typed SQLModel fields to __table_args__, so a report run has no attribute or constructor field for them, and API v1's list of direct SQLAlchemy uses names this one. The ReportRun description now says this covers only these four: trigger is still mapped, so it needs an earlier release of its own before a revision drops it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The earlier name contained the text the v2 model layer's rule forbids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The category no longer contains text the v2 model layer's rule forbids, and it says API v1 stopped using these columns rather than that nothing does: the simulation service still writes them until its own change deploys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
Brings in e87b0ea, which merges master at 003ee49 (C1 · 36's #4325: stored dynamics and revision 9d1d12a7ac58). Revision bc334f9877b7 now revises 9d1d12a7ac58 and stays the only v2 head. master's changes to files this branch also changes are route and protocol wording and the dynamics protocols; none touches cliffs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously 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 #4328
Stacks on #4327 (
v2plan/c1-37-cliff-results, revisionbc334f9877b7, tablecliff_impacts); retarget tomasteronce #4327 merges.Summary
Cliffs come from the simulation runs. An economy report run's
result.cliff_impactis its two simulation runs' succeededcliff_impactsrows,{baseline, reform}, once both have one, and null otherwise. Nothing in API v1 readsreport_runs' four cliff columns any more, so a later revision can drop them. A report run that stored cliffs only in those columns now reads none.Each economy report read gives
cliffs: how far the two cliff calculations have got, for the run read in any status. It appears on the get, and on the create and re-run answers, but not on lists or searches, and is null for a report with no run.status:not_calculated,pending,running,succeeded, orfailed. A side isfailedwhen its newest calculation failed and none is under way;error_messagethen says why.status:succeededonce both sides are. Otherwise it isfailedif either side is, elsenot_calculatedif either side is, elserunningif either side is, elsepending.uq_cliff_impacts_unfailed), else its newest failed one. One query per distinct simulation run, so a report naming one run on both sides reads it once.include_cliffson re-runs.POST /v2/reports/{report_id}/runstakesinclude_cliffs(default false)."include_cliffs": trueto the simulation service only when asked, so a re-run that doesn't ask still works on a simulation service whose re-run body takes onlyforce.include_cliffsand is unchanged.The four cliff columns leave the
ReportRunmodel. They are declared only in the table (__table_args__) and listed inexclude_properties, soReportRunhas no field or attribute for them and its SQL never names them. The table,ck_report_runs_cliff_impact_completeand the grants are unchanged, so there is no revision. The simulation service can keep writing the columns until its own change deploys.File split.
stored_reports.servicesreached its 800-line limit, so the code that reads reports as the requesting user sees them moves unchanged tostored_reports.requester_views.services._requesters_viewis renamedrequesters_viewthere, because another module now imports it.Changelog fragment:
changelog.d/report-cliffs-from-simulation-runs.changed.md.Merge and deploy order
bc334f9877b7, applied with its grants in staging and production. This PR readscliff_impactsas the runtime role.include_cliffs. Start each side's cliff calculation when a report asks for cliffs policyengine-sim-api#1099 won't merge as it stands.This PR needs only step 1 to deploy safely, and doesn't depend on when steps 2 to 4 happen. Until step 4 deploys:
include_cliffs: trueanswers 422 and the whole request is refused: a create creates no report, and a re-run starts no run. On a create the simulation service answerscliffs_not_available; on a re-run, a validation error naminginclude_cliffs. API v1 passes either on as 422. The OpenAPI descriptions say so.not_calculatedandresult.cliff_impactis null.reports.label,descriptionanduser_idand bothtriggercolumns. A separate change (C1 · 40a) stops mapping those five, and must deploy before the later revision (C1 · 41) drops all nine.report_runscolumns reads none, and they can't be calculated again until step 4. API v1's callers haven't been asking for cliffs, so few or none are expected, but production hasn't been counted.Migration notes
/v2/reports: read, create, re-run). Nothing on the Flask path changes.cliffs;include_cliffs;result.cliff_impactnow comes from the simulation runs' cliff results.scripts/export_migration_contracts.pyregenerates both migration contract documents unchanged; they don't record this route's answer shape.Inline suppressions added
# noqa: PLR0913onread_economy_result_rows, the database read of a report run's result rows. It now takes the cliff calculations the report service has already read, so a run's cliffs are read once whatever its status. Its other inputs (the session, the country, the run, its reform simulation run and the local-area flag) are each needed, and a parameter object used only by this one call would add a type without simplifying anything.# noqa: PLR0913on the integration test helperstore_cliff_calculation, which takes the connection, the simulation run, the status and each column a test sets.Testing
Each test was written first and seen failing for the expected reason, and committed with "(failing)" in the subject before the code that passes it. I ran only the tests this PR adds or changes, by node ID: 41 node IDs, 84 cases with their parameters, all passing. The PostgreSQL integration tests ran against a disposable PostgreSQL 17 database built from this branch, with
reconcile_v2_privileges.py apply --create-missing-rolesandverify, as the runtime role.tests/unit/v2/test_report_cliff_reads.py: each side's row; the side and overall statuses;cliff_impact; one run on both sides;tests/integration/test_v2_report_cliff_reads.py: succeeded, still calculating and failed sides; the four columns not read; no run;test_report_read_routes.py,test_report_run_routes.py,test_simulation_report_reruns.py,test_v2_report_runs.pyandtest_v2_report_creation.py;test_simulation_reports.pyandtest_simulation_report_reruns.py. These passed when written, because API v1 already answers both with 422.tests/fixtures/economy_results.pystores a result's cliffs as each simulation run's succeededcliff_impactsrow instead of the report run's columns;Also run: ruff, ruff format,
make typecheck-v2(mypy),lint-imports,python -m scripts.rules validate,python scripts/run_quality_guards.pyandscripts/export_migration_contracts.py.alembic -c alembic-v2.ini checkfinds no schema change, andreconcile_v2_privileges.py apply --create-missing-rolesandverifypass; there is no revision or grant change. Explicit mypy on the changedpolicyengine_api/data/v2/modelsfiles reports only theField(sa_type=...)overload errors those modules already have.Reviewed in six adversarial rounds, three for each stage of the work after the first build:
ReportRun): round 4 found a description implying this release survives the whole later column drop; round 5 found a category name that would have failed the v2 model-layer rule test. Both are fixed, along with their code-quality findings, and round 6 found no bugs.🤖 Generated with Claude Code