Skip to content

Send household inputs to the policyengine-us variables rules read - #40

Merged
MaxGhenis merged 5 commits into
mainfrom
claude/blissful-zhukovsky-0d720c
Nov 6, 2026
Merged

MaxGhenis merged 5 commits into
mainfrom
claude/blissful-zhukovsky-0d720c

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cliff-watch sent several household inputs to policyengine-us variables that the engine computes from other variables: totals (adds) and derived variables. An input on such a variable replaces the computation, so every rule that reads a component or a sibling saw zero. This PR sends each input to the variable rules read and adds invariant tests that fail if a builder sets an unreviewed total.

The live UI fetches its settings from /api/metadata and runs every calculation through /api/series, which runs cliff_watch/calculator.py on Vercel. Since a57332d (2026-05-29), no UI code calls frontend/src/policyengineApi.js's situation builder. It gets the same fixes, and a differential test holds it to the Python builder.

Rebase onto main (5 November 2026)

The original work on this PR stopped on 30 September, before its independent review finished. Changes since that head (0bca069):

Review round 1 (5 November 2026)

An independent review (Opus, read-only) asked for two fixes and six smaller changes. This push makes them:

  • Savings follow SSI's own test. The savings holder counted the Disabled checkbox as a way to claim SSI, but policyengine-us's SSI disability test reads meets_ssi_disability_criteria, which cliff-watch never sets. So when the user marked a 40-year-old head Disabled in a TX couple with a 70-year-old spouse, the savings stayed with the head and the spouse's SSI ignored them. Both builders now use age 65 or over, or blindness (_could_claim_ssi). A new test checks that couple: the spouse's SSI falls to $0 with $5,000 of savings and stays positive without them. Another checks _could_claim_ssi against the engine's is_ssi_aged_blind_disabled for ten people aged 0 to 90, under all four combinations of the Blind and Disabled flags. None of the 17 impact households has both a spouse and savings, so the tables below don't change.
  • The changelog no longer credits this PR with the pins and the CI workflow, which Pin policyengine-core >=3.32.0 so concurrent requests stop failing #41 added. It now says that share links that predate this release read their Dividends, Pension and Social Security amounts under the narrower new meanings.
  • The gross-income invariant compares with the engine's taxable Social Security. It used to infer taxable benefits as gross income minus everything else, so a $5,000 field counted twice could pass inside the 0–85% band whenever the household had benefits. It now checks gross income minus the taxable income the user entered against the head's own taxable_social_security, within the float32 tolerance, and applies the band to that variable.
  • CI runs the September float32 household every time, as an @example.
  • A new invariant covers formula variables. test_never_sets_a_computed_variable_unless_listed fails when either builder sets a variable that has a formula, unless KNOWN_COMPUTED_INPUTS lists it with what the input replaces. Ten variables qualify on 1.755.5, and main already sets all ten. One of them, childcare_expenses, fixes the out-of-pocket cost at the amount the user entered, even when a subsidy pays part of it; it gets a follow-up.
  • The JS-vs-Python differential states its scope. The payloads that Hypothesis draws carry filing_status, a lowercase programs_mode and the metadata program list, and a comment lists where the builders still differ outside that.

A follow-up takes one more finding, because it predates this PR: income and the earnings axis follow the first person in the payload, while savings follow the head role. The UI always lists adults first.

What went wrong

Input Sent before Effect (engine 1.755.5, reproduced) Now sends
Pension pension_income (total) taxable_pension_income stayed 0, so pensions never reached AGI, federal or state tax, or the taxable-Social-Security test (NY, 67, $30k: AGI 0; now 30,000) taxable_private_pension_income; new Government pension field → taxable_public_pension_income
Social Security social_security (total) social_security_retirement stayed 0 (CA CalWORKs, DE and RI child care read it); SSDI that cliff-watch sent alongside it dropped out of the total social_security_retirement (the field becomes Social Security retirement)
Dividends dividend_income (deprecated total) qualified_dividend_income stayed 0, so the engine taxed dividends as ordinary income qualified_dividend_income (the field becomes Qualified dividends)
Second adult's wages employment_income plus tanf_gross_earned_income and state TANF earned-income overrides Setting the override on one person fixed everyone else's at 0. TANF stayed flat across the whole earnings axis whenever a second adult had wages. Live production, NY couple + toddler, second adult $3k: TANF $4,668 at every point from $3k to $43k. Head Start and WIC, which read TANF, stayed on too. On the household path the override also dropped self-employment income employment_income only
MAGI (household path only) aca_magi = medicaid_magi = an estimate that left out Social Security /api/calculate disagreed with /api/series on the ACA PTC and CHIP premium. aca_magi itself adds up medicaid_magi nothing; policyengine-us derives MAGI on both paths
Checking and savings snap_assets (total of bank/stock/bond) State TANF resource tests (spm_unit_cash_assets) and the SSI resource test (ssi_countable_resources) saw $0 bank_account_assets on the head, or on a spouse who could claim SSI (65 or older, or blind) when the head couldn't
Utilities utility_expense (total of per-utility bills on 1.755.5) SNAP picks its utility allowance from the per-utility bills, so it gave no allowance in the 36 states without a forced standard allowance heating_cooling_expense (the tooltip says the app treats the bills as including heating or cooling)
CHIP premium (JS path only) a request on households policyengine-us defines it on tax_unit, and api.policyengine.org rejects wrong-entity requests a request on tax_units

The brief asked: can the UI set per-person ssi_amount or ssdi_amount? No. InputPanel has no control for either, share links don't carry them, and dataLookup.normalizePeople strips them. A test (household payload omits direct SSI and SSDI amount inputs) locks that in. PR #23 removed them on purpose. The Python API still accepts them, and the JS builder now mirrors that.

Engine pins

This PR changes no engine pin. #41 (4b87f6b) pinned policyengine-us 1.755.5, policyengine-core >=3.32.0,<3.32.2 and spm-calculator 0.3.1, committed uv.lock, and added the CI workflow that installs from it. In September this PR carried its own pins (policyengine-core 3.28.0). The tables below come out identical under both cores.

Which displayed numbers change, and by how much

Chart (/api/series, what the UI shows) on the pinned engine: origin/main code vs this branch. "Now @ $20k" reads each output at $20k of head earnings on top of any other adult's wages. The full per-output tables follow.

Household Main change
NY retiree 67, private pension $30k + SS $18k Taxes now include the pension: +$1,582 at $0 earnings and +$5,266 at $20k (up to +$8,006); net income falls by the same amount
NY retiree 67, government pension $30k + SS $18k Same as above (NY doesn't distinguish on 1.755.5). A $30k government pension instead of private lowers state tax in MO ($323 → $0), MN ($583 → $0), NE ($458 → $0), AZ ($154 → $91) and ID ($49 → $0)
CA retiree 67, dividends $20k + SS $15k Qualified-dividend rates: federal tax −$2,324 at $20k (up to −$2,400)
PA 62, pension $18k Pension now counts toward MAGI: Medicaid ($14,162) ends at $5k instead of later, and the ACA PTC takes over (+$12,904 at $20k). Taxes +$2,548 at $20k
DE / RI grandparent 60, SS $14k + toddler, child care $8k SS now counts for Purchase of Care / CCAP: subsidy at $20k $8,000 → $5,620 (DE) and $3,068 → $688 (RI)
ID retiree 70, SS $20k + government pension $25k Federal tax +$620 at $0 and +$4,294 at $20k (ID still exempts the government pension)
TX parent + 2 kids, dividends $3k Federal tax and refundable credits move by up to $360
GA couple 66/64, SS $24k + pension $12k MAGI at $0 earnings rises from 24,000 (113% of FPL) to 36,000 (170%); the ACA PTC appears at $0 (+$16,780), and at $20k it goes $15,602 → $13,671
TX 60 disabled, SS $12k + SSDI $6k (API only) Social Security now includes SSDI: SNAP $728 → $286 at $0; PTC −$937 at $20k
CA elder 70, SS $9k + pension $3k Federal tax +$10 at $20k (up to +$981 at high earnings)
MA couple + infant, pension $10k, dividends $2k, SS $6k Pension and dividends now count toward MAGI: parents' Medicaid ends earlier ($42,352 → $8,568 at $20k) and the ACA PTC takes over (+$21,117). Net income −$13,764 at $20k; 3 → 5 cliff points
NY couple + toddler, second adult wages $3k TANF phases out ($4,668 → $0 by $18k household wages) instead of staying at $4,668 to $43k; SNAP rises up to $2,102 as TANF falls; Head Start ($16,491) and WIC end with TANF instead of at $43k–$50k
TX parent + 2 kids, utilities $3.6k SNAP standard utility allowance: SNAP +$1,512 at $20k (up to +$1,602)
TX 70 alone, savings $5k SSI resource test ($2,000 limit) now applies: SSI $11,928 → $0 and Medicaid $13,708 → $0; SNAP $750 → $3,576
TX parent + 2 kids, savings $3k TX TANF resource test now applies: TANF $4,584 → $0; SNAP +$1,227 at $20k
CA 63, SS $18k No chart change. /api/calculate now matches the chart (PTC $19,723 → $17,048 at $20k)

Cliff locations and marginal rates move only where the programs above do. final_impact.py and impact_report.py in ~/PolicyEngine/_analysis/cliff-watch-total-inputs-2026-09-29/ produce these tables, IMPACT.md there holds them, and ~/PolicyEngine/_analysis/cliff-watch-pepy-2026-11/pr40-impact-rebased/ holds the 5 November reruns.

Full per-output tables
H1 NY retiree 67, private pension 30k + SS 18k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 30,000 28,418 47,905 42,639 -8,006 at $100,000
Taxes 0 1,582 2,095 7,361 +8,006 at $100,000
Federal tax 0 1,504 1,648 6,338 +7,389 at $100,000
State tax 0 78 448 1,023 +617 at $100,000

Cliff points: 0 now, 0 in the PR. Highest marginal tax rate: 37% now, 40% in the PR.

H2 NY retiree 67, government pension 30k + SS 18k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 30,000 28,418 47,905 42,639 -8,006 at $100,000
Taxes 0 1,582 2,095 7,361 +8,006 at $100,000
Federal tax 0 1,504 1,648 6,338 +7,389 at $100,000
State tax 0 78 448 1,023 +617 at $100,000

Cliff points: 0 now, 0 in the PR. Highest marginal tax rate: 37% now, 40% in the PR.

H3 CA retiree 67, dividends 20k + SS 15k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 19,998 19,998 34,614 36,938 +2,400 at $25,000
Taxes 2 2 5,386 3,062 -2,400 at $25,000
Federal tax 0 0 4,974 2,650 -2,400 at $25,000

Cliff points: 0 now, 0 in the PR. Highest marginal tax rate: 44% now, 46% in the PR.

H4 PA 62, private pension 18k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 32,442 31,694 49,602 45,796 -14,413 at $45,000
Total support 14,448 14,448 14,162 12,904 -11,695 at $45,000
Taxes 6 755 2,560 5,108 +4,525 at $82,500
Medicaid 14,162 14,162 14,162 0 -14,162 at $5,000
ACA premium tax credit 0 0 0 12,904 +15,092 at $5,000
Federal refundable credits 0 0 0 0 -664 at $10,000
State refundable credits 0 0 0 0 -66 at $10,000
Federal tax 0 190 1,934 3,924 +3,960 at $67,500
State tax 6 565 626 1,184 +712 at $5,000

Cliff points: 1 now, 1 in the PR. Highest marginal tax rate: 414% now, 422% in the PR.

H5 DE grandparent 60, SS 14k + toddler, childcare 8k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 50,971 50,971 62,366 59,986 -8,000 at $30,000
Total support 58,971 58,971 52,156 49,776 -8,000 at $30,000
Child care subsidy 8,000 8,000 8,000 5,620 -8,000 at $30,000

Cliff points: 6 now, 4 in the PR. Highest marginal tax rate: 784% now, 988% in the PR.

H6 RI grandparent 60, SS 14k + toddler, childcare 8k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 44,595 44,595 57,605 55,225 -2,380 at $20,000
Total support 52,595 52,595 47,355 44,975 -2,380 at $20,000
Child care subsidy 3,068 3,068 3,068 688 -2,380 at $20,000

Cliff points: 5 now, 4 in the PR. Highest marginal tax rate: 838% now, 843% in the PR.

H7 ID retiree 70, SS 20k + government pension 25k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 25,155 24,535 43,625 39,331 -6,233 at $100,000
Taxes 0 620 1,530 5,824 +6,233 at $100,000
Federal tax 0 620 1,530 5,824 +6,153 at $100,000
State tax 0 0 0 0 +80 at $60,000

Cliff points: 0 now, 0 in the PR. Highest marginal tax rate: 37% now, 39% in the PR.

H8 TX parent + 2 kids, dividends 3k, rent 12k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 43,807 43,807 50,137 50,137 +360 at $42,500
Total support 52,807 52,807 40,667 40,667 +360 at $42,500
Taxes 0 0 1,530 1,530 -360 at $65,000
Federal refundable credits 0 0 9,941 9,941 +360 at $55,000
Federal tax 0 0 1,530 1,530 -360 at $65,000

Cliff points: 3 now, 3 in the PR. Highest marginal tax rate: 872% now, 866% in the PR.

H9 GA couple 66/64, SS 24k + private pension 12k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 12,286 29,066 46,594 44,141 +16,780 at $0
Total support 286 17,066 16,124 13,671 +16,780 at $0
Taxes 0 0 1,530 1,530 +2,278 at $37,500
ACA premium tax credit 0 16,780 15,602 13,671 +16,780 at $0
Federal refundable credits 0 0 522 0 -664 at $15,000
Federal tax 0 0 1,530 1,530 +2,278 at $37,500

Cliff points: 1 now, 1 in the PR. Highest marginal tax rate: 435% now, 437% in the PR.

H10 TX 60 disabled, SS 12k + SSDI 6k (API only)
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 6,728 6,286 38,517 37,430 +16,215 at $2,500
Total support 6,728 6,286 20,487 19,550 +16,215 at $2,500
Taxes 0 0 1,970 2,120 +1,122 at $57,500
ACA premium tax credit 0 0 14,487 13,550 +16,215 at $2,500
SNAP 728 286 0 0 -442 at $0
Federal refundable credits 0 0 0 0 -57 at $17,500
Federal tax 0 0 1,970 2,120 +1,122 at $57,500

Cliff points: 1 now, 1 in the PR. Highest marginal tax rate: 438% now, 444% in the PR.

H11 CA elder 70, SS 9k + private pension 3k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 14,021 14,021 30,568 30,558 -981 at $97,500
Total support 11,022 11,022 9,360 9,360 -52 at $27,500
Taxes 1 1 1,792 1,802 +981 at $97,500
State refundable credits 0 0 124 124 -52 at $27,500
Federal tax 0 0 1,790 1,800 +700 at $80,000
State tax 1 1 2 2 +281 at $97,500

Cliff points: 1 now, 1 in the PR. Highest marginal tax rate: 395% now, 400% in the PR.

H12 MA couple + infant, pension 10k, dividends 2k, SS 6k, childcare 10k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 77,873 77,873 97,310 83,546 -21,665 at $27,500
Total support 75,873 75,873 77,392 64,202 -21,021 at $27,500
Taxes 0 0 2,082 2,656 +1,460 at $50,000
Medicaid 42,352 42,352 42,352 8,568 -42,352 at $25,000
CHIP 0 0 0 0 +4,022 at $25,000
CHIP premium 0 0 0 0 -336 at $67,500
ACA premium tax credit 0 0 0 21,117 +21,117 at $20,000
Federal refundable credits 0 0 6,127 5,753 -3,009 at $32,500
State refundable credits 440 440 2,211 2,061 -789 at $30,000
Federal tax 0 0 1,622 1,622 +960 at $50,000
State tax 0 0 460 1,034 +803 at $15,000
WIC 714 714 714 714 -714 at $32,500

Cliff points: 3 now, 5 in the PR. Highest marginal tax rate: 1195% now, 979% in the PR.

H13 NY couple + toddler, second adult wages 3k
Output Now @ $3,000 PR @ $3,000 Now @ $23,000 PR @ $23,000 Largest change on the $0–100k curve
Net income 86,663 86,663 104,747 102,177 -21,873 at $90,500
Total support 83,921 83,921 83,814 81,244 -21,873 at $50,500
SNAP 9,420 9,420 3,329 5,428 +2,102 at $18,000
Head Start 16,491 16,491 16,491 16,491 -16,491 at $43,000
TANF 4,668 4,668 4,668 0 -4,668 at $18,000
WIC 714 714 714 714 -714 at $50,500

Cliff points: 2 now, 2 in the PR. Highest marginal tax rate: 1765% now, 1779% in the PR.

H14 TX parent + 2 kids, rent 12k, utilities 3.6k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 54,112 54,112 59,454 60,966 +1,602 at $25,000
Total support 69,712 69,712 56,584 58,096 +1,602 at $25,000
SNAP 9,420 9,420 5,723 7,235 +1,602 at $25,000

Cliff points: 4 now, 4 in the PR. Highest marginal tax rate: 663% now, 663% in the PR.

H15 TX 70 alone, savings 5k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 26,386 3,576 34,903 18,756 -22,810 at $0
Total support 26,386 3,576 16,433 286 -22,810 at $0
Medicaid 13,708 0 13,708 0 -13,708 at $0
SNAP 750 3,576 286 286 +3,200 at $2,500
SSI 11,928 0 2,438 0 -11,928 at $0

Cliff points: 1 now, 0 in the PR. Highest marginal tax rate: 607% now, 32% in the PR.

H16 TX parent + 2 kids, rent 12k, savings 3k
Output Now @ $0 PR @ $0 Now @ $20,000 PR @ $20,000 Largest change on the $0–100k curve
Net income 57,712 53,128 63,054 61,554 -4,584 at $0
Total support 69,712 65,128 56,584 55,084 -4,584 at $0
SNAP 9,420 9,420 5,723 6,950 +1,454 at $15,000
TANF 4,584 0 2,728 0 -4,584 at $0

Cliff points: 4 now, 4 in the PR. Highest marginal tax rate: 663% now, 653% in the PR.

H17 CA 63, SS 18k

No displayed number changes.

Invariants and their tests

Hypothesis checks them against the installed policyengine-us graph, and fast-check against a committed snapshot of it. A test checks that the snapshot matches the installed engine.

  1. No total as input: neither builder sets a variable with adds/subtracts unless REVIEWED_TOTAL_INPUTS lists it with a reason (only employment_income and self_employment_income, which policyengine_us.Simulation moves onto *_before_lsr).
    1a. No formula variable as input: neither builder sets a variable that has a formula unless KNOWN_COMPUTED_INPUTS lists it with what the input replaces. A second test fails when a listed variable loses its formula, so the list can't go stale.
  2. No total with its component: neither builder sets an input together with any of its transitive components on the same entity.
  3. Right entity: every variable either builder emits exists in the engine and sits on its own entity.
  4. Conservation: each head income amount the user enters lands exactly once, on its mapped component. The builders send the same sum the user entered, and no other person gets it.
  5. Engine round trip: after simulation, each component equals the amount the user entered; social_security = retirement + SSDI; pension_income = private + government. Head irs_gross_income = the taxable income the user entered + Alaska PFD + the head's taxable_social_security, up to float32 rounding of $0.01 plus 20 × 2⁻²⁴ of gross income, and 0 ≤ taxable_social_security ≤ 85% of benefits. CI runs the September float32 household as an example. The invariant leaves out, on purpose, a first adult whom policyengine-us makes another adult's tax dependent (see limitations).
  6. Differential, JS vs Python: policyengineApi.js buildSituation sends exactly the inputs calculator.py does (Hypothesis through node), for payloads with filing_status, a lowercase programs_mode and the metadata program list.
    6a. Differential, savings holder vs engine: _could_claim_ssi equals the engine's is_ssi_aged_blind_disabled for every person the builder emits, and SSI_AGED_THRESHOLD equals gov.ssa.ssi.eligibility.aged_threshold.
  7. Differential, household vs series: /api/calculate equals the /api/series point at the same earnings for every displayed program, taxes and net income, to within cent rounding.
  8. Live (opt-in, POLICYENGINE_LIVE_API=1): situations from both builders round-trip through api.policyengine.org. All 5 Python live cases fail on origin/main (each component reads 0 where the test enters 30,000, 30,000, 20,000, 12,000 and 9,000) and pass here.

Engine-pinned regressions (tests/test_input_regressions.py):

  • NY pension reaches AGI and the NY exclusion;
  • CalWORKs counts Social Security;
  • TANF phases out with a second earner;
  • self-employment income counts as TANF earned income;
  • utilities give the standard allowance;
  • savings count for SSI and TX TANF;
  • savings go to the spouse who could claim SSI;
  • savings reach an aged spouse when the user marks the head Disabled.

The frontend test runner moves from node --test to Vitest, and the existing tests keep their assertions. #41's .github/workflows/test.yml runs both suites.

Known limitations (unchanged here; each has a follow-up task)

  • Savings beyond the head and spouse: savings stay with the head or spouse, so the SSI resource test of a blind child or a third adult aged 65 or over sees none of them. policyengine-us 1.755.5 has no parental deeming of resources, so moving them wouldn't model it either.
  • User-entered Social Security retirement, unemployment and child support still never enter displayed net income: household_market_income excludes them, and cliff-watch doesn't count them as programs. They stay constant along the earnings axis, so cliffs and MTRs come out right but levels come out low.
  • Cliff-watch files two-adult UNMARRIED households as JOINT: the UI never sends filing_status, and the API ignores marital_status. So an unmarried partner aged 65 or over also takes the household's savings into their SSI test. In some multi-adult households policyengine-us makes the first adult a tax dependent.
  • With one SSI-eligible spouse, policyengine-us tests the couple's savings against the $2,000 individual limit; deeming would use the $3,000 couple limit.
  • Cliff-watch sets childcare_expenses as an input, so SNAP's dependent care deduction and the other rules that read it see the full child care cost the user entered, even when a subsidy pays part of it. policyengine-us's formula would subtract the subsidy.
  • Head income, wages and the earnings axis go to the first person in the payload. The UI lists adults first; an API payload that lists a child first gives that child the earnings.
  • Housing assistance comes to $0 outside LA County because neither builder sets county_fips.
  • The Disabled flag never makes anyone SSI-eligible: meets_ssi_disability_criteria defaults to False, so a disabled 40-year-old gets SSI $0 and a blind one $11,928.
  • The chart's per-person Medicaid value depends on the chart's earnings range: $14,711 at a $10k max and $17,402 at $100k, for the same person at $0.
  • Run CliffWatch on policyengine.py's calculate_household #45 takes on the move to policyengine-us 2.x, which drops or renames CCDF inputs, deprecates heating_cooling_expense and changes Head Start income.

axiom: n/a: cliff-watch app input mapping; no policy encoding change

🤖 Generated with Claude Code

@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cliff-watch Ready Ready Preview Nov 5, 2026 5:06pm UTC

Request Review

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Heads-up from #41 (merged 2026-10-23 14:09 UTC as 4b87f6b, fixing #38). This PR conflicts with it in pyproject.toml, requirements.txt, modal_app.py, uv.lock and .github/workflows/test.yml.

Rebase onto main and take #41's engine pins. Two problems with the pins here:

  1. policyengine-core==3.28.0 reintroduces Intermittent 'rules-engine formulas must be deterministic' errors from /api/series #38.
    • Core 3.27.0 through 3.29.2 forbid randomness with a runtime guard that patches numpy.random process-wide while any formula runs.
    • On Vercel Fluid compute, concurrent requests share a process. One request's Simulation.__init__ call to np.random.seed(0) then fails with "rules-engine formulas must be deterministic".
    • Production failed 20 of 63 concurrent requests this way.
    • Pin policyengine-core >=3.32.0 so concurrent requests stop failing #41 adds tests/test_engine_concurrency.py, which fails on any core that still has the guard.
  2. policyengine-us==1.755.5 no longer installs from PyPI. The release was deleted; only weekly releases remain, e.g. 1.755.0 and 1.768.1. This branch's uv sync --locked and its Vercel build will fail on the next run.

What #41 pins instead

  • policyengine-us @ https://github.com/PolicyEngine/policyengine-us/archive/fc64cef64ab55c3c48309c7fb304c35e5f3c9184.tar.gz: the 1.755.5 release commit. Its wheel matches PyPI's 1.755.5 file for file.
  • policyengine-core>=3.32.0,<3.32.2, locked at 3.32.1. 3.32.2 and later reject 1.755.5's parameter files.
  • spm-calculator==0.3.1.

On those pins, /api/series output is identical to the previous production. So this PR's number-impact tables, which compare main vs branch on the same engine, should still hold after the rebase. Re-lock (uv lock) and rerun the fingerprint to confirm.

.github/workflows/test.yml is #41's copy of this PR's file, minus the comment about the JS-vs-Python differential test. Keep this PR's version.

MaxGhenis and others added 3 commits November 4, 2026 19:37
Cliff-watch set totals and derived variables as inputs. An input on a
policyengine-us variable that is computed from others replaces the
computation, so every rule reading a component or sibling saw zero:

- pension_income left taxable_pension_income, and so AGI and income
  tax, at 0; pensions now go to taxable_private_pension_income, with a
  new government pension field on taxable_public_pension_income.
- social_security left social_security_retirement at 0 and dropped
  SSDI from the total; it now sets social_security_retirement.
- dividend_income taxed all dividends as ordinary income; it now sets
  qualified_dividend_income.
- A tanf_gross_earned_income override on a second earner fixed the
  head's at 0, freezing TANF (and TANF-linked Head Start and WIC)
  across the earnings axis. Only employment_income is set now.
- The household path's aca_magi/medicaid_magi estimate left out Social
  Security; policyengine-us now derives MAGI on both paths.
- snap_assets hid savings from TANF and SSI resource tests; savings go
  to bank_account_assets.
- utility_expense gave no SNAP utility allowance; utilities go to
  heating_cooling_expense.

Pins policyengine-us 1.755.5, policyengine-core 3.28.0 and
spm-calculator 0.3.1 and commits uv.lock. That environment reproduces
production byte for byte. An unpinned redeploy would install 2.15.16,
which crashes the API.

Adds Hypothesis and fast-check invariants checked against the
policyengine-us variable graph, a JS-vs-Python builder differential, a
household-vs-series differential, engine-pinned regressions, opt-in
live-API checks, and a CI test workflow. Moves frontend tests to Vitest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main added seriesRefine.test.js on node:test after this branch moved the
frontend suites to Vitest, so the rebased suite found no tests in it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
policyengine-us adds the 20 gross income sources one at a time in
float32, so irs_gross_income can differ from the exact sum by up to
20 * 2**-24 of itself. An Alaska household with $523,288 of
miscellaneous income and $1 of SSDI computes $0.85 of taxable benefits,
but gross income comes back $0.875 above the other income, so the
fixed $0.01 tolerance failed on Hypothesis' random draws. The tolerance
now scales with that bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Savings go to a spouse only when the spouse is 65 or over or blind, the
  engine's own SSI test: the Disabled checkbox never sets
  meets_ssi_disability_criteria, so it made a disabled head keep the savings
  that an aged spouse's resource test needed. Both builders change; new tests
  cover that couple and compare _could_claim_ssi with the engine.
- New invariant: neither builder sets a formula variable unless
  KNOWN_COMPUTED_INPUTS lists it with what the input replaces.
- The gross-income invariant compares with the engine's
  taxable_social_security instead of a 0-85% band, and pins the September
  float32 household as an @example.
- The changelog no longer credits this PR with #41's pins and workflow, and
  notes the relabelled fields; the JS differential states its scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis marked this pull request as ready for review November 6, 2026 00:48
@MaxGhenis
MaxGhenis merged commit 7cb8f2d into main Nov 6, 2026
5 checks passed
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Merged as 7cb8f2d. GPT-6.1 Sol approved this PR's content at 3fd4aaf (review r2). For the merge of main at 5d9e520, an independent Opus 5.5 agent checked that it adds #46's changes and nothing else, and that no code a Vercel function loads imports a package #46 dropped: it ran 44 requests through all four handlers under an import recorder. It approved. All five checks passed at 5d9e520.

MaxGhenis added a commit that referenced this pull request Nov 6, 2026
Main now carries #40, whose files match this branch's base, and #46, which
removes the cold-start install on main's engine. This branch's engine takes
the function past Vercel's 225 MiB bundle again, so the port keeps its
install-fits-twice test and README section, adding #46's 4 KiB block wording,
its note that main requires no checks, the size walk's sanity floor and the
CI summary line. The pyproject comment now names policyengine-us as the
package that brings in tables, as uv.lock shows. The cold-start changelog
entry becomes a change from main rather than a fix.

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

Copy link
Copy Markdown
Contributor Author

Production now serves this change. Deployment dpl_HQwUTFUcJyvZ2oMdeoDprKXq3DCw built with no oversize line, so cold starts still skip the install. Eighteen production requests (metadata, the household types, and the series and single-household answers for four households in Texas and Massachusetts) returned the same JSON as a local run of this branch.

Ten of those answers differ from what production returned before the merge: the series and single-household answers for the 62-year-old with a pension in both states, and six /api/calculate answers that now echo public_pension_income_annual: 0.0 in their input. The function logs show the 18 requests on the new deployment, all 200, with no install, disk-full or invocation errors.

MaxGhenis added a commit that referenced this pull request Nov 7, 2026
README.md conflicted: keep main's Cold-start install section and this
branch's County from ZIP section, in that order. Everything else merged
cleanly. The next commit adapts this branch to #40's Vitest tests,
payload invariants and variable-graph snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Nov 7, 2026
The note for a link naming a county outside the ZIP said "ZIP 02467 lies
mostly in Middlesex County", but Middlesex holds 40% of its residents.
It now says the ZIP covers more than one county and that the chart would
otherwise use Middlesex County, home to 40% of its residents, or the
county with the largest share of its land when no one lives there.
A fast-check property checks that a note never says "mostly" and that
every share it quotes matches that county's option. The tests import
`test` from Vitest, as main's do since #40.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Nov 8, 2026
GitHub skipped the pull_request run for 07e66b8 because the PR still
targeted #40's branch when it arrived, and retargeting to main starts no run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Nov 8, 2026
* Resolve a household's county from its ZIP code

The form sends a ZIP and no county, so policyengine-us gave every household
its state's first county. A Cambridge, Massachusetts household read Barnstable
County's benchmark premiums.

The API now maps the ZIP to its county, keeps an explicit county from a share
link, passes the ZIP on to the engine, and returns a `location` block saying
which county it used and why.

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

* Show the county on the results page and test the ZIP rule

The results page now names the county the chart used. When a ZIP spans counties
it states the rule, shows each county's share of the ZIP's residents and offers a
picker, whose choice goes in the share link.

Tests cover the whole table, the resolution rule and the builder, with property
tests, and a differential test that a Middlesex ZIP gives the same series as the
explicit county link.

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

* Pin that every county code survives the explicit county path

A county picked on the results page goes through the calculator's county
normalization, so each code in the table must come out unchanged.

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

* Claim land share only for the county that has it

In a ZIP with no residents, the note said a county the user picked had the most
land. Only the first county does.

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

* Say when the engine holds no benchmark premium for a county

policyengine-us's premium table has no row for South Carolina's rating
areas 9 and 19 or Florida's 22, which serve Calhoun, Edgefield and Gulf
counties. Once the API read the ZIP, households there went from another
county's premium tax credit to none, with nothing on the page to explain
it. The location block now reports has_benchmark_premium, and the results
page states the gap. A test compares the list with the engine across every
county, so an engine update that adds the rows fails until the note goes.

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

* Word the no-county note for the District of Columbia

The note read "in a District of Columbia county" and "in District of
Columbia". DC is the state the form sends most mismatched ZIPs to, so it is
the note's most common reader.

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

* Quote the ZIP county's share when a link names another county

The note for a link naming a county outside the ZIP said "ZIP 02467 lies
mostly in Middlesex County", but Middlesex holds 40% of its residents.
It now says the ZIP covers more than one county and that the chart would
otherwise use Middlesex County, home to 40% of its residents, or the
county with the largest share of its land when no one lives there.
A fast-check property checks that a note never says "mostly" and that
every share it quotes matches that county's option. The tests import
`test` from Vitest, as main's do since #40.

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

* Keep housing assistance off and send the rating areas the engine misses

Housing: the ZIP and county let pha_payment_standard find a ZIP-level
standard, a small-area rent or Los Angeles County's schedule, and with
housing assistance among a household's programs the engine then pays a
voucher's subsidy to renters and homeowners alike wherever that standard
exceeds the household's required payment. CliffWatch
has no voucher input (#30), so both builders set
takes_up_housing_assistance_if_eligible to False. Housing assistance
stays at $0, as on main for every household but links naming Los
Angeles County, while receives_housing_assistance keeps feeding the
state programs that read it.

Rating areas: policyengine-us joins a county's code to
aca_rating_areas.csv and gives rating area 1 to a county the join
misses. 31 counties appear there under other names (BAYLOR_TX, the
former Valdez-Cordova and Wade Hampton rows, and so on), so the builder
now sends slcsp_rating_area for them. Oglala Lakota County has no row
under any name and keeps rating area 1.

Tests: every table county has an exact row, an override or no row;
each override holds its row's area; each override county prices like a
twin county the join matches; the override reaches every point of the
series; housing stays $0 where the engine computes a voucher; the API
cache keeps two ZIPs' series apart; a ZIP alone equals its county named
in every state; and the builder ranks a ZCTA with no residents by land.
The payload invariants now draw ZIPs and counties, and the JS
comparison leaves out the ZIP and the override counties, which only the
Python builder handles. The variable-graph snapshot adds zip_code,
slcsp_rating_area and the take-up flag.

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

* Test every ZIP and state, and a rating-area row under another spelling

The second review found three gaps in the tests:

- The ZIP-alone-equals-named-county property drew at most 300 examples from a
  fixed 2,000-ZIP sample. It now runs every (ZIP, state) pair the table holds,
  41,120 in all, per state; so does the check that a ZIP's county options lead
  with the county it resolves to.
- The rating-area test saw only exact codes, so a new row for Oglala Lakota
  under another spelling would have passed while the county kept area 1. A new
  test looks for rows under its own and its former name, Shannon.
- The frontend's form-vs-table check exempted every 201xx and 569xx ZIP. Those
  ranges now pass only with the known disagreement: form DC where the table
  says Virginia, and form Minnesota where it says DC.

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

* Check the loops cover every (ZIP, state) pair; format with ruff

The coverage test checked that every ZIP and every state appear in the
per-state lists, so lists holding each ZIP under its first state only
(40,982 pairs instead of 41,120) passed it while the 138 pairs of ZIPs
that cross a state line went untested. It now compares the listed pairs,
each exactly once, with a fresh walk of the table.

Also formats this PR's files with ruff (one blank line in zip_county.py),
sorts an import block, and passes the builder property's order check a
measure dict instead of lambdas that closed over loop variables (B023).

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 5d9e520e Deployed Nov 5, 2026 by vercel[bot]
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