Repository navigation
Keep dynamic parameters and their values in their own tables - #4347
Merged
Merged
Conversation
…r C1 · 50 C1 · 48's scripts/split_v2_policy_copies.py split each stored v2 policy that held model assumptions into a policy and a dynamic, and C1 · 49 runs it in staging and production before C1 · 50's revision. That revision moves dynamic parameters into their own tables and refuses to run while any policy value names one, so afterwards no stored policy can hold a model assumption, and the command's dynamics could no longer be stored either. The user decided on 2026-11-25 that C1 · 50 removes it. Removed: the policy_copy_split package, the script, its temporary role's privileges, V2_POLICY_COPY_SPLIT_DATABASE_URL and its loader, its import rules, its integration workflow entry and its tests. The stage-10 runbook keeps a short account of what the command did. The UK gov.dynamic. prefix and C1 · 48's other changes stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Failing tests for tracker task C1 · 50 (API v1): - Revision 7f7335f0eb31 creates dynamic_parameters and dynamic_parameter_values, then moves every stored version's dynamic parameters (US gov.simulation. and simulation., UK gov.simulation. and gov.dynamic.), their current-law values and every dynamic's values there with their IDs, deletes the policy tree's rows under those folders and lowers their parents' child counts, and deletes the originals. It refuses while a policy value names a parameter it would move, keeps its own copy of the prefixes, and its downgrade moves the rows back and leaves the trees (the user's decisions: C1 · 46, Q2, and C1 · 50's decision 1). - A read-only step in seed-v2-database.yml counts the same policy values and stops the deploy first. - Publication writes, compares, restores and prunes both tables, and leaves model assumptions and their folders out of the policy tree and the search file, whose format becomes 2. - Dynamics, the v1-to-v2 copy and the 422s on /v2/policies and /v2/dynamics read the new tables, and the grants cover them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v1 now stores model assumptions (gov.simulation., US simulation. and UK gov.dynamic.) in dynamic_parameters and their current-law values and every dynamic's values in dynamic_parameter_values (tracker task C1 · 50): - Revision 7f7335f0eb31 creates the two tables (generated) and, in its hand-written data step (the user's migration decision, C1 · 46, Q2), locks and moves every stored version's rows with their IDs, refuses while a policy value names a moved parameter, deletes the policy tree's rows under the dynamic folders after lowering their parents' child counts, and checks it deleted what it copied. Its downgrade moves the rows back and leaves the trees (decision 1). It keeps its own copy of the prefixes. - seed-v2-database.yml's new read-only step counts the same policy values before the upgrade (scripts/qualify_v2_dynamic_parameter_move.py). - Publication stages each parameter's kind, inserts, compares, restores and prunes both tables, analyzes them, counts them apart in its evidence, and builds the policy tree and the search file (now format 2) without model assumptions or their folders. - Dynamics read and write the new tables; /v2/policies and /v2/dynamics name the IDs they find in the other table in their 422s; the v1-to-v2 copy looks the assumptions up among dynamic parameters. - Every role has an entry for both tables. - alembic-migrations.md documents the revision, the decisions, the deploy order and the deploy window as the second accepted exception (decision 2); the stage 9 and stage 10 runbooks follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The read-only check before revision 7f7335f0eb31 counts no value on a target without the catalog tables, as the other check steps do, so a new or reset database can still be upgraded and seeded. - The catalog writer holds no UPDATE on dynamic_parameters: publication only inserts it. - The revision tests' fixture deletes its rows before upgrading back to the head, so a failed refusal test leaves neither rows nor a downgraded database; the tree test that could not fail is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The read-only check before revision 7f7335f0eb31 counts nothing on a database lacking any of the catalog tables it reads, as the other check steps do, so a new or reset database can still be upgraded and seeded. - The catalog writer has no UPDATE on dynamic_parameters, which publication only inserts. - The search file's 503 message and its route description say that only versions published since the current format have a file; the migration guide and the stage 9 runbook say that older kept versions get one only when a release installs them again; mirror_legacy_policy_in_session's docstring no longer says a stored copy keeps its assumptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The revision refuses while a dynamic's value names a parameter it doesn't move, which the new tables couldn't hold (failing). - A policy value written while the upgrade waits for its lock is counted and refused: without the lock the upgrade would delete it with its parameter. - The seed workflow's check counts no policy value on another country's look-alike prefix. - A version stored before catalog format 2 compares its dynamic parameters without format 2's fields; clear_format_2_fields clears their flags too. - The copy test named for parameters of the same name says what it checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Revision 7f7335f0eb31 also refuses, changing nothing, while a dynamic's value names a parameter it doesn't move: dynamic_parameter_values can't hold it, and after the move no reader would find it. - ParameterTreeChild's docstring says model assumptions and their folders have no tree rows; the migration guide names the publication modules that write both tables and says the check step classifies with the package's prefixes, which a test keeps equal to the revision's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…' into v2plan/c1-50-dynamic-parameter-tables
…ables The merge of C1 · 48's branch brought C1 · 45's household calculation route tests, whose catalog stored model assumptions in parameters and a dynamic's values in parameter_values. Since C1 · 50 they are dynamic_parameters and dynamic_parameter_values rows, as catalog publication and the dynamics service store them, so the missing-assumption check reads them there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…' into v2plan/c1-50-dynamic-parameter-tables # Conflicts: # policyengine_api/services/v2/policy_copy_split/database_connectors/reads.py # policyengine_api/services/v2/policy_copy_split/services.py # tests/integration/test_v2_policy_copy_splits.py # tests/unit/v2/test_policy_copy_split_rules.py
…c-parameter-tables
…bles CI found seven existing tests still expecting publication's shapes from before the dynamic parameter tables: the evidence's entity counts (now with dynamic_parameters and dynamic_parameter_values), the restored versions' tuples (now with a second count), the nine analyzed tables, the comparison pairs (now with dynamic parameters and their values), and the staged parameter rows (now ending with is_dynamic). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4347 +/- ##
==========================================
- Coverage 93.94% 93.86% -0.08%
==========================================
Files 434 428 -6
Lines 24291 24023 -268
Branches 3767 3719 -48
==========================================
- Hits 22820 22550 -270
- Misses 845 853 +8
+ Partials 626 620 -6
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:
|
…nsupported country Codecov's first report on #4347 listed these as uncovered changed lines: the dynamic parameter move check printing its evidence, asking Alembic about revision 7f7335f0eb31, and publication refusing to classify a country with no model assumption prefixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 26, 2026
anth-volk
marked this pull request as ready for review
November 26, 2026 20:44
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
…arameter_values dynamic_id drop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added a commit
to PolicyEngine/policyengine-sim-api
that referenced
this pull request
Nov 26, 2026
`public-api-commit` moves from `825a9b3c9` (C1 · 41's merge) to `806b1ec9a`, PolicyEngine/policyengine-api#4347's merge into `master`, whose revision `7f7335f0eb31` creates `dynamic_parameters` and `dynamic_parameter_values` and grants the service's role SELECT on both. The `Public API schema` job builds the tables at this commit, so the tests of the new tables run against them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
added a commit
that referenced
this pull request
Nov 27, 2026
C1 · 50 (#4347) merged without leaving dynamic_id out of ParameterValue's mapper, so the skill section's deploy order names C1 · 51a, which the user added to do it in its own release before this revision runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 27, 2026
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 #4346
Builds on #4345 (the UK
gov.dynamic.prefix and the one-time split of stored policy copies), which merged intomasteras1cf1d1ac7; this branch contains it and targetsmaster.Summary
Two tables.
dynamic_parametersholds each catalog version's model assumptions (gov.simulation., USsimulation., UKgov.dynamic.), withparameters' columns, catalog IDs and unique name per version.dynamic_parameter_valuesholds:dynamic_id);dynamic_id,CASCADE);with no
policy_id. Likeparameter_values, it has the period check, the period index, and two partial unique indexes: one current-law value per parameter and start date, and one value per dynamic, parameter and start date.parameter_nodesstays shared.Revision
7f7335f0eb31(parentd417fe8b1b17,master's head) is autogenerated for the tables. Its one hand-written data step is the explicit human migration decision the skill's "Mandatory generation rule" requires: the user's decision C1 · 46, Q2 (2026-11-25). In the one transaction thatmigrations/v2/env.pyruns every pending revision in, the step:parameter_valuesrow with apolicy_idnames one (deleting the parameter would delete the value and silently change the policy), or while a dynamic's value names a parameter it doesn't move (the new tables can't hold it);gov.simulation, USsimulationand UKgov.dynamicand everything below them;More on the revision:
DYNAMIC_PARAMETER_PREFIXES.seed-v2-database.yml(scripts/qualify_v2_dynamic_parameter_move.py) counts the same policy values before the upgrade, so a deploy stops with the count before Alembic starts.Publication:
entity_counts, anddynamic_parameter_valuesinrestored_catalog_versionsand inPrunedCatalogVersion);Readers and writers:
/v2/policiesnames in its 422dynamic_parametersthe IDs it finds indynamic_parameters./v2/dynamicsnames in its 422policy_parametersthe IDs it finds inparameters.Grants:
UPDATE.C1 · 48's split command is removed (decision 3, the user, 2026-11-25). Operator step C1 · 49 runs it before this revision, and afterwards no stored policy can hold a model assumption. The command, its package, its temporary role's grants,
V2_POLICY_COPY_SPLIT_DATABASE_URLand its tests go; the Stage 10 runbook keeps a short account.docs/engineering/skills/alembic-migrations.mdgains "API v2 dynamic parameters in their own tables", and the Stage 9 and Stage 10 runbooks follow.Deploy order
A merge to
masterreleases and runs the revision in staging and production, so this must not merge until both of these hold in both environments:parameter_valuesrow with apolicy_idnames a model assumption. Otherwise the seed job stops at the new check step.parameter_values, so after the move it would read none and run the dynamic as current law, storing that result. With Update PolicyEngine CANADA to 0.87.1 #1122 it refuses a dynamic without values (400dynamic_without_values, which API v1 answers as 503) until C1 · 52 reads the new tables.After it: C1 · 52 (the simulation service reads the new tables), then C1 · 53 (drops
parameter_values.dynamic_id).The deploy window is an accepted exception (decision 2, the user, 2026-11-25). It is the second exception to "the serving revision must work with the database changed on its own", after catalog pruning's first release, and this PR's review is the maintainers' approval. From the seed job's upgrade until the new release is promoted (or a later release succeeds), the previous API v1 release serves on the moved tables:
GET /v2/dynamics/{id}answers 200 with no values.POST /v2/dynamicsanswers the generic 422.POST /v2/policiesanswers a model assumption with the generic 422 instead of the named one.missing_parametersand the v1 response unchanged, for v1 policies that set model assumptions; such a policy gets no v2 copy until it is written again.Nothing in production calls these v2 routes yet.
Environment variables of the new step:
V2_MIGRATION_DATABASE_URL: a GitHub Actions environment secret instagingandproduction, passed bypush.yml'ssecrets: inheritand the step'senv:.V2_SUPABASE_PROJECT_REFandV2_SUPABASE_ENVIRONMENT: environment variables, set in the job'senv:.These are the same as the three existing check steps.
Testing
alembic -c alembic-v2.ini checkfinds no drift on a fresh database.reconcile_v2_privileges.py apply --create-missing-rolesandverifypass.lint-imports,python -m scripts.rules validate,scripts/run_quality_guards.py, ruff, ruff format and mypy pass. mypy on the changeddata/v2files reports only the 7 errorsmodels/metadata.pyalready had.scripts/export_migration_contracts.pychanges nothing.Inline suppression added:
# noqa: BLE001onmain()'sexcept Exceptionindynamic_parameter_move_qualification.py. The command must print safe evidence for any failure, as the three existing check commands do.🤖 Generated with Claude Code