Repository navigation
Conversation
Each simulation run can have one cliff calculation that hasn't failed, holding its state and, once it succeeds, the run's cliff gap and cliff share. The tests cover the model, its checks and partial unique index, the revision that adds the table, and the grants: the simulation service starts calculations, the Modal workers finish them, the Public API reads them, and the catalog writer and the Stage 12 role can do neither. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add cliff_impacts (revision bc334f9877b7, autogenerated on f519a77ba122): one row per cliff calculation of a simulation run, with its state and, once it succeeds, the run's cliff gap and cliff share. A partial unique index allows one calculation per run that hasn't failed, so identical requests join it and a failed one never counts. The row is deleted with its run, and inherits the run's versions. Its status reuses v2_simulation_status, the revision's one post-generation correction. The simulation service may insert calculations and record or fail their Modal calls, the Modal workers may write their state and results, the Public API may read them, and no other role may touch them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Stage 9 and Stage 12A runbooks' downgrade chains now start with bc334f9877b7, and the head foreign-key test counts cliff_impacts among the simulation side's tables. The changelog fragment and the skill section say what each role may do, since the simulation API writes the table only once its own change lands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4327 +/- ##
==========================================
- Coverage 93.69% 93.67% -0.03%
==========================================
Files 397 397
Lines 22885 22900 +15
Branches 3599 3599
==========================================
+ Hits 21443 21451 +8
- Misses 839 846 +7
Partials 603 603
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 v2 metadata now holds 51 tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
Open
Draft
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 #4326
Summary
Adds revision
bc334f9877b7to the v2 chain (onf519a77ba122, autogenerated with--rev-id). It createscliff_impacts: one row per cliff calculation of a simulation run, with the calculation's state and, once it succeeds, the run's cliff gap and cliff share. It also declares the table's grants.Design decisions
The simulation API's change that writes the table and its change that starts calculations agreed this design before the revision was built:
status(thev2_simulation_statustype runs use),modal_call_id,error_message(code: message),started_atandcompleted_at. This lets a request tell "no result" from "being calculated" from "done".uq_cliff_impacts_unfailed, partial unique onsimulation_run_idwherestatus <> 'failed', also declared for SQLite).ON CONFLICT (simulation_run_id) WHERE status <> 'failed' DO NOTHING, so two requests at once start one calculation.completed_at; a succeeded row has both numbers, and no other row has either. The numbers aren't range-checked: .py doesn't keep the share to at most 1, and a filtered simulation with no adults gives NaN.CASCADEon the run, aspovertyandinequalityhave. The result is part of its run, and nothing references it.(status, started_at), so the simulation API's stuck-run sweep can fail a calculation whose worker ended without an outcome.Grants (
policyengine_api/data/v2/privileges.py)cliff_impactspolicyengine_v2_simulation_serviceSELECT,INSERT,UPDATE (status, modal_call_id, error_message, completed_at, updated_at): insert a calculation, record its Modal call, or fail it when Modal refuses the callpolicyengine_v2_modal_workerSELECT,UPDATE (status, modal_call_id, error_message, started_at, completed_at, updated_at, cliff_gap, cliff_share): claim, finish or fail; noINSERTpolicyengine_v2_runtimeSELECTpolicyengine_v2_catalog_writer,policyengine_stage12_<environment>Neither simulation API role may change the run a row names or delete a row. The deploy's existing
reconcile_v2_privileges.py applyandverifysteps grant and check these after the schema upgrade; no role needs creating.The revision
statusreuses the baseline'sv2_simulation_statustype (postgresql.ENUM(..., create_type=False)), as1356f658347ddoes forsimulation_runs.status. The generatedcreate_tablewould create the type again and fail. This is the only correction, and it is commented in the revision.simulation_runs.V2_ALEMBIC_HEAD_REVISIONmoves tobc334f9877b7.report_runs' four cliff columns stay until a later revision drops them.f519a77ba122. Whichever merges second mergesmasterand re-points itsdown_revision.Docs
docs/engineering/skills/alembic-migrations.md: a section for this revision, plus the two simulation roles' rows in the role table.docs/migration/stage-9-v2-metadata.mdanddocs/migration/stage-12a-user-login.md.Testing
Test-first: the first commit holds the failing tests, seen failing because there was no
CliffImpactmodel, nocliff_impactsgrants and no revisionbc334f9877b7. The tests below were run by node ID against a disposable PostgreSQL 17 database.test_cliff_impact_modelscovers the columns, checks and indexes, and checks that SQLite keeps one unfailed calculation per run and refuses numbers on any row but a succeeded one.test_simulation_run_models' per-simulation result tables.test_alembic_v2_cliff_impacts, PostgreSQL):CASCADE.test_v2_simulation_role_privileges, as the managed roles):test_alembic_v2_simulation_runs): the head foreign-key test now countscliff_impactsamong the simulation side's tables.alembic -c alembic-v2.ini check: no drift;reconcile_v2_privileges.py apply --create-missing-rolesandverify: pass;lint-imports,python -m scripts.rules validate,python scripts/run_quality_guards.py, ruff, ruff format andmypy.policyengine_api/data/v2/modelsfiles reports theField(sa_type=...)overload error on the newstatus,started_atandcompleted_atfields. That is the same error the existingSimulationRunfields have onmaster; the directory is outsidemake typecheck-v2..github/scripts/test_alembic_v2_lifecycle.sh.V2_MIGRATION_DATABASE_URLandV2_ALEMBIC_DISPOSABLE_TEST.alembic-v2-check.ymlsets both as literal job-levelenv:values, for the job's own PostgreSQL service.seed-v2-database.yml, withV2_MIGRATION_DATABASE_URLfrom each GitHub environment's secrets.🤖 Generated with Claude Code