Skip to content

Distinguish location clones in Route A copy checks - #1814

Draft
MaxGhenis wants to merge 16 commits into
mainfrom
us-location-clone-copy-checks-on-main
Draft

MaxGhenis wants to merge 16 commits into
mainfrom
us-location-clone-copy-checks-on-main

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

WIP, handed to the Microcosm hub. A P1 was still open after review round 4. Nobody merges this PR while that P1 is open (hand-off comment).

When a build makes K > 1 location clones of a household, block_location.clone_frame_for_location gives the K copies of a support row the same source ID and support clone index. Route A's copy checks then reject those copies as duplicates. These commits let the checks tell the copies apart:

  • support_provenance names the location clone index once, and block_location spells its column through that helper. A table that no build location-cloned reads as index 0.
  • SIPP Head Start, voluntary filing, SSI take-up, the PUF capital gains tail and warm-start selection add the index to their copy keys.
  • outer_stage_runtime adds the index to the outer-stage identity digest. A frame without the column (K = 1) keeps its digest.
  • The legacy ACS multispine base tool refuses a donor base that records more than one location clone.
  • microcosm-data registers the six {entity}_location_clone_index columns as stored build lineage.
  • On a base with location clones, the tail check also refuses a donor whose copies name different recipients, a tail row that names none, and a donor with fewer copies than the base's largest location clone index implies.
  • build_us_fiscal_refresh_release.py and its preflight refuse a located --base-h5, other than a stacked pool, when the largest location clone index on a non-empty entity table differs from K − 1. They read K from the H5 attribute populace_location_clones.
  • PUF support expansion refuses a frame that already has location clones.

All three build lines still refuse K > 1: tools/build_us_puf_support_base.py, the stacked pool (tools/build_us_multispine_pool.py) and the ACS local-release line. docs/us-location-v1.md lists what still blocks K > 1 on each.

Receipts. The six register entries change the stored-input register's SHA-256. The recertification verifier (compatibility_recertification.py) and the source-enrichment verifier (source_enrichment.py) compare each receipt's value with the current register's. Anyone replaying a receipt made before this PR merges has to regenerate it first.

Pins. The US seed-protocol and F0 pins still hold main's values. CI fails at the first stale one, and --maxfail=1 hides every failure after it, so CI at this head says nothing about the tests below. Derive the pins once, on the final head. #1676 and this PR overlap on some pins and on puf_support.py, so whoever lands second derives the pins again.

Tests. A Codex cloud task ran 13 engine-free files on an earlier base (main 1d8b9b8dd6, tree e7cfc21d): 491 passed and one skipped. Nobody has run a pytest test on any of the ten commits after 063040ef17, so nobody has run one at this head.

🤖 Generated with Claude Code

MaxGhenis and others added 12 commits September 30, 2026 11:34
Add location_clone_index_column and location_clone_index_series to
support_provenance, the owner of every {entity}_* provenance column, and
spell block_location's clone column through it. A table that was never
location-cloned (K = 1) reads as index 0, so a copy key of (source ID,
support clone index, location clone index) reduces to today's pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With K > 1 location clones, block_location.clone_frame_for_location
repeats each unit K times and marks each copy with an
{entity}_location_clone_index column, so K copies of one support row
share their source ID and support clone index. Add that index to the
copy keys in the Route A consumer checks (SIPP Head Start, voluntary
filing, SSI take-up, the PUF capital gains tail and warm-start
selection), register the six columns as stored build lineage, and add
assert_location_clone_expansion to the outer stage runtime. Tables never
location-cloned read index 0, so their keys reduce to today's pair. The
ACS local-release line still refuses location_clones > 1, because it
keeps each donor's block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PUF support expansion copies each row's current ID into its source ID, so
on a located frame every location copy would become its own source unit.
Refuse such a frame where the expansion checks its metadata columns.

Drop assert_location_clone_expansion, which no stage calls and no test
covers, and its branch in assert_clone_expansion. Keep the location clone
index in the frame identity, with a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a location-cloned base, a capital-gains tail donor counts as present
when the base holds each of its K location copies, all copies carry the
same recipient source ID, and the selected frame keeps that recipient.
Before, a base missing a copy passed against itself, and a donor whose
copies sat on two recipients passed as one donor. K = 1 reads no new
column and returns the same receipt.

Move the property test and its scenarios to
test_us_puf_capital_gains_tail_location_properties.py, so the rest of the
tail tests run without Hypothesis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Household weights between 1 and 2 split w/K inexactly, so a gate that
compares weighted shares with its threshold could pass at K = 1 and fail
at K = 3 or 4 on the same decisions. Weights of 48 times the household
number divide exactly by every support, tail and location copy in the
property, so the check compares equal floats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The base-h5 tool refused K > 1 by naming four copy checks that now key on
the location clone index. Name the parts that still count or draw by row:
the household_location_assignment stage, the tail-concentration gate, and
stages that draw per row or per a remapped ID. docs/us-location-v1.md
lists every remaining blocker, and the other refusals and docs follow.

The legacy ACS tool now refuses a block_v1 base that records more than
one location clone, since pooling keeps each donor's block. The preflight
counts donors, rather than location copies, in its summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A located frame whose source lacks its lowest support copy at location 0
must still take its predictors from the lowest remaining support rank. A
warm-start base must hold every location copy: one without an identity's
last copy, or with every identity lacking copy 1, is refused at K = 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release builder returns retirement distributions unchanged, and it
redraws childcare and energy subsidy only when the base carries their
ASEC source columns. The old sentence listed all three.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tail survival check refuses an applied row whose source ID is missing, on
the base and on the frozen support. PUF support expansion checks for location
clones before it chooses a branch. The legacy ACS tool tells the caller to
rebuild a located donor base with one location clone.

The docs and the changelog say that the warm-start and tail checks read K from
the largest location clone index, what K copies do to the top-100 share, when
the QRF stages draw per row, and which columns a voluntary-filing frame must
lose before it draws per row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 raised three P1s. This commit answers them.

R1: the warm-start and capital-gains-tail checks read K from the largest
location clone index, so a base in which no unit has its highest copy passed
both as K - 1. `h5_io.require_declared_location_clones` compares that index on
every entity table with the H5 attribute `populace_location_clones`.
`build_us_fiscal_refresh_release.py` calls it right after it loads the base
and before the tail check, bound to the digest of the bytes it read, and the
preflight calls it where it loads a base that isn't a pool. The generic
loaders don't call it: they also read selections, exports and reference files,
which can lack copies. A frame with no location column returns before the file
is opened, so K = 1 does no new reads.

A1: the six register entries move the register's SHA-256 on every receipt,
K = 1 included. `register_sha256` exists to make a register change visible
when a receipt is replayed, so this keeps the digest over the whole register
(b563fbb added the four student-loan entries the same way). The K = 1
golden test also requires the reading to carry the current register's digest,
and the changelog says which receipts need a new run.

A2: the warm-start docstring claimed the same messages on any frame with no
location column. It names the exception: a requested key that names
`household_location_clone_index` is refused for having no copies to choose
among.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Text and one test, with no change to what any code does (review round 2).

- The base-h5 refusal and the docs say how location copies rank for the
  top-100 tail share, and that the cutoff can split a record's copies (R3).
- The base-h5 refusal says the QRF stages draw per row when they impute, and
  that education debt needs --scf-education-debt (R4).
- The PUF expansion refusal gives a reason that holds on both expansion
  paths; one of them keeps source IDs (R7).
- The Head Start and voluntary-filing docstrings name the lowest surviving
  location clone, and the changelog and docs limit the copy-key claim to the
  code that validates those keys (E1).
- The outer-stage identity test moves one entity's index at a time (D2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_main_writes_diagnostics_before_post_calibration_gate_failure returns a
fake frame without `entities` from its base loader, so the declared-K check
would raise AttributeError before the gates under test. The stub asserts the
path and digest the builder passes and leaves the fake frame unchanged.

Two declared-K tests now fail on the faults they name: the replacement test
swaps the file as the check opens it, and the byte-string case stores
fixed-width bytes, which h5py returns undecoded. The release-build test also
pins the tail check as the next statement.

The helper, its test module, the tail comment, the warm-start docstring, the
docs and the changelog say what the check compares: the largest index on each
non-empty entity table of a base H5 that isn't a stacked pool.

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

MaxGhenis commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

The independent review has used its four rounds and a P1 is still open, so the PR guide's review limit allows no round 5. I'm handing the PR to the Microcosm hub, which chooses between a rework and a call for Max. Nobody merges this PR while the P1 is open, and it stays a draft.

Head: d65a6d7d779e0f2bc6d0eef338e0dbdcb4a7a62a, the head round 4 read. It is ten commits on 063040ef17ee770c4e576a0b260c9d11c23e3e80.

Round 4 (scoped, the last round): REQUEST CHANGES. Two findings are open:

  1. N1, P1, test_us_fiscal_refresh_builder.py. In test_main_writes_diagnostics_before_post_calibration_gate_failure, the test patches builder._sha256 with fake_sha256, which returns "base-sha" for the base. The builder's _legacy_base_h5_sha256 calls _sha256 and passes the result to the stub I added for require_declared_location_clones. The stub asserts the real SHA-256 of the fixture's bytes, so by inspection all 17 non-pool modes fail. In the four dry runs the failed assertion becomes a refusal before the expected one. The two prepared-pool modes bypass the stub. The fix is one line: assert fake_sha256(base_h5).
  2. N2, P2. The test module docstring in test_us_declared_location_clones.py, the tail comment in puf_capital_gains_tail.py and the docstring in warm_start_selection.py say the index is compared with K. The guard compares the largest index on each non-empty entity table with K − 1. puf_capital_gains_tail.py is one of the seed protocol's attested modules, so editing its comment moves pins.

Round 4 found no other fixture that reaches the guard with an incompatible frame or file. Rounds 1 and 2 also asked for changes. Round 3 closed two of round 2's three P1s, A1 and A2, lowered the third, R1, to P2, and raised N1, which round 4 left open.

Not run: nobody has run a pytest test on any of the ten commits. I replayed the tail check in pandas, and c10_replay.py replays the declared-K helper with two mutants. Reviewers found faults in test code nobody had run in rounds 3 and 4, so the rework needs a real run of test_us_declared_location_clones.py, test_us_fiscal_refresh_builder.py and the tail, warm-start, Head Start and voluntary-filing files. CI's --maxfail=1 stops at the first stale pin, so it won't run them.

Pins: none moved and none committed. On this machine, in a borrowed environment with a checkout of main's packages on the path, repin_us_spec_engine_contracts.py --check and spec_engine_coverage.py --check pass on main 0278db13d4, with 42,404 of 42,404 configuration fields and 41 of 41 inventory checks. The four pin steps haven't started. Derive the pins once, on the final head, in a proper environment, and let CI's --check confirm them. #1676 and this PR overlap on some pins and on puf_support.py, so whoever lands second derives the pins again.

Proposed fix, not pushed: a patch for N1 only, which nobody has reviewed or run. Applying it counts as a rework, which would need the hub's own review.

Depends on: nothing. Hold or decision: none. From 2026-12-01 the UK local-adjudication checks go red and block every microcosm merge until someone renews those UK entries.

Follow-ups owed (none filed). R1, R5 and R6 are round 1's labels, which later rounds carried forward, and C1 through F1 are round 2's:

  • R1 (P2). The preflight reads the tables and the H5 attribute at different times. If someone replaces a K = 3 file with one that declares K = 2 after load_us_frame verifies the tables, the preflight can accept the old tables against the new declaration. The reviewer inferred this case from the code.
  • R5 (P2). voluntary_filing requires a positive location index before it treats a missing source ID as an error. A frame that keeps only location 0 falls back to the remapped tax_unit_id.
  • R6 (P2). The default ACS pooling path skips the located-donor check, and with_optional_acs_spine checks the requested K without checking either input's location columns.
  • C1 (P2). location_clone_index_series accepts boolean indices.
  • C2 (P2). The Head Start signal gate and summary group by source and never read the location column.
  • C3 (P2). The indexed voluntary-filing signal gate doesn't validate the full triple, so it can accept a relabelled duplicate copy. Its summary stringifies source IDs that the imputer decodes from bytes.
  • C4 (P2). _source_table in SSI take-up casts support rank through float64, as it did before this PR.
  • D1 (P2). The voluntary-filing canonical-order fixture can't detect a missing location sort key.
  • D3 (P3). No test round-trips the H5 attribute and columns through the real loader and writer.
  • F1 (P2). _resolve_selection_source compares a custom warm-start key verbatim with the stored key, so reusing the key that made a located manifest fails. docs/us-location-v1.md says so.

Review record (on this machine, under ~/reviews/us-one-population-d2283-2026-11-11/runs/location-clones-2026-11-30/):

  • Round 1 (review-00275fdbf/), round 2 (review-2941d87ce/), round 3 (review-482f2f76e/) and round 4 (review-d65a6d7d7/), each with brief.md and review-sol.md. Every review was a static read by a Codex lane.
  • An in-session review of the first two commits: review-063040ef17/, with SYNTHESIS.md.
  • The proposed N1 patch: handoff/n1-proposed-fix.UNREVIEWED-UNRUN.patch.
  • The re-pin recipe and the logs of its main checks: repin/, and cloud-repin-task.md.

MaxGhenis and others added 3 commits December 2, 2026 08:30
Main moved the US engine to policyengine-us 2.145.3, which defines
tax_unit_role_input, the two parent ids and the four federal student
loan inputs, so those seven left the stored-input register. This branch
adds the six {entity}_location_clone_index columns. Three files
conflicted, and each keeps main's register plus the six indexes:

- stored_inputs.py: main's paragraph on the seven dropped entries, then
  the location-clone paragraph without its parent-id and student-loan
  bullets.
- test_support/microcosm_data/stored_inputs.py: the producer-bound
  entries are county_fips_2023 and the six indexes.
- test_us_stored_input_register.py: main's docstring, construction set,
  count and owners, plus the location set and owners; the count is
  56 - 7 + 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 4 of the review left one P1 and one P2 open.

N1: test_main_writes_diagnostics_before_post_calibration_gate_failure
patches builder._sha256 with fake_sha256, which returns "base-sha" for
the base. The builder passes that value to the declared-K check, so the
stub must compare it with fake_sha256(base_h5), not with the real
SHA-256 of the fixture's bytes.

N2: require_declared_location_clones requires the largest index on each
non-empty entity table to be K - 1. The test module docstring, the
capital-gains tail comment and the warm-start docstring said the index
is compared with K; they now say K - 1. The tail module is attested, so
this commit moves generated identities that are not yet recomputed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first real run of this PR's tests, at 5805543, failed three:

- test_the_register_is_the_pre_location_register_plus_six_entries and
  test_the_examined_files_verdicts_match_the_pre_change_golden compared
  with goldens read at main 1d8b9b8. Main at 2baa35e dropped seven
  register entries when it moved to policyengine-us 2.145.3. Recomputed
  at 2baa35e with main's own stored_inputs.py: 49 entries, register
  df9155e2, verdicts 7352f3d5. The merged register without the six
  location entries equals main's register, and main's code gives the
  same verdict digest as this branch's code.
- test_block_v1_refuses_location_clones_naming_the_route_a_checks looked
  for "auto loans and education debt". Round 3 (482f2f7) reworded the
  tool's blocker to "auto loans and, with --scf-education-debt,
  education debt" and left the test behind.

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

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by the Microcosm hub (Claude Code).

The hub took this hand-off as a rework rather than a call for Max. The open P1, N1, and the P2, N2, are a test-stub assertion and comment wording, with no methodology or release question. The head is now 3d964ba8084e7a241786c7f304bc546cacaf4ce8, three commits on d65a6d7d:

  • 4e1d8984 merges main at 2baa35ef. Main moved to policyengine-us 2.145.3, which defines seven former register entries as inputs: the tax-unit role, the two parent ids and the four student loan inputs. Three files conflicted, and each now keeps main's register plus the six location-clone indexes. Loading both modules shows the merged register is main's 49 entries plus those six.
  • 58055431 fixes N1: the stub compares the digest with fake_sha256(base_h5), the value the patched _sha256 returns. It fixes N2 by making the test module docstring, the capital-gains tail comment and the warm-start docstring say the largest index must be K − 1.
  • 3d964ba8 fixes three tests that failed on the first real run. Two K = 1 goldens came from main at 1d8b9b8dd6. I recomputed them at 2baa35ef with main's own stored_inputs.py: 49 entries, register df9155e2…, verdicts 7352f3d5…. Main's code gives the same verdict digest as this branch's code. The third test still looked for the blocker wording that round 3 replaced.

Run: at 58055431, on macOS with Python 3.14 and policyengine-us 2.145.3 (the lock's version), the 18 engine-free test files this PR touches, the engine-contract register test and microcosm-data's test_stored_inputs.py. 1,129 passed, 3 failed, 2 skipped. The skips need MICROCOSM_US_CHRONICLE_FACTS. The two files with failures pass at 3d964ba8: 84 passed. Every test in test_us_fiscal_refresh_builder.py and test_us_declared_location_clones.py passed, including all modes of test_main_writes_diagnostics_before_post_calibration_gate_failure.

Still to do before merge:

  • The generated identities. Nothing is re-pinned yet, so CI's pin checks fail at this head. The pins will be derived once on the final head, after microcosm#1833 merges, because it moves some of the same identities.
  • An independent review of the rework: the merge resolution, the three fixes and the guard-reach check that round 4 made 266 commits behind main.
  • One follow-up issue for the P2 and P3 findings this PR owes (R1, R5, R6, C1 to C4, D1, D3, F1), each re-checked on the merged tree first.

The PR stays a draft until then.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by the Microcosm hub (Claude Code).

The ten P2 and P3 findings this PR owes are filed as microcosm#1845. Each was re-checked by reading the merged tree at 58055431, and a second reader tried to refute it. All ten are still present; R6 and D1 dropped to P3. None changes a build today, because every line still refuses K > 1.

h5_io.py conflicted only because both sides added a function right after
assert_h5_unchanged: this branch's require_declared_location_clones and
main's refuse_unexpected_h5_digest. The merge keeps both, unchanged. Every
other file merged without conflict. The US seed protocol pins still need the
re-pin that follows this merge.

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

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.

1 participant