Repository navigation
Send household inputs to the policyengine-us variables rules read - #40
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Heads-up from #41 (merged 2026-10-23 14:09 UTC as 4b87f6b, fixing #38). This PR conflicts with it in Rebase onto main and take #41's engine pins. Two problems with the pins here:
What #41 pins instead
On those pins,
|
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>
0bca069 to
b1c014a
Compare
- 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>
|
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. |
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>
|
Production now serves this change. Deployment 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 |
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>
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>
* 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>
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/metadataand runs every calculation through/api/series, which runscliff_watch/calculator.pyon Vercel. Since a57332d (2026-05-29), no UI code callsfrontend/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):
uv.lock, so this PR keeps Pin policyengine-core >=3.32.0 so concurrent requests stop failing #41's pins and adds onlyhypothesisto the lock. The rebase drops this PR's own pins and itsrequirements.txtandmodal_app.pychanges, and keeps Pin policyengine-core >=3.32.0 so concurrent requests stop failing #41's.github/workflows/test.ymland adds one comment to it.seriesRefine.test.js, which main gained after this PR opened, importstestfrom Vitest instead ofnode:test, so the Vitest runner collects it. Vitest now runs 75 tests in 8 files and skips 4 live ones.irs_gross_incomecan differ from the exact sum by up to 20 × 2⁻²⁴ of itself. Hypothesis drew an Alaska household with $523,288 of miscellaneous income and $1 of SSDI: taxable benefits came to $0.85, but gross income came back $0.875 above the other income, which failed the fixed $0.01 tolerance. The invariant now passes on that household and on 150 further random draws.final_impact.pyon main (1ffb4a0) and on this branch (b1c014a), both with policyengine-us 1.755.5 and policyengine-core 3.32.1, reproduces the September tables below exactly: all 27,618 numbers on main and 27,610 on this branch match, with a largest difference of $0.~/PolicyEngine/_analysis/cliff-watch-pepy-2026-11/pr40-impact-rebased/holds the outputs.pyproject.tomlandtests/test_deploy_footprint.pymatch Remove the cold-start install by trimming packages a calculation never imports #46's changes line for line, anduv.lockkeeps this PR'shypothesison top of Remove the cold-start install by trimming packages a calculation never imports #46's lock (uv lock --checkpasses). CI runs all five footprint tests at this head, and all five pass.final_impact.pyon 5d9e520 reproduces this branch's tables: all 27,610 numbers match. The preview deploymentdpl_EZaV1BqjCrCzYEQTRBxqW67Hg16Xbuilds with no "exceeds the standard size" line, its logs show no runtime install, and its first calculation requests took 32.7 to 34.6 seconds.Review round 1 (5 November 2026)
An independent review (Opus, read-only) asked for two fixes and six smaller changes. This push makes them:
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_ssiagainst the engine'sis_ssi_aged_blind_disabledfor 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.taxable_social_security, within the float32 tolerance, and applies the band to that variable.@example.test_never_sets_a_computed_variable_unless_listedfails when either builder sets a variable that has a formula, unlessKNOWN_COMPUTED_INPUTSlists 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.filing_status, a lowercaseprograms_modeand 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
pension_income(total)taxable_pension_incomestayed 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_incomesocial_security(total)social_security_retirementstayed 0 (CA CalWORKs, DE and RI child care read it); SSDI that cliff-watch sent alongside it dropped out of the totalsocial_security_retirement(the field becomes Social Security retirement)dividend_income(deprecated total)qualified_dividend_incomestayed 0, so the engine taxed dividends as ordinary incomequalified_dividend_income(the field becomes Qualified dividends)employment_incomeplustanf_gross_earned_incomeand state TANF earned-income overridesemployment_incomeonlyaca_magi=medicaid_magi= an estimate that left out Social Security/api/calculatedisagreed with/api/serieson the ACA PTC and CHIP premium.aca_magiitself adds upmedicaid_magisnap_assets(total of bank/stock/bond)spm_unit_cash_assets) and the SSI resource test (ssi_countable_resources) saw $0bank_account_assetson the head, or on a spouse who could claim SSI (65 or older, or blind) when the head couldn'tutility_expense(total of per-utility bills on 1.755.5)heating_cooling_expense(the tooltip says the app treats the bills as including heating or cooling)householdstax_unit, and api.policyengine.org rejects wrong-entity requeststax_unitsThe brief asked: can the UI set per-person
ssi_amountorssdi_amount? No. InputPanel has no control for either, share links don't carry them, anddataLookup.normalizePeoplestrips 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/maincode 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./api/calculatenow matches the chart (PTC $19,723 → $17,048 at $20k)Cliff locations and marginal rates move only where the programs above do.
final_impact.pyandimpact_report.pyin~/PolicyEngine/_analysis/cliff-watch-total-inputs-2026-09-29/produce these tables,IMPACT.mdthere 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
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
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
Cliff points: 0 now, 0 in the PR. Highest marginal tax rate: 44% now, 46% in the PR.
H4 PA 62, private pension 18k
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
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
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
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
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
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)
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
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
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
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
Cliff points: 4 now, 4 in the PR. Highest marginal tax rate: 663% now, 663% in the PR.
H15 TX 70 alone, savings 5k
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
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.
adds/subtractsunlessREVIEWED_TOTAL_INPUTSlists it with a reason (onlyemployment_incomeandself_employment_income, whichpolicyengine_us.Simulationmoves onto*_before_lsr).1a. No formula variable as input: neither builder sets a variable that has a formula unless
KNOWN_COMPUTED_INPUTSlists it with what the input replaces. A second test fails when a listed variable loses its formula, so the list can't go stale.social_security= retirement + SSDI;pension_income= private + government. Headirs_gross_income= the taxable income the user entered + Alaska PFD + the head'staxable_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).policyengineApi.jsbuildSituationsends exactly the inputscalculator.pydoes (Hypothesis throughnode), for payloads withfiling_status, a lowercaseprograms_modeand the metadata program list.6a. Differential, savings holder vs engine:
_could_claim_ssiequals the engine'sis_ssi_aged_blind_disabledfor every person the builder emits, andSSI_AGED_THRESHOLDequalsgov.ssa.ssi.eligibility.aged_threshold./api/calculateequals the/api/seriespoint at the same earnings for every displayed program, taxes and net income, to within cent rounding.POLICYENGINE_LIVE_API=1): situations from both builders round-trip through api.policyengine.org. All 5 Python live cases fail onorigin/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):The frontend test runner moves from
node --testto Vitest, and the existing tests keep their assertions. #41's.github/workflows/test.ymlruns both suites.Known limitations (unchanged here; each has a follow-up task)
household_market_incomeexcludes 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.filing_status, and the API ignoresmarital_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.childcare_expensesas 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.county_fips.meets_ssi_disability_criteriadefaults to False, so a disabled 40-year-old gets SSI $0 and a blind one $11,928.heating_cooling_expenseand changes Head Start income.axiom: n/a: cliff-watch app input mapping; no policy encoding change
🤖 Generated with Claude Code