Skip to content

Declare target sets and target registers as data, with shared code for the US and the UK (no target change) - #1755

Draft
juaristi22 wants to merge 35 commits into
mainfrom
claude/us-target-set-declarations
Draft

juaristi22 wants to merge 35 commits into
mainfrom
claude/us-target-set-declarations

Conversation

@juaristi22

@juaristi22 juaristi22 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1728 (work item 1) and of #1759.

This PR stays a draft while more commits land on this branch. Those commits also keep the calibrated targets the same.

The national and the local build compile the same target registry, then each tool keeps a subset. Until now the subset was in tool code. This PR declares it as data, for each product and mode, and both tools select by the declaration. The UK now selects its targets with the same shared code (see "#1759 on this branch"). No target surface changes, in the US or the UK.

What this PR adds

File What it is
packages/microcosm-calibrate/src/microcosm/calibrate/target_sets.py The shared reader and selector. It holds no country code: a country passes its named predicates and rules.
packages/microcosm-build/src/microcosm/build/us/spec/target_sets.yaml The US declarations: product national (--target-surface: full, national_state) and product local (--soi-mode: state, totals, full, state_cd, state_county). us/country_package.json lists it as a typed resource of kind target_sets.
packages/microcosm-build/src/microcosm/build/spec_engine/schema/target_sets.schema.json The schema of the declarations, the sixteenth of the spec engine's catalog (see the review of 27 Nov below).
packages/microcosm-build/src/microcosm/build/us_runtime/target_sets.py The US names: the file, the products, the congressional_district predicate and the state_cd_district_shares rule.
tools/build_us_fiscal_refresh_release.py _select_target_surface selects by the declaration.
tools/build_us_acs_local_release.py state_admin_surface and soi_surface_predicate select by the declaration.
docs/us-target-sets.md How the declarations work, what each mode selects, and how to change a target set.

A declaration states, for each mode:

  • Compiled clauses: families, levels, metadata tests, named exclusions and a named rule. The selection is each clause's targets in declaration order, in compile order inside a clause.
  • Built rows: the rows the tool makes itself (the PUMA ladder's population totals; in state_county, the county SOI shares and ACS households). The declaration names their family and levels.
  • A rationale for each clause, as the UK membership files have for each exclusion.

A target's family is TargetSpec.family. Its level comes from the level rule that the file declares: for the US, ledger_geography_level, else geography_level. These are the labels that the shared target-loss rule of #1735 reads, so a target has one family and one level everywhere. The UK declares its own level rule in uk/spec/target_sets.yaml (see "#1759 on this branch").

Proof of no change

Each surface was measured on the pinned 41b2fb2 feed on main 0f963ac77 before the change and on this branch after it. The count, the TargetRegistry version (an order-sensitive content hash), the family × level census and the selection receipt are identical for every surface:

Product Mode Targets Registry version
national full 31,748 4cc4cfb7a147
national national_state 6,102 4dfe25b1238a
local state 4,380 compiled; 4,867 with the ladder's 487 population rows 0ee16ca42be5; 69b952ef181f
local totals 255 c6a0f757c0bc
local full 29,977 b6c71f2e8505
local state_cd 26,425 e0bb302e3add
local state_county 4,380 compiled, then the county rows 0ee16ca42be5

test_us_target_sets.py pins all of these. The pinned-feed tests run when MICROCOSM_US_CHRONICLE_FACTS names the feed; the 4,867 test also needs MICROCOSM_US_PUMA_LADDER_ARTIFACT (the ladder with SHA256 39a2ab2a…).

Differences on other feeds

The local SNAP, Medicaid, totals, full and state_cd filters used to keep every row that carries state_fips, at any level. Their clauses now also name the level: state for SNAP and Medicaid, state and district for the SOI rows of totals, full and state_cd. On the pinned feed every such row is at a declared level, so nothing changes. On a feed with such rows at another level (for example county rows in the main feed), they stay out until a clause names the level.

The SOI clause of state and state_county reads a row's level as every clause does: ledger_geography_level, else geography_level. The filter it replaced read only ledger_geography_level. So a state SOI row that carries only geography_level now enters these two modes. Every compiled row carries ledger_geography_level, so no compiled registry changes.

The national modes keep "*" for families and levels, as before: a family that a re-pin adds still enters full and national_state (unless the district classifier drops it).

Pins that move

The US bundle has three new resources: the typed spec/target_sets.yaml, and the legacy_json rows us/local_target_construction.json and us/fiscal_target_registers.json. They move the US F0 spec-engine pins:

  • 42,557 configuration fields (32,771 authored).
  • The country_manifest claim has 122 pointers, and a new target_sets claim in the field ledger has 144.
  • The pointer inventory digest.
  • The bundle's semantic spec_sha256 is e76daa6c. Pool builds record it in their run config's spec binding. It now covers the declared clauses of the target sets.
  • The spec engine's catalog has a sixteenth schema, target_sets.schema.json, and a resource kind target_sets.

These are identities, not targets: no target changes. us_runtime/target_sets.py joins the reviewed non-registry modules in test_us_spine_blindness.py.

The spec-engine pins are US-only, and the UK gate battery's fingerprint covers only the gates manifest. So the new UK resource uk/spec/target_sets.yaml moves no pin. It does change the UK solve fingerprint (see "What a UK build computes again" below).

The US JSON resource rows are in sorted order since 202b82526. The order moves no pin: both --check modes of the re-pin tools pass unchanged.

Merges

Tests

  • New: packages/microcosm-build/tests/engine_free/shared/test_spec_engine_target_sets.py (the resource kind and its schema, the documentation projection, the content hash and the narrow loader; 67 tests), packages/microcosm-calibrate/tests/engine_free/shared/test_target_sets.py (the shared reader and selector, 50 tests) and packages/microcosm-build/tests/engine_free/us/test_us_target_sets.py (the US declarations against the tools, the pinned surfaces, and a check that every compiled target's level is the level that target_loss_weights.target_geography_level gives).
  • Run locally with the pinned feed and the ladder: the new tests, and test_us_acs_local_release_tool.py, test_us_acs_local_county_surface.py, test_us_acs_local_sparse_cd.py, test_us_fiscal_refresh_builder.py, test_us_fiscal_targets.py, test_release_target_parity.py, test_first_party_imports.py, test_transport_evidence_kernels.py, and the country-package and spec-engine tests (test_spec_only_country_packages.py, test_country_spec.py, test_us_spec_bundle.py, test_spec_source_citations.py, test_spec_engine_loader.py, test_spec_engine_reemission.py, test_transport_composed_graph.py). ruff and tools/ci_test_plan.py verify pass.
  • New for Consolidate the shared target code so it serves the UK and the US #1759: test_uk_level_selection.py, test_uk_calibration_line_selection.py, test_uk_review_loaders.py, test_uk_reviewed_exclusions_core.py and test_uk_target_surface_pins.py, with additions to test_target_sets.py, test_holdout.py, test_declared_registers.py and test_us_target_holdouts.py. The verbatim copies of the replaced code are in test_support/microcosm_build/.
  • Run locally for Consolidate the shared target code so it serves the UK and the US #1759: the touched UK and shared tests, test_uk_target_compile_modules.py, test_country_spec.py, test_first_party_imports.py, the US pinned-feed pins (34 tests, at D4; D5 to D7 change no US code), and all 22 UK pin tests at 9130ebe15 (the surface and the national registry compiled from the pinned feed; the 19 selections on the pinned surface).
  • Run locally after the review fixes (27 Nov): 1,519 touched shared and US tests with the pinned feed and the ladder (none skipped), 1,132 touched UK tests, and the 19 UK selection pins on the pinned surface. The UK surface and national registry were not compiled again: no review fix changes the compile path.
  • Run locally after the review by anth-volk (27 Nov): the shared reader's tests; the spec-engine, country-spec and US bundle tests; the touched US tests with the pinned feed and the ladder (the surface, receipt and level pins among them; none skipped but six that need an optional package); test_uk_solve_scope.py and the UK and shared tests that read the country spec or the solve fingerprint; both --check modes of the US re-pin tools and the coverage tool (42,557 of 42,557 fields, 41 of 41 checks). The engine_contract and engine_workflow tests need the US engine, which the local environment does not have: they run in CI. On 884f1eb53 both engine-free jobs failed on one test, the closure check of the transport compile list (test_transport_compile_modules.py); 5eac92f5f corrects it. On 5eac92f5f every CI job passes: lint, wheels, integration-uk, and engine-free, engine-uk and engine-us on Python 3.13 and 3.14.
  • The rest of the suite runs in CI. On 9130ebe15 and 202b82526 every CI job passed except engine-free, which failed only on a UK clock test (test_no_committed_exclusion_is_about_to_lapse) that failed on main too. Main has renewed the entries (Draw LCFS spending as a budget and a donor's mix, and fix the donor's income predictors (#1717) #1736), and this branch has that main merged. After the merge, 1,660 touched UK tests (every clock test among them) and 1,680 touched US and shared tests with the pinned US feed pass locally.

Builds

None. No surface changes in either country, so no build is needed. The first UK build after this PR merges computes some nodes again, with the same outputs (see "What a UK build computes again").

Shared-code work on this branch

The calibrated targets stay the same for now, so that #1719 keeps its behavior. The tool code that builds the target surfaces moves to shared code in later commits on this branch, each with no target change. Done so far:

  • f605ffa07 (C0): test_us_acs_local_surface_bytes.py follows the target part of do_materialize for each non-county --soi-mode and pins the sha256 of target_registry.json, target_roles.json, the target receipts (SOI surface, district and county hold-outs) and the population rows' matrix, on the pinned feed and ladder. These pins also catch a change of metadata key order, which TargetRegistry.version does not (it sorts the keys). state_county is not pinned yet: it needs the pinned county facts and a household frame.
  • fb34e5e29 (C1): the US ledger filter rules (25 names, 446 lines) move verbatim from the national tool to us_runtime/ledger_filter_rules.py; the tool imports them back. Two builder tests that changed a rule on a fresh copy of the tool now use monkeypatch, because every load of the tool shares the package module. The district surface reads them from the package, so it no longer imports the national tool. The local tool compiles the registry in one function. The C0 pins pass unchanged.
  • 868f414bc (C2): the district and county hold-outs run on the new shared microcosm.build.target_holdouts (hashed blocks from declared passes, the training target set, and scoring against the pro-rata baseline). The US passes are declared in the new us/local_target_construction.json; the tool functions keep their names. test_us_target_holdouts.py holds them to verbatim copies of the replaced code on random records (91 tests), and the C0 pins pass unchanged.
  • 904a46d86 (C3): the state and district ladder population rows and specs run on the new shared microcosm.build.ladder_population_targets, declared in the ladder_population section. The district module no longer imports the county module. test_us_ladder_population.py holds the tool functions to verbatim copies of the replaced code (54 tests), and the C0 pins pass unchanged.
  • 33cdf6667 (C6): the 13 reviewed registers of the US fiscal target compile (the fact exclusions with their reasons and vintage scope, the misread source columns, the restamped source packages, the SOI variable maps, the direct and indicator Ledger targets, the M-CHIP states) move to us/fiscal_target_registers.json, with their code comments as descriptions and notes. The new shared microcosm.build.declared_registers reads them back as the literals they replace, and the code keeps every name. test_us_fiscal_target_registers.py pins each register's digest as measured on the literals, the pinned-feed compile under four flag sets (full registry JSON) and the exclusion receipt. docs/us-target-sets.md describes the declared construction and the registers.

The district SOI shares of state_cd and the county rung stay tool code. They make child rows as shares of parent rows, and one nesting rule across all levels will replace them, together with the district rows of #1731.

#1759 on this branch: one shared module for each job, in both countries

María ruled (26 Nov) that #1759 goes into this PR, so that the duplicates this PR made do not reach main. Each commit keeps the outputs of both countries the same and carries its own proof. The proofs compare the new code with verbatim copies of the code it replaced (in test_support/microcosm_build/*_reference.py).

Commit Step What changes Proof
fba28da98 D0 The new name of the US matrix-row measures is pinned (see "One label changes" below). test_us_target_holdouts.py
ca3a67e9b D0 The UK target nodes' artifacts are pinned on the pinned Chronicle feed (15040ea5, sha256 9fc0715e…) and the OA ladder, at calibration year 2025 and review date 2026-11-26: the full surface, the selection for 19 parameter sets (13 selections, 6 refusals) and the national registry. The digests were measured at 38dbd0187, before D1. test_uk_target_surface_pins.py passes at 9130ebe15: the surface and the national registry compiled again from the feed, and the 19 selections. Main has since re-pinned the UK feed to e4d46c93 (#1736), so these tests skip, with the reason, until the pins are measured again on the new feed (ca2444289)
e9317a3bb D1 microcosm.calibrate.target_sets reads a declared level_rule (keys, a closed set of levels, refusal of a conflict), and select_by_levels keeps a run-time set of levels in compile order, with the receipt microcosm.calibrate.target-selection.v1. The US level_keys form was unchanged at this commit; since 36d976c7b the US file declares its rule in the same form (see the review of 27 Nov below). shared tests
61e24394d D2 The UK declares its target sets in the new uk/target_sets.json (since 8fd3e88e9: uk/spec/target_sets.yaml): the level rule and the full build's selection by level. uk.full.target_selection@1 selects with the shared code, and target_geography reads the declared rule. microcosm.calibrate.target_selection is removed (the UK kernel was its only caller). test_uk_level_selection.py: 400 random registries and requests, refusals included
0d5dc1a9d D3 The two UK calibration lines are the modes of a calibration_line product. The line filter selects through it with one UK predicate; each target's calibration_lines stays in the contract. The shared selector reads a level only when a clause tests levels. test_uk_calibration_line_selection.py
4e74c81a1 D4 microcosm.build.holdout gains HoldoutSplit, fold_splits and held_estimates; the UK rowwise hold-out and the US local hold-out both use them. The draws stay apart on purpose. test_holdout.py: byte-equal to the replaced UK and US expressions on float64 matrices, which both builds pass
2ead043a4 D5 microcosm.build.declared_registers gains the shared review core for signed entries: read_strict_json, canonical_date, ReviewWindow and stale_entries. shared tests
c866b8951 D6 The UK calibration measure exclusions and the support floor check their dates and windows with the core. test_uk_review_loaders.py
34c8d436a D7 The UK reviewed exclusions (target fit, local target fit, area support) read their files, dates and windows with the core. test_uk_reviewed_exclusions_core.py
9130ebe15 docs/uk-target-sets.md describes the UK declaration, the hold-outs, the signed entries and what stays UK code.

Where a UK kernel now runs a shared module, it also hashes that module. The import-coverage test (test_uk_target_compile_modules.py) checks this for the target, problem and national kernels, and test_uk_graph_terminal.py pins the entries of the hold-out kernel and of each gate kernel.

One label changes (ruling 1). Commit C2 moved csr_row_measure to the shared microcosm.build.target_holdouts. The calibration diagnostics name each matrix-row measure <module>.<name>, so a US local release now writes microcosm.build.target_holdouts.target_matrix_row[N] where it wrote us_acs_local_cd_surface.target_matrix_row[N]. The targets and weights are the same, but target_surface.sha256 in calibration_diagnostics.json and build_manifest.json changes. María accepted the new name on 26 Nov, because no build uses these files at the moment. The changelog records it for anyone who compares two releases.

The UK hold-out stays as it is (ruling 5). The UK rowwise hold-out keeps its constants: 5 rotated folds over the local target rows, seed 20260529 (UK_LOCAL_HOLDOUT_FOLDS and UK_LOCAL_HOLDOUT_SEED in uk_runtime/local_rowwise.py). It is report-only. A stricter UK hold-out, for example one that declares its draw as data the way us/local_target_construction.json does, would start there.

What stays country code.

  • The UK support floor drops target rows that no source household carries; the US county minimum support moves donor households before targets exist. They are different policies at different stages.
  • The small-cell deferrals keep their own expiry check, because it also accepts compact dates.
  • The district SOI shares of state_cd, the county rung and off_surface_cells.py belong to the nesting work of US targets: one declared nesting rule across national, state, district and county levels #1760, which runs in parallel.

What a UK build computes again. uk/spec/target_sets.yaml is a new solve-scoped UK resource, so it is in the UK solve fingerprint (by its normative content since 8fd3e88e9), which the spine gates also hash. The first UK build after this PR merges computes these again: the spine from frs_brma on, the target nodes and every node after them, and the national graph. The target nodes write the same bytes (the UK pins above), and the other nodes run the same code on the same inputs. A UK release that is between its first build and its sign-off build when this PR merges would not reuse its solve.

Review by anth-volk (27 Nov)

The review made three suggestions on the declaration format and the UK cache key. Each led to a change. No target, order or pinned receipt changes: every surface pin in this description holds.

Commit Suggestion What changed
36d976c7b 1. One form for the level rule. The US file declares a level_rule, as the UK file does. The level_keys form and target_level are removed from the shared reader. us_runtime.target_loss_weights.target_geography_level reads the declared rule, and a test holds it to a verbatim copy of the replaced code. On the pinned feed all 31,748 compiled targets set ledger_geography_level only, so no target sets both fields; a test pins this.
36d976c7b 2. Rows dropped for their level leave no record. select_target_set returns left_out_by_level: the targets that an active clause names by family and that no such clause keeps at their level. The local tool writes the counts in materialize_rss.json under target_levels_left_out, beside the SOI receipt (its pinned bytes are equal). The assertion that could not fail (undeclared_cells on the kept rows) is replaced by a pin of the counts for each local mode.
8fd3e88e9 3. Key the UK solve on the content of the declared target sets, not on the file's bytes, through a schema of the spec engine. The declared target sets are a typed resource of the spec engine: kind target_sets, schema target_sets.schema.json, files us/spec/target_sets.yaml and uk/spec/target_sets.yaml. The schema marks each description and rationale as documentation. The country spec records the hash of each typed resource's normative projection, and the UK solve fingerprint takes it for its target sets. A reworded rationale or a new layout re-keys no solve node; a changed clause, level or exclusion re-keys every one. The calibrated gates and the release manifests keep the byte hash.

884f1eb53 adds microcosm.calibrate.target_sets to the reviewed list of modules in the gate battery's binding identity (test_transport_evidence_kernels.py): the country spec now checks the declared target sets with the shared reader when it loads a bundle. For the same reason, 5eac92f5f names the reader in transport.compile_modules.EXCLUDED_DIRECT_IMPORTS: country_spec is a listed transport compile module, and the compile calls only its reference validators, which do not read the reader. No compile kernel hashes the list module, so no node key changes.

What the typed resource changes beyond the cache key.

  • The bundle's spec_sha256 now covers the declared clauses. As legacy_json the files had no semantic content in the bundle, so a changed US clause moved no pin.
  • The products and the modes are lists with an id. The spec engine sorts the keys of an object, and the order of the UK calibration lines is content (two refusals list them), so an ordered thing must be a list.
  • The shared reader takes the object the spec engine parsed. Its own file reader is removed. The country modules read through country_spec.load_country_target_sets, which loads the one resource as the bundle loader does.
  • The US typed files are generated from the constants-era code, which never held the target sets. So the US file is written by hand (AUTHORED_DOMAIN_KINDS of the generator), with a reviewed claim in the F0 field ledger: a front-end validation whose verifier checks the domain against the schema and the shared reader. This claim is new in kind (a typed domain that the release tools read themselves, not through the constants adapter), so it needs a look from the owners of the spec engine.

The rows left out by level on the pinned feed. The review expected every count to be zero. They are not: no local mode keeps a country row, and the state and state_county modes keep no district SOI row (main's filter tested that level in code).

Family Level Rows Left out by
usda_snap country 2 every local mode
cms_medicaid country 3 every local mode
irs_soi country 441 every local mode
irs_soi congressional_district 22,996 state and state_county

Not in this PR.

  • Two parts of suggestions 1 and 2 add a refusal to a US build at run time, so they wait for a decision: a closed US level rule (four values, refuse a target whose two level fields disagree), and a refusal of a row at a level that a clause neither keeps nor names as left out.
  • us/local_target_construction.json and us/fiscal_target_registers.json are still legacy_json. By the same principle they should be typed resources; that is a follow-up.
  • The other typed UK resources still enter the solve fingerprint by their bytes.

What a UK build computes again is as stated above: the solve fingerprint has a new value, and the outputs are the same bytes.

Adversarial review (27 Nov)

A fresh reviewer agent read the whole diff against the claim that no output changes. It found no build input where the targets, their order, a receipt or a cache key differ. It found these gaps, and each has a fix on this branch:

Commit Finding Fix
dcd2e470e Three declaration readers took a repeated JSON key without a word (plain json.loads keeps the last one), ["*"] as a literal name and true as a version. The readers refuse them. The packaged files already pass. Since 8fd3e88e9 the spec engine's strict reader reads the target sets; it refuses a repeated key too.
47561f9a3 The shared hold-out and ladder code wrote generic refusal texts, and the tests compared only the error class. fraction=None drew the declared default without a word. The replaced texts are back, through declared labels (child_label and parent_label of a pass's scoring, code_name of a ladder level). None is refused. The tests compare class and text.
f7cdd43fc The UK reviewed-exclusion reader raised a new error class. A gate that fails closed records the class name in its report. The reader raises a plain ValueError again, and the UK tests compare the class.
b66abff84 The UK hold-out kernel ran the level-rule modules and the review core without hashing them. No stale result was possible, because a node key chains through its producers' keys. The kernel hashes them. test_uk_graph_terminal.py pins these entries and the review core in each gate kernel's hash.
0f4b6e8ca Four claims said more than the proofs: the level reading of the state SOI clause, the float64 premise of held_estimates, what the byte pins of C0 cover, and a stale field count in the changelog. Corrected in the docs, the changelog and the tests. A new test pins the float32 case.
202b82526 One US resource row was out of order. Sorted. No pin moves.

Three refusals differ on purpose. One shared check now serves both US hold-out passes:

  • the county fraction refusal also names the value, as the district one always did;
  • the district pass checks its salt before it reads a record, as the county pass always did;
  • the county scorer reads role on every record, as the district scorer always did.

No run of the tool reaches these cases: the command line checks fractions and salts first, and the district pass gives every record a role. test_us_target_holdouts.py pins all three, and docs/us-target-sets.md lists them under "Refusals". A refusal is still a ValueError (the shared error classes are subclasses).

What the proofs do not cover. The pinned-feed tests do not run in CI, because CI has no feed; the random-record comparisons and the register digests do. The UK pins cover the compile, the selection and the national registry, on feed 15040ea5; they skip since main re-pinned the UK feed. The UK problem, measures, hold-out and gate nodes rest on the comparisons with the replaced code.

Not in this PR

🤖 Generated with Claude Code

juaristi22 and others added 10 commits November 25, 2026 22:42
microcosm.calibrate.target_sets reads one country's declarations of what
each product calibrates to. For each product and mode, a declaration has
compiled clauses (families, levels, metadata tests, named exclusions, a
named rule) and the rows the tool builds itself, each with a rationale.
select_target_set keeps each clause's specs in compile order, clause by
clause in declaration order. The module holds no country code: a country
passes its named predicates and rules. A target's family and level are the
labels the shared target-loss rule reads (microcosm#1729).

Part of microcosm#1728.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
us/target_sets.json declares the national tool's --target-surface modes and
the ACS local tool's --soi-mode modes. _select_target_surface,
state_admin_surface and soi_surface_predicate now select by it.
us/country_package.json lists the new resource.

On the pinned 41b2fb2 feed every surface keeps the same targets in the same
order (count and TargetRegistry version, measured on main 0f963ac):
national full 31,748 and national_state 6,102; local state 4,380 (4,867 with
the ladder's 487 population rows), totals 255, full 29,977, state_cd 26,425
and state_county 4,380. test_us_target_sets.py pins them, and checks
that every compiled target's level is the one target_geography_level gives.

docs/us-target-sets.md explains the declarations. docs/us-fact-to-target.md
now says that the national and the local product calibrate to different
subsets of the one compiled registry.

Part of microcosm#1728.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The US runtime module classification (test_us_spine_blindness) now lists
`us_runtime/target_sets.py` as a reviewed non-registry module. It names and
loads the declared target sets, selects target specs only, and reads no frame.

Registering `us/target_sets.json` as a `legacy_json` row in
`country_package.json` adds the row's three normative fields: 42407
configuration fields (32621 authored), the `country_manifest` claim at 116
pointers, and a new pointer inventory digest. The row also moves the US
bundle's semantic `spec_sha256` to f130419c, which pool builds record in their
run config's spec binding. No target changes.

Run on the merge of main 268156c, in an environment without country
engines: `tools/repin_us_spec_engine_contracts.py --legacy-only` (no change),
then without it, then `tools/spec_engine_coverage.py`. Both tools' `--check`
modes pass, and coverage reads 42407/42407 fields and 41/41 inventory checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ladder

microcosm#1728 moves the code that builds the local target surface out of
the tools. Each move must leave every target, role and receipt as it was.
TargetRegistry.version sorts metadata keys, so it does not see a change of
key order. Materialize writes target_registry.json and target_roles.json with
the keys in insertion order, and their sha256 is in the run identity.

test_us_acs_local_surface_bytes.py follows the target part of do_materialize
for each non-county --soi-mode: the admin surface, the ladder populations,
the role records, the district pro-rata populations, the ladder population
rows, and the district and county hold-outs. It pins the sha256 of
target_registry.json, of target_roles.json, of the target receipts, and of
the population rows' matrix on a household table that supports every ladder
cell (a release run refuses a cell with no household).

Measured at 3316038 and run twice: state 4,867 targets, totals 742, full
30,464, state_cd 26,912. The tests run only when MICROCOSM_US_CHRONICLE_FACTS
and MICROCOSM_US_PUMA_LADDER_ARTIFACT name the pinned inputs. state_county is
not pinned: it needs the pinned county facts, which are not on this machine,
and a household frame for its support moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C1 of the shared-code work in microcosm#1728. No target changes.

- The ledger filter rules move verbatim from
  tools/build_us_fiscal_refresh_release.py to
  microcosm.build.us_runtime.ledger_filter_rules: 25 names, 446 lines. They
  say how the national irs_soi slice reads a spec's AGI band, filing status
  and EITC child count, and which restated ledger_filter_* keys a spec may
  carry. Each definition is byte-identical. The tool imports all 25 names
  back (its materializer and filter guard call them, and tests and
  tools/bakeoff_us_support_mix.py read them there). It drops the two FSA
  balance-bound imports that only the moved code used, and keeps the two
  age-stamp keys, which a test reads through the tool.
- tools/us_acs_local_cd_surface.py reads the rules from the package, so it
  no longer imports the national tool.
- tools/build_us_acs_local_release.py compiles the registry in one function:
  _compiled_fiscal_registry takes the district crosswalk that
  state_admin_surface also gives the state_cd rule.
- test_us_spine_blindness.py classifies the new module.
- Two tests in test_us_fiscal_refresh_builder.py changed a rule on a freshly
  loaded tool and relied on that copy being thrown away. The rules now live in
  one package module that every load shares, so both use monkeypatch: one
  removes the age rule for its own run only, and one empties the refused EITC
  child-count sides where the comparison reads them.

Proof: test_us_acs_local_surface_bytes.py (the C0 pins) passes unchanged on
the pinned feed and ladder for state, totals, full and state_cd, and the
pinned surfaces of test_us_target_sets.py pass. In all, 3,714 tests
in the 47 files that load the changed tools or hold the module and binding
registers pass locally (8 skipped), with the pinned feed and ladder set.

Left for later commits, as planned: the import cycle between the district
and county modules goes when C3 moves the population rows, and the county
code's use of the argparse namespace moves with the county rung (C5),
because #1719 changes check_support.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The US bundle generator writes country_package.json from
LEGACY_RESOURCE_PATHS. The target_sets.json row was in the committed manifest
but not in the generator, so the engine-tier check
test_generator_reproduces_every_checked_in_bundle_byte failed on
3316038. The generated manifest now equals the committed one (checked
without a country engine), and both re-pin tools' --check modes pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C2 of the shared-code work in microcosm#1728. No target, role or receipt
changes.

- microcosm.build.target_holdouts (new, country-free) draws held-out
  targets by hashed blocks from declared passes: scope and eligibility tests
  on the record, unit fields joined with '|', a concept-family rule, the
  salt, the default and largest fraction, and the receipt keys in order. It
  also builds the training target set, and scores the held rows against a
  pro-rata baseline (the parent target times the child's population share),
  with the populations attached from declared fields.
- us/local_target_construction.json (new) declares the US district and
  county passes, their concept-family rule and their scoring, with the values
  the tools held. microcosm.build.us_runtime.local_target_construction reads
  it.
- tools/us_acs_local_cd_surface.py, tools/us_acs_local_county_surface.py and
  tools/build_us_acs_local_release.py keep their function names and call the
  shared code.
- The new resource row: country_package.json, the bundle generator's
  LEGACY_RESOURCE_PATHS, the US F0 re-pin (42,410 configuration fields,
  country_manifest at 119 pointers; the US bundle spec_sha256 moves to
  c25fbed9), and the module classification.

Proof:
- test_us_acs_local_surface_bytes.py (C0) passes unchanged on the pinned
  feed and ladder: the roles, units, populations and hold-out receipts are
  byte-identical.
- test_us_target_holdouts.py (91 tests) holds the tool functions to
  verbatim copies of the replaced code
  (test_support/microcosm_build/us_target_holdouts_reference.py) on random
  records: roles, receipts, populations, training sets and scores, with key
  order.
- test_target_holdouts.py (30 tests) tests the shared module on a made-up
  country.
- 4,044 tests in the 51 files that load the changed tools or hold the
  registers pass locally (8 skipped), with the pinned feed and ladder set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C3 of the shared-code work in microcosm#1728. No target changes.

- microcosm.build.ladder_population_targets (new, country-free) makes, for
  each declared geography level, the population rows (household size times
  the cell indicator; a household of size zero supports its cell but adds
  nothing), the cells that no household supports, and the target specs with
  their calibration hierarchy. Names, record code fields, geography ids,
  labels, sources and families are declared; a country passes a label lookup
  for each label kind.
- us/local_target_construction.json gains the ladder_population section: the
  state and district levels with the values the tools held.
  microcosm.build.us_runtime.local_target_construction reads it and gives
  the label lookups (Census state names, and congressional_district_label).
- tools/us_acs_local_cd_surface.py (population_rows, population_target_name)
  and tools/build_us_acs_local_release.py (population_targets,
  population_target_specs) keep their names and call the shared code. The
  county population rows and specs stay with the county rung (C5).
- The district module no longer imports the county module: the local tool's
  population_targets picks the county rung's rows for a county run, and the
  district rows refuse a county level.

No spec-engine pin moves: the pins read the resource row, not its content.

Proof:
- test_us_acs_local_surface_bytes.py (C0) and the pinned surfaces of
  test_us_target_sets.py pass unchanged on the pinned feed and ladder.
- test_us_ladder_population.py (54 tests) holds the tool functions to
  verbatim copies of the replaced code
  (test_support/microcosm_build/us_ladder_population_reference.py) on random
  households and ladders: records, matrix rows, dropped cells and specs.
- test_ladder_population_targets.py (13 tests) tests the shared module on
  a made-up country.
- 4,111 tests in the 53 files that load the changed tools or hold the
  registers ran locally with the pinned feed and ladder. All passed (8
  skipped) except one C2 test that checks the file's top-level keys; this
  commit adds the new section to it, and that file passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C6 of the shared-code work in microcosm#1728, with the docs. No target
changes.

- microcosm.build.declared_registers (new, country-free) reads a reviewed
  register from a package JSON file: a description, the key fields (one, or a
  tuple), the value fields (one, a tuple, or none for a set) and the entries
  in order, each with an optional note. JSON arrays read back as tuples, so a
  register reads back as the Python literal it replaces.
- us/fiscal_target_registers.json (new) holds 13 registers of the US fiscal
  target compile, generated from the live objects: the fact exclusions with
  their reasons and vintage scope, the misread source columns, the restamped
  source packages, the SOI variable maps, the direct and indicator Ledger
  targets, and the M-CHIP states. The comments that stood beside them in the
  code are their descriptions and the notes of their entries.
  microcosm.build.us_runtime.fiscal_target_registers names the file.
- us_runtime/fiscal_targets.py and us_runtime/source_vintage.py keep every
  name and read the registers from the file (about 890 lines of literals go).
- The new resource row: country_package.json, the bundle generator's
  LEGACY_RESOURCE_PATHS, the US F0 re-pin (42,413 configuration fields), the
  module classification, and the two modules the transport bindings now reach
  (BINDING_MODULES_ADDED_AFTER_BASE).
- docs/us-target-sets.md describes the declared construction
  (us/local_target_construction.json) and the compile registers, and how to
  change them.

Proof, measured on 904a46d before the move and pinned in
test_us_fiscal_target_registers.py:
- each register's digest (keys, values, Python types and entry order);
- the pinned-feed compile under four flag sets (with and without aging, with
  and without the student-loan targets): count, TargetRegistry.version and
  the sha256 of the full registry JSON;
- the exclusion receipt.
test_declared_registers.py tests the shared reader on made-up registers.
5,599 tests in the 94 files that load the changed tools or the compile, or
hold the registers, ran locally with the pinned feed and ladder. All passed
(46 skipped) except one case of the new register test: it read the
module's dict after another test had reordered it (monkeypatch.delitem
restores a key at the end). The test now reads each fiscal_targets register
fresh from the file and checks the module's content; it passes after those
tests in one process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juaristi22 juaristi22 changed the title Declare each US product's target set as data, with no surface change Declare US target sets, local target construction and compile registers as data (no target change) Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/evidence/spec-engine/us-f0-coverage.json
#	packages/microcosm-build/tests/engine_workflow/us/test_us_multispine_pool_tool.py
juaristi22 and others added 9 commits November 26, 2026 18:32
Two generated pin files conflicted: the US F0 coverage evidence and the
multispine pool tool's spec_sha256. Took main's side of both, then ran
tools/repin_us_spec_engine_contracts.py --legacy-only, the full re-pin and
tools/spec_engine_coverage.py (42,413 of 42,413 configuration fields);
both --check modes pass. The pool tool's pin comment now names this PR's
three declared US resources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Commit C2 moved csr_row_measure from the district tool to the shared
microcosm.build.target_holdouts. The calibration diagnostics name a callable
measure <module>.<qualified name>, so each matrix-row measure is now
microcosm.build.target_holdouts.target_matrix_row[N] instead of
us_acs_local_cd_surface.target_matrix_row[N]. The targets and weights do not
change, but target_surface.sha256 does. María accepted the new name on
26 Nov 2026 (microcosm#1759 plan, decision 1). The new test pins it, and the
changelog says so for anyone who compares two releases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
microcosm.calibrate.target_sets gains what the UK selection needs, as data:

- A declaration can give a level_rule in place of level_keys: the metadata
  keys, a closed set of levels or "*", and whether two keys that disagree
  are refused. level_keys stays the short form of an open rule that takes
  the first key, so the US declarations read as before.
- select_by_levels keeps the targets of a run-time set of levels (all by
  default) in compile order, for a mode with one clause for each level of a
  closed set. It returns them as a registry with the receipt schema
  microcosm.calibrate.target-selection.v1, and refuses a bad request, a
  requested level that no target has, and an empty selection, with the
  texts of microcosm.calibrate.target_selection.

Nothing calls it yet (microcosm#1759, step D1). New shared tests cover the
rule's forms and refusals and the selection and its receipt; the existing
target-set tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UK now declares its target sets the way the US does (microcosm#1759,
step D2):

- uk/target_sets.json (a new legacy_json row in uk/country_package.json)
  declares the UK level rule: a target's level is geography_level or
  ledger_geography_level, the two must agree, and it must be one of
  country, region, constituency, la and brma. It also declares the full
  build's product with one mode, "levels", that has one clause for each
  level.
- uk_runtime/target_sets.py names the file and products.
  graph_targets.target_geography reads the declared rule, and
  uk.full.target_selection@1 calls the shared select_by_levels.
- microcosm.calibrate.target_selection and its tests are removed: the UK
  kernel was the only caller.
- The full-graph target kernels hash the shared and UK target-set modules
  in place of target_selection. The national kernels now hash them too:
  the national problem writes each row's level, and it now reads the level
  through the UK adapter, not through graph_targets, which those kernels
  never hashed.

No selection changes. test_uk_level_selection.py compares the new code with
verbatim copies of the removed selector and UK resolver
(test_support/microcosm_build/target_selection_reference.py) on 400 random
registries and requests: the same registry version, the same receipt bytes,
or the same refusal type and text. The new resource is in the UK solve
fingerprint, so the first UK build after this change computes the spine
from frs_brma on, the target nodes and the national graph again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two UK calibration lines (microcosm#1301) become the modes of a
calibration_line product in uk/target_sets.json (microcosm#1759, step D3):

- Each mode has one clause that keeps every compiled national reference
  except the ones the predicate off_calibration_line names.
- uk_runtime.ledger_targets.uk_registry_on_calibration_line selects through
  the declared mode with the shared select_target_set. It binds that
  predicate to the contract targets whose calibration_lines leave the line
  out. The membership stays with each target in
  uk/uk_population_targets.json.
- UK_CALIBRATION_LINES is the product's declared modes.
- The shared selector reads a target's level only when an active clause
  tests levels, so the closed UK level rule does not refuse rows that a line
  selection never places by level. The US declarations are open rules, so
  their results do not change.
- ledger_targets now imports the shared and UK target-set modules, so both
  join UK_TARGET_COMPILE_MODULE_NAMES.

No line changes. test_uk_calibration_line_selection.py holds the new
function to a verbatim copy of the old one
(test_support/microcosm_build/calibration_line_reference.py). It covers 150
random registries on each line and an unknown line: the same registry (the
same object when nothing drops), the same receipt, or the same refusal. The
existing line, CenTax and measurement-period tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e US

The UK rowwise hold-out and the US local hold-out keep their own draws:
rotated folds over the UK's local target rows, and hashed blocks over US
units. They now share the two steps after the draw (microcosm#1759, step
D4):

- microcosm.build.holdout.HoldoutSplit names a split's training rows and
  held rows. fold_splits makes one for each rotated fold, and
  target_holdouts.role_split makes one from the US roles.
- microcosm.build.holdout.held_estimates gives the held rows' estimates
  from the target matrix and the solved weights, in float64.
  rotated_uk_local_holdout (with the size stage's record columns) and
  target_holdouts.score_holdout both call it.
- The UK hold-out node (uk.full.rotated-holdout@1) now also hashes
  microcosm.build.holdout. It already ran rotated_folds from that module
  without hashing it.

No result changes. test_holdout.py compares fold_splits with the old
rotated_folds and setdiff1d code. It also compares held_estimates with
the replaced UK and US expressions on random float64 and float32 data,
byte for byte. The 91 US hold-out tests still match the verbatim copies
of the old tool code, and the UK hold-out, candidate-scorer and graph
tests pass unchanged. The UK fold constants stay in local_rowwise.py,
as María ruled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
microcosm.build.declared_registers gains what every signed register file
needs, for any country (microcosm#1759, step D5):

- read_strict_json reads JSON and refuses duplicate keys, non-finite
  numbers and malformed text, with the texts the UK reviewed-exclusion
  reader uses;
- canonical_date reads a date only as YYYY-MM-DD (date.fromisoformat
  also accepts the compact and week-date forms);
- ReviewWindow is an entry's window, approved_on to expires_on with both
  days in force, and gives its state on a date and the days left;
- stale_entries gives the declared entries that name nothing found.

They return values; the country's code keeps its error texts and decides
what a lapse does. No code calls them yet. The new shared tests cover each
function; the US register tests and spec-engine checks pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UK compile-side loaders of signed entries now use the shared review
core (microcosm#1759, step D6):

- measure_simulation.load_uk_calibration_measure_exclusions reads each
  approval and expiry with canonical_date.
- apply_uk_calibration_measure_exclusions checks each window and its
  seven-day warning with ReviewWindow, and finds stale entries with
  stale_entries.
- support_floor.uk_support_floor_from_payload reads the floor's dates with
  canonical_date, and UKSupportFloor.assert_in_force uses ReviewWindow.

Each function keeps its texts, its order and its policy. The full-graph
target kernels and the national kernels now also hash declared_registers,
which these modules import (test_uk_target_compile_modules found the new
import).

No change in results, warnings or refusals. test_uk_review_loaders.py holds
the new code to verbatim copies of the old functions
(test_support/microcosm_build/uk_review_loaders_reference.py) on the
packaged file, on 13 changed copies and on the days around each window edge
(34 refusals and 34 warnings among the cases). The existing exclusion,
support-floor and full-target tests pass unchanged.

The small-cell deferrals (ledger_targets.assert_uk_local_deferrals_in_force)
keep their own expiry check: it parses with date.fromisoformat, so it also
accepts compact dates, and moving it would change what it accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UK reviewed-exclusion registers (target fit, local target fit and area
support) now use the shared review core (microcosm#1759, step D7):

- weighted_integrity._read_register_payload reads with read_strict_json,
  which keeps its texts for duplicate keys, non-finite numbers and
  malformed JSON. The "must be a JSON object" check stays with the UK.
- UKReviewedExclusion reads approved_on and expires_on with
  canonical_date, with the same message. Its new window() gives the
  ReviewWindow, and expired and premature read it.
- The national gate kernel and uk.full gate kernels, which hash
  weighted_integrity, now also hash declared_registers.

Every public name stays where battery_bindings and the tools import it.
battery_bindings, gate_battery, stage_health and graph_evidence are not
changed.

No change in what these registers read, accept or refuse.
test_uk_reviewed_exclusions_core.py holds the new code to verbatim copies of
the old reader, date checks and window methods
(test_support/microcosm_build/uk_reviewed_exclusion_reference.py) on the
three packaged files, on ten changed texts, on ten date pairs and on the
days around every packaged entry's window. The existing weighted-integrity,
terminal-gate, battery-binding, graph and CLI tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
juaristi22 and others added 2 commits November 26, 2026 20:34
The digests were measured at 38dbd01, before the UK selection moved to the
shared target sets: the full surface, the selection for 19 parameter sets
(13 selections, 6 refusals) and the national registry, on the pinned Chronicle
feed and the 2021 output-area ladder, at calibration year 2025 and review date
2026-11-26.

The tests run when MICROCOSM_UK_CHRONICLE_FACTS and MICROCOSM_UK_OA_LADDER are
set. The selection tests can read a saved surface (MICROCOSM_UK_TARGET_SURFACE)
that has the pinned digest.

Part of microcosm#1759.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/uk-target-sets.md describes the UK declaration (the level rule, the full
build's selection by level and the calibration lines), the shared hold-out
split, the signed entries on the shared review core, what stays UK code and
what a UK build computes again. The US page and uk/target_sets.json link to it.

Part of microcosm#1759.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juaristi22 juaristi22 changed the title Declare US target sets, local target construction and compile registers as data (no target change) Declare target sets and target registers as data, with shared code for the US and the UK (no target change) Nov 27, 2026
juaristi22 and others added 3 commits November 27, 2026 10:10
The review of microcosm#1755 found that three readers took a repeated JSON
key without a word: plain json.loads keeps the last one, so a second mode or
register of one name replaced the first. The target-set reader, the declared
registers and the US local target construction now refuse a repeated key and
a non-finite number. A version must be the integer 1 (True passed before),
and a list of clause names refuses "*", which would match only a name "*".

The packaged files already pass, so no selection or register changes.

Part of microcosm#1728.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The review of microcosm#1755 found that the shared code wrote generic
refusal texts, and that the tests compared only the error class.

- A pass's scoring declares child_label and parent_label, and a ladder level
  declares code_name. With them the pro-rata baseline refusals and the
  ladder's state-code refusal have the replaced texts again.
- assign_holdout_roles refuses None for the fraction and the salt. Only an
  omitted argument draws with the declared value, so a caller that forwards
  an unset option cannot hold targets out silently.
- The US tests compare each refusal's class and text with the replaced code.

Three cases still differ from the replaced code, because one shared check now
serves both passes: the county fraction refusal also names the value, the
district pass checks its salt before it reads a record, and the county scorer
reads role on every record. The tests pin them. No run of the tool reaches
them: the command line checks fractions and salts first, and the district
pass gives every record a role.

No target, role or receipt changes.

Part of microcosm#1728.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The shared strict reader raises DeclaredRegisterError, a ValueError subclass.
A gate that fails closed records the class name of the error in its report,
so a malformed register gave a different report than before (the review of
microcosm#1755). The UK reader raises a plain ValueError with the same text
again. The UK loader tests now compare the error class as well as the text.

Part of microcosm#1759.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
juaristi22 and others added 5 commits November 27, 2026 10:10
uk.full.rotated-holdout@1 rebuilds the problem inputs, so it runs the
declared level rule (microcosm.calibrate.target_sets through the UK adapter)
and the review core (microcosm.build.declared_registers). It hashed neither
(the review of microcosm#1755). No stale result was possible, because a node
key chains through its producers' keys, but the kernel now hashes what it
runs.

test_uk_graph_terminal.py pins these entries, the shared hold-out module,
and the review core in each gate kernel's hash. No test pinned them before.

Part of microcosm#1759.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Corrections from the review of microcosm#1755. They change texts and add one
test; no code path changes.

- held_estimates multiplies in float64. It gives the bytes of the replaced UK
  expression for a float64 matrix, which the UK problem matrix always is. A
  new test pins the float32 case, where the two differ.
- The SOI clause of the local state and state_county modes reads a row's
  level as ledger_geography_level, else geography_level. The replaced filter
  read only ledger_geography_level. Every compiled row carries it.
- The byte pins of test_us_acs_local_surface_bytes.py were measured after the
  declared selection replaced the selection code, so they hold the later
  moves only.
- docs/us-target-sets.md lists the refusals that keep their texts and the
  three that differ. docs/uk-target-sets.md states the hold-out kernel's
  hash and the reader's error class.

Part of microcosm#1728 and microcosm#1759.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
fiscal_target_registers.json was listed before fiscal_target_references.json,
the one row of the 28 US JSON resources out of order (the review of
microcosm#1755). The package list and the generator's list now agree on the
sorted order. Both --check modes of the re-pin tools pass with no pin
changed, so the order moves no spec-engine pin.

Part of microcosm#1728.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main brings the renewed UK register entries (the clock tests of the
engine-free job pass again), the UK feed pin e4d46c93 and the LCFS work of
microcosm#1736. No file conflicted. Both --check modes of the US re-pin
tools pass with no pin changed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The digests of test_uk_target_surface_pins.py hold Chronicle feed 15040ea5,
the UK input files of 38dbd01 and review date 2026-11-26. Every pin passed
at 9130ebe, after the move to shared code: that is the proof of the move.

Main has re-pinned the UK feed to e4d46c93 and renewed register entries with
approval date 2026-11-27 (microcosm#1736). So the surface is different now,
and the renewed entries are not in force on the old review date. The tests
now skip, with the reason, while the package pins another feed than
PINNED_FEED_COMMIT. To use them again, measure the surface, the selections
and the national registry on the new feed, and set the feed commit, the
review date and the digests together.

Part of microcosm#1759.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@anth-volk

Copy link
Copy Markdown
Contributor

Review: three suggestions on the target-set declarations

The shared selector and the US declarations select what main selects. A comparison of main's local filters with this branch's, on 2,100 combinations of metadata values, differed only in the cases the description lists under "Differences on other feeds". The three suggestions below are about the declaration format and the UK cache key.

1. Use the UK's level_rule form for the US as well

The two countries share one file layout and one loader, but read a target's level in two ways:

  • US: level_keys (b56bdaa5a). The level is the first non-empty of ledger_geography_level and geography_level, and any value is accepted. A target with neither field gets "unspecified".
  • UK: level_rule (e9317a3bb). Both fields must agree when both are set, and the level must be one of five values; anything else is refused. level_keys stayed as a short form "so the US declarations read as before".

Suggestion: give us/target_sets.json a level_rule, and remove level_keys from the loader:

"level_rule": {
  "keys": ["ledger_geography_level", "geography_level"],
  "values": ["country", "state", "congressional_district", "county"],
  "conflict": "refuse",
  "rationale": "..."
}
  • Readers that would use the declared rule: target_level, target_set_census, undeclared_cells, and us_runtime.target_loss_weights.target_geography_level. That last one repeats the first-non-empty reading in its own code today.
  • What a US build would refuse: a target with a level outside the four values, or with the two fields disagreeing. Today such a target becomes "unspecified" or takes the first field.
  • What needs confirming on the pinned feed: test_pinned_feed_levels_are_the_target_loss_levels already shows the compiled levels are country, state and congressional_district. Could you also check that no compiled US target sets both fields to different values? Those checks need the feed, so they couldn't be run here.

2. US local: rows dropped for their level leave no record

Example: the local/state declaration, run on three compiled rows (a state SNAP row, a county SNAP row and a state SOI row):

kept:          ['snap_state_06', 'soi_state_06']
clause_counts: {'snap': 1, 'medicaid': 0, 'soi': 1}
rule_receipts: {}
undeclared cells of the compiled input: {('usda_snap', 'county'): 1}
  • The county row is dropped. The selection result only counts the rows it kept, so nothing written records the dropped one.
  • Main kept that row without notice; this branch drops it without notice. Main's filter kept every row that has state_fips.
  • Where it can happen: only the local product. The national modes use "*" for levels. A closed level_rule refuses an unknown level, but county is an allowed US level, so suggestion 1 does not catch this.
  • The pinned test can't catch it either. test_pinned_feed_local_surfaces_are_unchanged asserts undeclared_cells(declaration, specs) == {} on the rows the selection kept. A kept row always matches a clause, so that assertion cannot fail because of a dropped row.

Suggestion:

  • In select_target_set, count the rows each clause accepts by family but rejects by level, grouped by (family, level), and return those counts with the selection.
  • In state_admin_surface, refuse to run when any count is not zero, unless the clause names that level as deliberately left out, with a reason. For example: "left_out_levels": {"county": "<reason>"}.
  • Write the counts into the SOI receipt.

On the pinned feed every count is zero, so no target changes. After a feed re-pin, rows at a new level stop the run with their family and level named, and keeping or leaving them out becomes a reviewed edit to the JSON.

3. UK cache key: hash the parsed content of uk/target_sets.json, not its bytes

uk_solve_fingerprint() combines the SHA-256 of each packaged UK file's bytes. Adding three words to one clause's rationale changes it:

solve fingerprint before: 9fbccfb681cc1d1a
solve fingerprint after:  264a9440033d84bc

These steps key on that fingerprint:

  • the validation check that runs on the household data once frs_brma has assigned each household a Broad Rental Market Area;
  • every household-data step after that check, since each one waits on its result;
  • target compilation and selection;
  • the solve;
  • the national build.

Most of this file is prose. A UK local release's second build, after sign-off, is meant to reuse the first build's solve. A rationale edit merged between the two builds would force a re-solve with no change in output.

Suggestion: keep the file in the fingerprint and keep it as JSON, but key the solve on its content without the prose. The spec engine already does this for the bundles:

  • Add a target_sets.schema.json that marks description and every rationale with x-spec-surface: documentation.
  • Read the file with spec_engine.yaml12.load_json_strict. That also gives the duplicate-key and non-finite-number refusals that _read_declaration_file adds by hand.
  • spec_engine.canonical.normalize_and_project splits out the documentation. The solve fingerprint hashes the remaining content for this file, and the release manifests keep the byte hash, so provenance still names the exact file.
  • Extend test_uk_solve_scope.py: changing a clause, level or exclusion must change every key that reads the file; changing a description or rationale, or reformatting the file, must change none of them.

country_spec hashes every resource's bytes today, and this file is a plain legacy_json resource. So the resource row would name the new schema, and country_spec would hash the content without the prose for the solve fingerprint. The projection hasn't been tried on this file yet.

The alternative of leaving the file out of the solve fingerprint, with each reading step adding its own hash, is weaker: correctness would depend on every reader remembering that hash, and a missed reader would reuse stale results.

juaristi22 added a commit that referenced this pull request Nov 27, 2026
…'s keys and receipts

Step 2 of microcosm#1760 (docs/us-target-nesting-rule-design.md, section
5.5), on María's go of 27 Nov 2026. No target value changes: on the pinned
feed and ladder each of the 26,272 rows of the state_cd SOI surface has the
bits of the value it had, and the full, state and totals surfaces have the
bytes they had.

What is general now, and where:

- cross_grain_controls holds one row-level pass, reconcile_rows: it runs
  the operator on target rows and says, for each row, its value, what
  reconciled it, the factor, and the control row. The helpers that only the
  US used (factor band, completeness, self-consistency, sibling ratio) are
  gone: the operator's bound, members and selectors do that work.
- us/cross_grain_declarations.json is in the UK's key names:
  bridge_selectors (Historic Table 2 state rows over district-file rows,
  with the bound +0.25 / -0.20 around the median and unbind; state SOI rows
  over county-file rows), derived_controls (county households),
  same_measurement (the ladder population), relations (six subset pairs,
  Medicaid with max_excess), local_routes, members, registers. What goes at
  the feed re-pin is under until_the_feed_repin: the allocators, the level
  bridges of the six district-only concepts, the compile rules of rows 1
  to 4 and two known gaps. The keys mechanisms and inventory are gone.
- us_runtime/target_nesting.py runs each of the four passes through one
  function, run_pass.

What changes by design:

- Metadata keys: cross_grain_parent, cross_grain_value_before,
  cross_grain_factor, cross_grain_control and cross_grain_members replace
  the state_cd_* and state_county_* keys. Six old keys have no new one:
  the parent row, the operator's receipt or the declaration holds the value.
- Receipts: the district receipt has bridge (with the unbound legs),
  level_bridge_out_of_band and factor_by_measure. factor_band,
  rebase_factor_by_measure and internal_consistency are gone. County blocks
  lose share_sum. target_nesting.json entries are pass, allocator and the
  operator's receipt.
- So three pins of state_cd move (registry, roles, receipts). The target
  count and the population matrix are the same.
- A refusal that the operator makes has the operator's text.
- The check that the district file's own state row is the sum of its
  district rows is gone. Row 4 of the compile scales the district rows to
  that state row before this pass (22,236 district rows carry its marker on
  the pinned feed; the 436 that do not are never bound).
- A concept that takes its state parent from Historic Table 2 in some
  states and from the district file in others is refused. It does not occur
  on the pinned feed.
- With the bound turned off (tests only), a concept whose Historic Table 2
  level is zero in every state keeps district rows of zero.

The readers of the keys move with them: the loss weights, the hold-outs and
their pro-rata baselines, the county reports, and one field of the reviewed
limitations. The dated runs under experiments/ are not changed.

Proof: test_us_target_nesting_district.py and test_us_target_nesting_county.py
hold the tool functions to verbatim copies of the code they replace (160 and
120 seeded inputs, and the pinned feed): the same rows in the same order, the
same value bits, the same parent, factor, value before and members under the
new keys, the same counts, drops and summaries. Both US pin tools ran and
wrote no file; --check passes.

PR #1755 declares the old parent keys in us/local_target_construction.json
and pins the state_cd registry bytes. The PR that merges second takes the
other's change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
juaristi22 added a commit that referenced this pull request Nov 27, 2026
Ruled on 27 Nov 2026, after steps 1 and 2 of microcosm#1760 were written:
no allocator after the re-pin; one parent source for a concept; the
district file's self-consistency check stays out; the county rows are
compared and pinned on the pinned county facts file now; the merge waits for
a gap between UK releases; PR #1755 merges first; the rulings go on the
issue after the text is approved; Medicaid stays a subset with a declared
excess; the full surface and district capital gains nest in the Historic
Table 2 state row at step 3; decisions 4 and 7 go in their own PRs.

Docs only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
juaristi22 and others added 5 commits November 27, 2026 16:51
From the review of microcosm#1755 (suggestions 1 and 2).

One form for the level rule. us/target_sets.json now declares a
level_rule, as the UK file does: the first of ledger_geography_level and
geography_level that has a value, any level accepted. The shared reader
loses the short level_keys form and target_level; target_set_census
takes the rule. us_runtime.target_loss_weights.target_geography_level
reads the declared rule in place of its own copy of that reading. A test
holds it to a verbatim copy of the replaced code. On the pinned feed all
31,748 compiled targets set ledger_geography_level only, so no compiled
target sets both level fields; a test pins that.

A record of the rows left out by level. select_target_set counts, by
family and level, the targets that an active clause names by family and
that no such clause keeps at their level (left_out_by_level). The ACS
local tool writes the counts in materialize_rss.json under
target_levels_left_out, beside the SOI receipt, whose pinned bytes are
equal. The assertion that could not fail (undeclared_cells on the kept
rows) is replaced by a pin of the counts for each local mode: the
country rows of the three families in every mode, and the district SOI
rows in state and state_county.

No target, order or pinned receipt changes. The US rule stays open: a
closed rule and a refusal of an undeclared level add run-time refusals
to a US build, and they are not in this commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
From the review of microcosm#1755 (suggestion 3).

The declared target sets decide what a build calibrates to, and most of
each file is prose: a description for each mode and a rationale for each
clause. They were legacy_json resources, the kind for files from before
the spec engine. The bundle gives that kind no semantic content, so the
bundle's spec_sha256 did not cover a clause, and the UK solve keyed on
the file's bytes: a reworded rationale merged between the two builds of
a local release would force the second build to solve again
(microcosm#1301).

The spec engine already separates a typed resource's normative content
from its documentation. So the target sets become a typed resource:

- A new resource kind, target_sets, with target_sets.schema.json, the
  sixteenth schema of the catalog. Each description and rationale is
  documentation; every other field is normative.
- us/target_sets.json and uk/target_sets.json become
  us/spec/target_sets.yaml and uk/spec/target_sets.yaml. The products
  and the modes are lists with an id, so their declared order is content
  (two UK refusals list the calibration lines in that order); the order
  of the fields of an object is not content.
- microcosm.calibrate.target_sets takes the object the spec engine
  parsed. Its own file reader is removed. The country modules read
  through country_spec.load_country_target_sets, which loads the one
  resource as the bundle loader does.
- The country spec records, for each typed resource, the sha256 of its
  normative projection (ResolvedCountrySpec.content_hashes).
  fingerprint_excluding takes that hash for the resources named in
  by_content, and the UK solve fingerprint names its target sets there.
  The calibrated gates and the release manifests keep the byte hash.

The US typed files are generated from the constants-era code. That code
never held the target sets, so the US file is written by hand: the
generator declares its manifest row (AUTHORED_DOMAIN_KINDS) and does not
write it. The F0 field ledger has a reviewed claim for the domain, a
front-end validation with its own verifier: the release tools read the
typed domain themselves, so it does not pass through the constants
adapter. The US pins move to 42,557 configuration fields and a new
spec_sha256, which now covers the declared clauses.

No target, order or receipt changes. The pinned US surfaces, censuses
and receipt bytes hold on the pinned feed, and the UK selection and
calibration-line tests still match the verbatim copies of the replaced
code. test_uk_solve_scope.py edits the packaged file both ways: a
reworded description or rationale, another layout or another order of a
set of names re-keys no solve kernel; a new level, a changed clause
level or family, a removed exclusion, or another order of the clauses or
the modes re-keys every solve kernel.

The UK solve fingerprint has a new value, so the first UK build after
this change computes the solve-scoped nodes again, with the same
outputs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two generated pin files conflicted, as in the earlier merges: the US F0
coverage evidence and the spec_sha256 pin of the multispine pool test.
The re-pin tools regenerated both for the merged tree (42,557 of 42,557
configuration fields, 41 of 41 inventory checks). Main raised
microcosm-emitter-interface to 0.18.0; no other file needed a change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The country spec now checks a package's declared target sets with the
shared reader when it loads the bundle, and the US field ledger does the
same for its target_sets claim. So the gate bindings' source closure
reaches microcosm.calibrate.target_sets, one module more than the
reviewed list of test_transport_evidence_kernels.py. The module joins
that list.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The country spec's loader now checks a bundle's declared target sets with
microcosm.calibrate.target_sets (microcosm#1728). country_spec is a listed
transport compile module, so the closure test needs each of its first-party
imports listed or excluded with a reason.

Target compilation calls only the reference validators of country_spec.
They do not read the reader, and a target set selects among the targets
after the compile. So the reader joins EXCLUDED_DIRECT_IMPORTS with that
reason, like the other imports of the loader. No compile kernel hashes the
list module, so no node key changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@juaristi22

Copy link
Copy Markdown
Collaborator Author

Thank you for the review. All three points led to a change on this branch. Two refusals from points 1 and 2 wait for María's decision.

1. One form for the level rule: done (36d976c7b)

  • The US file now declares a level_rule. The loader has no level_keys form, and target_level is removed.
  • us_runtime.target_loss_weights.target_geography_level reads the declared rule. A test holds it to a verbatim copy of the code it replaced.
  • Your check on the pinned feed (41b2fb2): all 31,748 compiled targets set ledger_geography_level and not geography_level. So no compiled target sets both fields. The levels are country, state and congressional_district. test_pinned_feed_levels_are_the_target_loss_levels now pins this.
  • Not done yet: the US rule is open (values: "*", conflict: first), which is the reading the code had. The closed rule (four values, refuse a conflict) adds a refusal to a US build at run time. It also changes the loss weights' reader, where a row with no level has the level unspecified today. María decides this.

2. Rows dropped for their level: the record is done (36d976c7b), with one correction

The counts are not zero on the pinned feed. Main's state SOI filter tested the level in code, and no local mode keeps a country row:

Family Level Rows Left out by
usda_snap country 2 every local mode
cms_medicaid country 3 every local mode
irs_soi country 441 every local mode
irs_soi congressional_district 22,996 state and state_county
  • select_target_set now returns left_out_by_level: the targets that an active clause names by family and that no such clause keeps at their level, by (family, level).
  • The local tool writes the counts in materialize_rss.json under target_levels_left_out. They are beside the SOI receipt, not in it, for two reasons: the pinned receipt bytes stay equal, and the counts cover SNAP and Medicaid too.
  • You were right about the pinned test: undeclared_cells on the kept rows could not fail. It is replaced by a pin of the table above for each mode. The case of your example (a county row of a family whose clause keeps the state level) is a shared test, test_a_selection_counts_the_specs_it_leaves_out_by_level.
  • Not done yet: the refusal. The design that fits the table is left_out_levels on a clause (level → reason), with a refusal of any other level of the clause's families. It is a second run-time refusal in a US build, so it waits for the same decision.

3. UK cache key: done by the schema route (8fd3e88e9)

The declared target sets are now a typed resource of the spec engine, as you proposed.

  • Kind and schema. A new kind target_sets with target_sets.schema.json (the sixteenth schema of the catalog). Each description and rationale is x-spec-surface: documentation; every other field is normative.
  • Files. us/spec/target_sets.yaml and uk/spec/target_sets.yaml. A typed resource must be YAML by the loader's rule, so the engine's strict YAML 1.2 reader reads them, and _read_declaration_file is gone from the shared reader.
  • The key. ResolvedCountrySpec.content_hashes holds the sha256 of each typed resource's normative projection, from normalize_and_project. fingerprint_excluding(..., by_content=...) takes it, and uk_solve_fingerprint() names spec/target_sets.yaml. The byte hash stays in resource_hashes, in the full fingerprint and in the release manifests.
  • A side effect that I think is the main gain. As legacy_json the files had no semantic content in the bundle, so a changed US clause moved no pin. The bundle's spec_sha256 now covers the clauses.
  • Tests, as you listed. test_uk_solve_scope.py edits the packaged file both ways. A reworded description or rationale, another layout (JSON in place of block YAML, fields in reverse order) or another order of a set of names re-keys no solve kernel. A new level, a changed clause level or family, a removed exclusion, or another order of the clauses or of the modes re-keys every solve kernel.

Three things differ from your sketch, and I would like your view on the last one:

  1. Products and modes are lists with an id. The engine sorts the keys of an object, and the order of the UK calibration lines is content: two refusals list them in that order. So an ordered thing must be a list.
  2. The country modules read through a narrow loader, country_spec.load_country_target_sets. It loads the one resource as the bundle loader does (parse, schema, defaults, normalize), in the way load_country_take_up_contract_projection does for take-up. UK modules read the calibration lines at import, and a full bundle load there costs too much.
  3. The US file is written by hand in a generated bundle. The constants-era code never held the target sets, so generate_us_bundle_from_constants.py only declares the manifest row (AUTHORED_DOMAIN_KINDS). The F0 field ledger has a new claim, target_sets: FRONT_END_VALIDATION with NO_GENERATION0_EFFECT, and a verifier that checks the domain against the schema and the shared reader. The release tools read the typed domain themselves, so it does not pass through the constants adapter. No claim in the ledger is like it yet. Is that the right classification, or do you want an adapter surface for it?

The US pins move: 42,557 configuration fields (32,771 authored) and a new spec_sha256. Every CI job passes on 5eac92f5f, the US engine jobs among them. Two reviewed module lists needed the shared reader, because the country spec now checks the declared target sets when it loads a bundle: the gate battery's binding identity (884f1eb53) and the exclusions of the transport compile list (5eac92f5f).

Not in this PR: us/local_target_construction.json and us/fiscal_target_registers.json are still legacy_json, and the other typed UK resources still enter the solve fingerprint by their bytes.

Drafted with AI assistance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants