Repository navigation
Move the v2 report app's cache onto the prebuilt-file level handlers - #1136
Merged
Merged
Conversation
Record what main (6865dc2) produces for fixed inputs, so moving the v2 report app's cache (stage12_cache) onto the level handlers can show that its US behaviour is unchanged: - the plan from plan_artifacts_impl: the years 2026, 2027 and 2025 in that order, 3 default-dataset year files, 60 baselines (each year by the 20 region groups, in order) and 153 state files (each year by the 51 states sorted by code), with every stage12-ds1, stage12-sds1 and stage12-bl1 digest, store path, simulation ID and output plan hash; the bundle identity, partition hash, determinism record path and the presence flags and select_work result; - the key payloads of the three identities, which include policyengine-core's version and the output plan's SHA-256; - the manifest: entry order, hashes and sizes, top-level fields, the exact payload of a one-entry-per-kind plan, write-once publishing of its canonical bytes under their digest, and the digest line the precompute prints; - which runs build_stage12_simulation gives a fixed cache identity (every planned group baseline, an unplanned state group, a planned group in a year without files) and which a random one (reform side or role, a policy, US national without a group, one state, a district, a group with a district, UK-wide); - the download step's checks: exactly 3 year files and 60 baselines, the years in submission order, each file's size; and the deployed worker's check of the downloaded cache and the release it reports. The image folders (where the download step places files, where the worker loads a state's or district's dataset from, where the deploy check reads its probe baseline, and the manifest digest, which covers each state file's folder) are pinned in classes of their own: the handler design moves those folders to prebuilt/, so those pins change in a commit of their own. The manifest is also pinned without its folder fields, which must not change. The inputs are stand-ins with no GCS, Hugging Face or Modal access: a fixed Stage 12 bundle and release bundle, the 51 US state regions with their real codes and FIPS numbers, two districts, a fixed SPM capability and an in-memory cache bucket. The national partition is the real one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The v2 report app's cache should plan, place, check and look up its files through the level handlers in stage12_cache: - the plan takes its years from the US handler settings, its year files and baselines from the handlers' targets, and names each entry's country and prebuilt/ image folder (baselines sit beside their year file); which year-file and baseline levels it covers are the cache's own settings (stage12_cache.cache_levels), never the run_simulation app's, and a year file it has no key for is refused; - expected_cache_contents gives the years and the year-file and baseline counts, without loading the US model, for the download step and the deploy-time check; - every manifest entry records its folder (schema label unchanged); the download step places each file there, refuses a folder outside prebuilt/<country>/, and checks the years and counts it is passed; - the worker takes each run's folder from levels.prebuilt_dataset_folder, and qualifying_cache_identity takes the level and scope key from the handlers, giving a random ID when the scope lookup fails, the level is not one the cache precomputes, or the group lists anything but states; - the year-file builds go through the handlers' write_year_files, the baseline build downloads its year file into the prebuilt folder, and the copies the handlers replace are gone. 33 of the 34 tests fail on the current code; the one that passes guards that the cache ignores the run_simulation app's levels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The approved handler design (1.6 · 1, section 6.2) moves every prebuilt file under prebuilt/<country>/<dataset>/<state or "all">/, so the v2 cache's files move there too: state files from state-datasets/<dataset>/<state>, and year files and baselines from the image data folder itself to the national folder, where a baseline sits beside the year file it was computed on. The user chose on 2026-11-26 that every manifest entry records its folder, so the download step, which runs before the package code is in the image and cannot call the handlers, places each file where its entry says. These pins change with it, and only these: - the plan entries' folders, and where the download step places each file and the deploy-time check reads its probe baseline; - the folder a state, district, national or group run loads its dataset from (national and group runs now read the national prebuilt folder when the image holds it); - the manifest's full digest and the exact payload of a small plan; the digest without the folder fields is unchanged; - the download pins pass the expected years and counts, which the step now receives from the deploying machine instead of holding as constants; what it accepts and refuses is unchanged; - two pins read the years and state targets through the handlers, since main's PRECOMPUTE_YEARS and state_dataset_targets are deleted; their values are unchanged. The fixture now patches only the module attributes that exist, so it works before and after the change. The plan, key, digest-without-folders and fixed-ID pins pass unchanged; the 19 changed pins fail until the change lands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The v2 report app's cache (stage12_cache) now plans, builds and looks up its files through the level handlers in stage12_cache/levels*.py, and its copies of that code are gone (design 1.6 · 1, section 6.2): - stage12_cache/cache_levels.py holds the cache's own levels: US national and state year files, and the state-group baselines. They are separate from the run_simulation app's year_file_levels and baseline_levels, so a task that adds files or fixed IDs there does not add them here. - The plan takes its years from the handler settings and its targets from the handlers, keyed by the existing stage12-ds1, stage12-sds1 and stage12-bl1 identities; a target the cache has no key for is refused. Every plan entry names its country and the handler's prebuilt folder. The baseline keys go through qualifying_cache_identity, so the precompute and the worker apply one rule. - qualifying_cache_identity takes the run's level and scope key from the handlers. A fixed ID still needs a current-law baseline whose group lists only states, and a level the cache precomputes baselines for (the user's decision of 2026-11-26: fixed IDs for the 20 state groups as today; other runs keep random IDs until a task adds their level, noted on 2.2 · 6 and 2.1 · 1). A failing scope lookup gives a random ID. - The year-file builds go through the handlers' write_year_files; the baseline build and the determinism check download the year file into the baseline's prebuilt folder, where .py saves the baseline beside it. - Deleted: state_dataset_targets, StateDatasetTarget and PRECOMPUTE_YEARS; _checked_state_targets, _registered_district_geoids, _require_districts_within_their_states and the filtering body of the state build; the state_datasets lookup (year_file_reuse_problem stays, for the handlers); the scope half of qualifying_cache_identity. - Every manifest entry records its folder (the user's decision of 2026-11-26; schema label unchanged). The image download step, which runs before the package code is in the image, places each file there, refuses a folder outside prebuilt/<country>/, and checks the years and counts the deploying machine computes with expected_cache_contents instead of fixed constants. The deploy-time worker check reads the same values and its probe baseline from its folder. Keys, store paths, the set of files built and the fixed-ID outcomes are unchanged: the plan, key, folder-free manifest digest and fixed-ID pins pass unchanged, and the image-folder pins moved in the previous commit. No environment variable is added or removed; the download step gains an argument passed from the deploying machine. Existing tests are ported to the new fields, folders and interfaces; tests of code that moved into the handlers are deleted where 1.6 · 2's handler tests cover it (tests/test_prebuilt_levels.py, test_prebuilt_state_files.py). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adversarial review round 1 confirmed three defects; these tests fail until they are fixed: - a failure while loading the handler settings fails a request instead of giving its baseline a random ID, because the settings are loaded outside the guarded scope lookup; - a cache setting with no baseline levels plans fine, then crashes the precompute after the year files are built, and would also crash the manifest publication and the deploy check: planning and expected_cache_contents must refuse it first; - the national year-file build leaves an empty temporary folder behind on every call. Two tests that relied on an empty baseline setting now show the same dependence on the cache's own levels another way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- qualifying_cache_identity loads the handler settings inside its guarded lookup, so a failure there gives the baseline a random ID instead of failing the request, as the prebuilt-folder lookup already did. - plan_artifacts_impl and expected_cache_contents refuse a cache setting with no baseline level (required_baseline_levels) before anything is built: the precompute's determinism check, the manifest's publication and the deployed worker's check each probe a precomputed baseline. - The national year-file build passes the handler a temporary work folder that is removed afterwards. - A new test runs the real prebuilt-folder lookup during the precompute's baseline build, with only the dataset loader replaced: it loads the downloaded year file from the baseline's prebuilt folder. The existing test stubbed the calculation, so it showed only where the year file is downloaded and where the upload is read from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The expected-contents test no longer treats as valid a setting that precomputes group baselines without the national year file they run on; it now varies only the handler years. - The states-only test now uses a group that includes a district: its level is one the cache precomputes and the handler gives it a scope key, so only the states-only check keeps it from a fixed ID. The old version used a national run, which the handler gives no key, so it passed whether or not the check existed. With the check replaced by one that accepts any group, the new version fails. Round 2's third finding is left as stated in the pull request: national and group runs find their year file only through the handlers' lookup, which reads private .py helpers; the precompute and the deploy check fail if that lookup stops finding it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 27, 2026 18:16
anth-volk
added a commit
that referenced
this pull request
Nov 27, 2026
Since #1136, qualifying_cache_identity takes the run's RunScope (country, year, region and dataset selection) in place of the dataset-default flag and the scoping strategy. The test now builds it as the segment worker does. Against main's coordinator the identity test still fails with stage12-bl1-6bf58faeedaedc36 against stage12-bl1-928929ee9ffcc2a4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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 #1135
Summary
Moves the v2 report app's cache (
stage12_cache/) onto the prebuilt-file level handlers and deletes its copies of that code. The handlers were added by #1132, which merged intomain; this branch was built on that PR's head and hasmainmerged in. Its keys, store paths, the set of files it builds, which runs get a fixed cache ID, and its US results are unchanged. What changes is where the files sit in the worker image: every file now sits in its handler'sprebuilt/<country>/<dataset>/<state or "all">/folder.What changes
Paths are under
projects/policyengine-simulation-executor/src/.stage12_cache/cache_levels.py(new) lists the year-file levels the cache bakes (US national and state) and the levels whose baselines it precomputes (US state groups). These settings are separate from the run_simulation app'syear_file_levelsandbaseline_levels, so a change there adds no files or fixed IDs to the v2 cache.stage12_cache/precompute_planning.py):stage12-ds1,stage12-sds1andstage12-bl1identities.qualifying_cache_identity, the function the worker uses.expected_cache_contentsgives the years and the year-file and baseline counts without loading the US model.write_year_files. The cache's copies of the state targets, the district checks and the state filtering are deleted.stage12_runtime/cached_simulation.py):qualifying_cache_identitynow takes the run's level and scope key from the handlers.state/…codes, and a level the cache precomputes. Every other run keeps a random ID.stage12_runtime/simulation.py): the worker gets each run's folder fromlevels.prebuilt_dataset_folder. National and group runs now read the national prebuilt folder when the image holds it.folder; the schema label staysstage12-mf1.src/modal/stage12_cache_image.py) places each file in that folder.prebuilt/<country>/.src/modal/v2_app.pycomputes on the deploying machine, instead of fixed constants.stage12_worker_validation.py) reads the same values, and reads its probe baseline from its folder.PRECOMPUTE_YEARS,StateDatasetTargetandstate_dataset_targets.baked_state_data_folderlookup;year_file_reuse_problemstays, because the handlers use it.qualifying_cache_identity.What stays the same, and the evidence
New pin tests (
tests/test_v2_cache_us_*_pins.py, inputs infixtures/v2_cache_us_inputs.py) record whatmainproduced for fixed inputs. The commits come in this order: the pins; failing tests of the new behaviour; the pins that change, updated alone; then the change. After the change, these pins pass unchanged:folderfields;The pins that changed are the image-folder ones, the manifest's full digest, and the download step's pins, which now pass in the expected counts. Two pins of deleted names now read the same values through the handlers.
Deployment effects
folderfields alone.modal deploy, so a normal deploy is unaffected.Environment variables
The change adds and removes none, and changes no wiring. The download step gains one argument, the expected years and counts. The deploying machine computes it from the installed .py package's metadata and the handler settings, which read no environment variable.
POLICYENGINE_DATA_FOLDERSTAGE12_DATA_DIRinsrc/modal/v2_app.pybuild_v2_image's.env({...})step, before the download stepSTAGE12_CACHE_MANIFEST_DIGESTv2_app._deploy_time_cache_inputs; download stepenv:insimulation-deploy.reusable.yml, then the image.env({...})stepSTAGE12_CACHE_BUCKETv2_app._deploy_time_cache_inputsvars.STAGE12_CACHE_BUCKETenv:STAGE12_BUNDLE_MANIFEST_SHA256.env({...})stepGOOGLE_APPLICATION_CREDENTIALS_JSONstage12-evaluation-gcp-credentialsrun_function(..., secrets=[gcp_secret]); the key names inside the secret are not visible in the code (unverified)Known limitations
Checks run
mainmerged in. The full suite was not run locally.scripts/run_quality_guards.py, and the changelog fragment check againstmain.🤖 Generated with Claude Code