Repository navigation
Household calculations and reports apply a dynamic, and every simulation refuses another country's dynamic - #1113
Merged
Merged
Conversation
… country (failing) Household jobs take and store a dynamic_id, household reports and their re-runs take one per side, and each merges the dynamic's values into the household reform, as economy simulations do. Every simulation refuses a dynamic stored for another country. The insert_dynamic test helper writes the columns API v1's revision 9d1d12a7ac58 requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ther country's Household jobs take a dynamic_id, store it in household_jobs.dynamic_id and return it in the job's state; household reports and their re-runs take one per side. Each reads the policy's and the dynamic's values together with the new read_simulation_reform, as economy simulations now do too, so a parameter both set is refused. The household report key already names each side's dynamic, and a stored household report naming one is now re-run with it instead of refused. The Dynamic model gains country_id, and read_dynamic_reform refuses a dynamic stored for another country as UnknownDynamicError, which every route answers as unknown_dynamic. A value the household contract refuses is located at dynamic_id when the dynamic sets its parameter. public-api-commit moves to 003ee4996, API v1's merge of PolicyEngine/policyengine-api#4325, whose revision 9d1d12a7ac58 gives dynamics their country. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and require dynamic_parameters Review round 1 found two existing tests that the change broke: a route case still expected a household report side's dynamic_id to be refused, and the generated-client test read a household job state without the now-required dynamic_id. Both now expect the new shapes, and new route and generated-client tests send each side's dynamic and read it back. The inputs that carry which parameters a dynamic sets now require them, so no caller can leave them out and have a refused dynamic value located at policy_id. The README paragraphs this change edited are rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h its dynamic's parameters Review round 2 found no bugs. Its quality findings: - Economy requests and household reports now build the refusal of a simulation's policy or dynamic with one function, simulation_values_refusal, so each says the same thing and locates it the same way. The household calculation route keeps its own refusals, whose details and error types differ. - The household inputs carry each side's SimulationReform, the combined values with the parameters its dynamic sets, instead of two parallel fields. - The entry README's re-run refusals and the CallerRowRefusalCode comment name the dynamic refusals, and two README paragraphs are rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1096 moved public-api-commit to d2b5dc31, API v1's merge of PolicyEngine/policyengine-api#4327, which contains 003ee4996, and rewrote insert_dynamic to write the same columns. The conflicts keep main's pin and helper, and this branch's Dynamic.country_id, with the model's docstring saying that sim reads the country. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
main now pins API v1's merge of the report column drops (825a9b3c), and its table models drop the columns C1 · 41 drops. Nothing conflicted. 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
November 25, 2026 20:16
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
…namic parameter tables branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
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 #1112
Household calculations and household reports now apply a dynamic, as economy simulations do. Every simulation now refuses a dynamic stored for another country, using
dynamics.country_idfrom API v1's revision9d1d12a7ac58(PolicyEngine/policyengine-api#4325). The pin move and theinsert_dynamicchange this PR first made are now onmain, from #1096.What changes
Persistence library
Dynamicgainscountry_id.read_dynamic_reformtakes the country and raisesUnknownDynamicErrorfor a dynamic stored for another country, asread_policy_reformdoes for a policy.read_simulation_reformreads a simulation's policy and dynamic and combines them withcombine_reforms, which refuses a parameter both set. It returns aSimulationReformholding the values and the names of the dynamic's parameters. Every reader uses it:read_simulation_values;HouseholdJobStore.read_inputs, which now takesdynamic_id;HouseholdReportStore.read_inputs, which now takes each side'sSimulationChoiceinstead of policy IDs.NewHouseholdJobandHouseholdJobRecordgaindynamic_id, stored inhousehold_jobs.dynamic_id.dynamic_id; it was always null.public-api-commitand the test helperinsert_dynamic: no change left in this PR. Calculate each simulation run's cliff gap and share as its own cliff result #1096 moved the pin tod2b5dc31(Store one cliff result per simulation run, and run every database statement through the ORM policyengine-api#4327's merge, which contains003ee4996) and changedinsert_dynamicthe same way; Drop the report columns API v1 removes from sim's table models #1111 then moved the pin to825a9b3c(Drop the per-user and cliff columns from v2 report rows policyengine-api#4335's merge). The merges ofmain(36f61d43,d2328526) keep both.Simulation Entrypoint
POST /household-calculationstakesdynamic_id, andGET /household-calculations/{id}returns it.HouseholdPolicyChoice) takesdynamic_id. A stored household report whose side names a dynamic is now re-run with it, where it used to be refused with 409.unknown_dynamic, also for a dynamic of another country;missing_parametersatdynamic_id, for a dynamic setting parameters the catalog version lacks;overlapping_parametersatdynamic_id, for a dynamic setting a parameter the policy also sets.dynamic_idwhen the dynamic sets its parameter.simulation_values_refusal. Theunknown_dynamicdetail now names the country.The v1
run_simulationcode imports nothing this adds. API v1 sends no householddynamic_iduntil C1 · 45.Tests
1717addacommitted the failing tests. Then 29 of 50 persistence cases and 40 of 54 entry cases failed, for the expected reasons.003ee4996before the merges ofmain, then at each pinmainbrought in:d2b5dc31and now825a9b3c(revision4e30076d4b9f). At825a9b3c, 61 persistence cases (the six comparisons included), 95 entry cases and 4 generated-client cases pass.scripts/generate-clients.sh.main, all five comparisons also pass at003ee4996. Between63cce8273and003ee4996, API v1's tables changed only indynamicsand in tables sim doesn't model.Deploy order
Production must have API v1's revision
9d1d12a7ac58before this releases. As of 2026-11-24 it does (below).dynamics.country_idwhenever a request, or a stored record being re-run, names a dynamic.database_unavailable, where it is answered 400 today. Requests without a dynamic don't readdynamics, and no readiness check reads the column.mainreleases and deploys by itself, so this PR should merge only after API v1's production release containing #4325.Read from GitHub only (no database read):
80a42ddebhad staged the revision, but its Push run then failed before any production job.5d9b1eee8, which contains003ee4996andd2b5dc31, finished its Push run on 2026-11-24, includingSeed production v2 database / Upgrade schema and seed v2 databaseandDeploy production Cloud Run candidate. So production's v2 database has been upgraded past9d1d12a7ac58.Grants
From API v1's
privileges.pyat003ee4996, no new grant is needed:dynamics: table-levelSELECTfor the simulation service role and the Modal worker role.household_jobs:SELECT, INSERTfor the service role, so it can insertdynamic_id, plusUPDATEon the call-start columns.simulations,parameter_values,parameters,policies,householdsand the catalog: unchanged.825a9b3cand C1 · 43's merge9bcda036(Let users save named dynamics through /v2/user-dynamics policyengine-api#4337), which adds only theuser_dynamicstable and its grants.The persistence tests ran as
policyengine_v2_simulation_serviceon a database with those grants applied. Sim's readiness list (SERVICE_TABLE_PRIVILEGES) already requiresSELECTondynamics.Pin order and overlap
mainpins825a9b3c, C1 · 41's merge (Drop the report columns API v1 removes from sim's table models #1111), and this PR keeps that pin. C1 · 43 adds onlyuser_dynamics, which sim doesn't model, so no pin move is needed for it.mainis merged into this branch twice:36f61d43(Calculate each simulation run's cliff gap and share as its own cliff result #1096, Start each side's cliff calculation when a report asks for cliffs #1099): the conflicts inpublic-api-commit,tests/public_api_rows.pyandinput_tables.pywere resolved as above.d2328526(Drop the report columns API v1 removes from sim's table models #1111, Restore the simulation workers from Modal memory snapshots with the country models loaded #1118): no conflicts. Drop the report columns API v1 removes from sim's table models #1111 also changed__init__.py,test_keyed_household_records.py, the entry README andhousehold_report_reruns.py, in separate hunks.Review
dynamic_idto be refused;dynamic_id.SimulationReformpassed through, and documentation.mainatd2328526, the changelog fragment dropped its sentence naming the pin at003ee4996, sincemainnow moves the pin (f7161f1f). A review of that edit found no bugs; its one quality finding, that no fragment then said sim readsdynamics.country_id, is fixed inaee0634c.🤖 Generated with Claude Code