Repository navigation
Honor supplied Medicaid exclusions and uprate foreign earned income exclusions from a shared input period - #10224
Conversation
…nputs Without Form 2555 leaf inputs, foreign_earned_income_exclusion uprated from the latest earlier period in holder.get_known_periods(), which includes years the simulation had calculated. A 2026 value computed after 2025 was uprated from the float32-rounded 2025 result instead of the 2024 input, so its bits depended on calculation order (2024 input 10,000: 11090.326171875 fresh, 11090.3271484375 after 2025). Mirror Core's uprating (policyengine-core#563, released in 3.32.17): take the latest earlier same-unit period from Holder.get_input_periods for this branch, breaking ties with Core's _latest_input_key. The legacy default, carry-over and held-flat index behaviour are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dependent
From 2027, medicaid_enrolled_for_ssi_state_supplement returned
simulation.get_array("medicaid_enrolled") whenever any value was stored,
calculated or supplied, and otherwise calculated enrollment in a private
branch with the SNAP/TANF community-engagement pass-through forced False.
A calculated medicaid_enrolled keeps the pass-through, so the result
depended on whether medicaid_enrolled had been calculated first. With SNAP
or the pass-through supplied (so the SNAP -> SSP cycle does not compute this
variable on the way), a pass-through adult got False fresh and True after
medicaid_enrolled. Under a reform that removes Indiana's SSI-recipient
Medicaid coverage, a working-age reported SSI recipient in a medical
facility falls into the adult group, and Indiana SAPN changed from $0 fresh
to $22 after medicaid_enrolled.
Read medicaid_enrolled directly only when it is a supplied input this branch
reads (Holder.get_input_periods); otherwise always use the private branch.
The recursion guard is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
foreign_earned_income_exclusion: a Hypothesis property over entered year, target year, amounts and the years calculated first asserts the target is bit-for-bit the same as asked alone and equals the entered amount uprated straight from its year; the 2024 -> 2026-after-2025 repro is an explicit @example. Example tests pin the latest-entered-year source, the held-flat index before 2015, and the default when only an unreadable branch holds an amount (previously a TypeError). medicaid_enrolled_for_ssi_state_supplement: a Hypothesis property over state, which value on the SNAP-SSP-Medicaid cycle is supplied, and the variables calculated first asserts the SSP enrollment, eligibility and benefit match a fresh simulation; the SNAP-supplied, medicaid_enrolled-first repro is an explicit @example. Example tests cover SNAP and TANF pass-through adults and an SSI recipient placed in the adult group, whose SAPN was $22 or $0 depending on order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Drop the per-unit input history. An entered year applies to every tax unit in the simulation, as it does for other inputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DTrim99
left a comment
There was a problem hiding this comment.
Program review
Base repository: PolicyEngine/policyengine-us
PR number: 10224
Reviewed head SHA: 3c14d9e
Merge base SHA: 50756f2
Mode: full
Scope: changed behavior and affected dependencies
Source manifest: /private/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-review-sources.json
Review status: COMPLETE
Source Documents
- usc26-911.html — cached original.
- irs-feie-page.html — cached original.
- rp-23-34.pdf — cached original.
- rp-24-40.pdf — cached original.
- rp-25-32.pdf — cached original.
- ecfr-435-554.html — cached original.
- in-pm-5000.pdf — cached original.
- ks-ssp-memo.pdf — cached original.
- i1040gi.pdf — cached original.
- in-rcap.html — cached original.
- usc42-1382c.html — cached original.
Critical
None.
Should Address
None.
Suggestions
S1 — The new Indiana SAPN YAML case passes with main's helper, so it does not guard the fix (OPEN)
- Location:
policyengine_us/tests/policy/baseline/gov/states/in/fssa/ssp/in_ssp_sapn.yaml:124-142. - Trigger: the policyengine-core YAML runner checks outputs in the order they are listed (
policyengine_core/tools/test_runner.py:324,for key, expected_value in output.items()). The case listsmedicaid_enrolledfirst. That calculates and stores enrollment before the SSP asks for it. Main's helper then returns the stored value, so SAPN is $22 on main as well. - Evidence:
pr-10224-review-code-diag/diag2.pyswaps main's helper formula in through a reform. Main's formula in YAML order givesmedicaid_enrolledtrue,in_ssp_sapn_eligibletrue andin_ssp_sapn22, which matches the expected values. Main's formula with the SSP first gives 0 and false. The PR formula gives 22 and true in both orders. Raw output is inpr-10224-review-code-diag/diag2.log. - Impact: none on behavior. The change already has a test that fails without it:
test_ssi_recipient_in_the_adult_group_gets_the_same_sapn_in_either_orderwithfirst=(). The YAML case only documents the end state. - Suggested fix: list
in_ssp_sapnandin_ssp_sapn_eligiblebeforemedicaid_enrolled, or drop themedicaid_enrolledoutput, so the YAML case runs the SSP-first order.
S2 — The FEIE fallback can grow an amount at the ceiling past the 911(b)(2)(D) limit (already on main) (OPEN)
- Location:
policyengine_us/variables/gov/irs/income/taxable_income/adjusted_gross_income/above_the_line_deductions/foreign_earned_income.py:24-63, the branch used when no Form 2555 inputs are supplied. The growth factor is set at lines 60-63. - Trigger: One tax unit, no Form 2555 inputs,
foreign_earned_income_exclusion= $126,500 supplied for 2024 only. That is the full 2024 ceiling for one qualifying person with no housing amount. - Expected vs observed: Under the statute the ceiling for one person becomes $130,000 in 2025 and $132,900 in 2026, a 5.06% rise over 2024 that follows C-CPI-U. When I ran this case on the snapshot, the model returned $133,989.53 for 2025, $140,292.63 for 2026 and $144,665.80 for 2027, because it grows the amount by per-capita AGI (×1.10903 from 2024 to 2026). For 2026 that is $7,392.63 more than the ceiling allows unless the person has a housing exclusion or deduction of at least that size. The model has no parameter for the section 911 ceiling, so nothing caps the grown amount.
- Impact and why it is not new here: Only exclusion amounts at or near the ceiling are overstated in years after the supplied year. Main uses the same per-capita AGI index and factor; this PR only changes which supplied year is the starting point, so it does not introduce the overstatement. Its new YAML tests use amounts well below the ceiling ($900–$10,000) and do not lock in an overstated result. The local policyengine-us-data checkout never supplies this variable, so microsimulation exposure appears limited. I did not establish this for every build.
- Severity: SUGGESTION. Follow-up: add a parameter for the 911(b)(2)(D) amount, or grow amounts at the ceiling with the statutory index. This PR does not need to change.
- Sources:
- 26 U.S.C. 911(b)(2)(A) and (D) (/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-sources/usc26-911.txt)
- Rev. Proc. 2023-34 sec. 3.39 (page 18), Rev. Proc. 2024-40 sec. 3.39 (page 18) and Rev. Proc. 2025-32 sec. 3.39 (page 25)
- IRS "Figuring the foreign earned income exclusion"
- Run: /tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-diag/feie_cap.py, output in /tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-diag/feie_cap.log (exit 0; imports resolved to the snapshot)
S3 — A new YAML test locks in a negative exclusion, which section 911 does not allow (OPEN)
- Location:
policyengine_us/tests/policy/baseline/gov/irs/income/taxable_income/adjusted_gross_income/foreign_earned_income_exclusion.yaml:21-38("Signed exclusions uprate directly from the year entered") - Trigger: A 2024 input of −$10,000 is expected to become −$11,090.33 in 2026.
- Expected vs observed: Section 911(a) lets a taxpayer elect to exclude foreign earned income and the housing cost amount. The excluded amount cannot be below zero. The model's own Form 2555 path also floors worksheet line 2c at zero ("if zero or less, enter zero"). The new case treats a negative supplied value as a legitimate amount to grow. Main already kept the sign of supplied values; the test is new.
- Impact: No effect on any lawful household. The test documents how the model handles an invalid input.
- Severity: SUGGESTION. Say in the case that it covers sign handling for an invalid input, or replace the −$10,000 with a non-negative amount.
- Sources: 26 U.S.C. 911(a), (b)(2)(A) (/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-sources/usc26-911.txt); Form 1040 instructions, Foreign Earned Income Tax Worksheet, PDF page 37 (/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-sources/i1040gi.txt).
S4 — The new SAPN test relies on an SSI recipient who is neither aged, blind nor disabled (OPEN)
- Location:
policyengine_us/tests/policy/baseline/gov/states/in/fssa/ssp/in_ssp_sapn.yaml:124-142(new case "Indiana SAPN counts Medicaid enrollment through a supplied SNAP exclusion")policyengine_us/tests/core/test_ssi_state_supplement_medicaid_dependency.py:377-417
- Trigger: The test uses a 40-year-old with
receives_ssi: trueand no blindness or disability input. It also setsis_ssi_recipient_for_medicaidto false, although Indiana is a section 1634 state, and supplies the January SNAP exclusion. - Expected vs observed: Under section 1614(a)(1), a person under 65 can get SSI only if blind or disabled. Such a person is a specified excluded individual under 42 CFR 435.554(c)(5)(i)(A), and in Indiana an SSI recipient gets Medicaid through the SSI-recipient group anyway. So in law this person is enrolled without the SNAP exclusion. The test's expected results are still correct under the sources:
medicaid_enrolledtrue, SAPN eligible, and $22 = $52 − $30 (PM 5000, page 2). Only the test's name and premise describe a route to Medicaid that a lawful SSI recipient cannot take. - Impact: None on model outputs or expected values. The test checks how the code handles a supplied input, not a situation that occurs in law. The PR body admits it simulates turning off SSI-recipient coverage.
- Severity: SUGGESTION. Add a comment saying the input combination is a modeling device, or name the test after the input-handling behavior it checks.
- Sources: 42 U.S.C. 1382c(a)(1) (/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-sources/usc42-1382c.txt); 42 CFR 435.554(b) and (c)(5)(i)(A), (c)(7) (/tmp/policyengine-command-runs/ea33c0bb2b64/pr-10224-policy-sources/ecfr-435-554.txt); Indiana Medicaid PM 5000, page 2.
S5 — YAML placement and naming conventions in the new FEIE file (OPEN)
tests/policy/baseline/gov/irs/income/taxable_income/adjusted_gross_income/foreign_earned_income_exclusion.yamlsits one directory above where it should. The variable lives in.../adjusted_gross_income/above_the_line_deductions/foreign_earned_income.py, so the mirrored test path would be underabove_the_line_deductions/.- The new case names in the FEIE file and in
in_ssp_sapn.yamllack theCase N, ... .form that cases 1-4 ofin_ssp_sapn.yamluse. - FEIE YAML cases 1 and 2 also give the same result on main: with no intermediate year calculated, main picks the same source period. They are regression guards. Case 3 (the tie-break) and the Python tests are the ones that tell the fix apart from main.
Evidence Gaps
No material gaps reported.
Notes
- Both changes do what the PR says, and results no longer depend on calculation order. The FEIE fallback now grows only from supplied inputs, the same way core 3.37.2 does its own uprating. A $10,000 input for 2024 gives the same 2026 value in the root simulation, a branch and a nested branch, even after 2025 is calculated first.
- Counting a supplied SNAP or TANF community engagement exclusion as Medicaid enrollment for state supplements is right. Indiana SAPN (PM 5000 p. 2) and Kansas SSPP require receiving Medicaid without limiting which Medicaid group counts. Under 42 CFR 435.554(b) and (c)(6)–(7), a person covered by the SNAP or TANF exclusion has no community engagement condition.
- The FEIE ceiling (policy-1) is already a problem on main and the model has no parameter for it, so it suits a follow-up issue rather than this PR.
Validation Summary
Local tests at the reviewed head (review venv, policyengine-core 3.37.2, matching uv.lock; imports resolved to the snapshot): 79 pytest tests passed (3 deselected) and 116 YAML cases passed, with 0 failures. Every other branch that changes behaviour has a test that fails on main. The all-states poverty test was left to CI because the PR doesn't change it. Sources: 11, including Rev. Procs. 2023-34, 2024-40 and 2025-32, Indiana PM 5000 and 42 CFR 435.554; the manifest check passed. CI: 35/35 checks pass at 3c14d9e.
Timing
setup seconds: 5.00s; scope seconds: 60.00s; parallel review seconds: 447.40s; policy role seconds: 368.10s; code role seconds: 447.40s; adjudication seconds: 90.00s; consolidation cleanup seconds: 1287.60s; elapsed seconds: 1888.00s
Review Severity
APPROVE. Open findings: 0 critical, 0 should address, 5 suggestions.
|
US + core hub merge audit, us#10224 at
|
Two formulas read a stored value as if it had been entered. A stored value can also be one the simulation calculated, so their results depended on what had been calculated first. This PR makes both independent of calculation order. It also lets a supplied SNAP or TANF community engagement exclusion count toward the Medicaid enrollment that SSI state supplements read.
Invariant
Order independence. For a simulation built from fixed inputs, the value of each changed variable for a period is the same whatever was calculated before it, and in whatever order. For
foreign_earned_income_exclusionwithout Form 2555 inputs, two more things hold:1.
foreign_earned_income_exclusion(no-leaf-input path)Float32 drift. The formula uprated from the latest earlier period in
holder.get_known_periods(), which includes years the simulation calculated. So 2026 computed after 2025 was uprated from 2025's float32 result, not from the 2024 input.main(a2f63c1235)The drift persists into later years: 2035 asked after 2025–2034 differed by up to 0.125 on a $1,000,003.30 input. Of six amounts, five differed bitwise for 2026.
A crash with the same cause. An amount stored only under a branch the simulation cannot read (
holder.set_input(period, value, "sibling")) was picked as the source, read back asNone, and raisedTypeError: unsupported operand type(s) for *: 'NoneType' and 'float'. It now takes the legacy default.Staggered tax-unit inputs: no change. As for other inputs, a year entered for one tax unit applies to every tax unit in the simulation. With $10,000 entered for the first unit in 2024 and $0 for the second in 2025, the 2025 array holds $0 for both, and 2026 is [0, 0]. Enter the amount for both years, or build the units separately.
Form 2555 leaf inputs: no change beyond rounding. These cases matched bitwise before and after:
has_section_911_leaf_inputschecks the active branch's visible leaf inputs across the batch. A leaf whose period starts at or before the requested period selects the leaf path whenever the formula runs.validate_section_911_batch_inputsrequires matching period coverage across tax units when a batch combines leaf and legacy inputs.Fix. Core has tracked supplied input periods since policyengine-core#563, released in 3.32.17, and PolicyEngine US requires Core 3.37.2 or later. The formula uses visible input periods and Core’s
_latest_input_key. It records the per-capita index reads on the calculating branch, asmaindoes. These behaviours are unchanged:None, so Core's carry-over or default applies;2.
medicaid_enrolled_for_ssi_state_supplementFrom 2027, the formula returned the stored
medicaid_enrolledwhenever one existed, whether supplied or calculated. Otherwise it calculatedmedicaid_enrolledin a private branch, withmedicaid_community_engagement_pass_through_eligibleforced False, to avoid the SNAP → SSP → Medicaid recursion. A calculatedmedicaid_enrolledkeeps that pass-through.Order dependence on
main. Each case below compares the value asked alone with the value aftermedicaid_enrolled(and aftersnap), using IN SAPN/RCAP and KS SSPP candidates and pass-through non-candidates.Baseline, SNAP calculated by formula: no order dependence. Calculating
medicaid_enrolledreaches this variable through pass-through → SNAP →in_ssp, beforemedicaid_enrolledis stored, so every order uses the branch.Baseline, SNAP or the pass-through supplied as an input:
medicaid_enrolled.At baseline, SSI recipients in Indiana (section 1634) and Kansas (SSI criteria) are in the
SSI_RECIPIENTcategory, which the community engagement requirement does not reach. RCAP's aged, blind or disabled candidates are exempt by age (SSI's aged threshold is 65; the requirement covers ages 19–64) or by blindness or disability.A candidate differs under a reform. With Indiana's SSI-recipient Medicaid coverage turned off (
gov.hhs.medicaid.eligibility.categories.ssi_recipient.is_covered.IN: false), a 40-year-old institutionalized SSI recipient with no disability finding falls into theADULTgroup. With the pass-through supplied, that person's SAPN depended on order:in_ssp, 2027-01medicaid_enrolledmainWith the January SNAP exclusion supplied, the Indiana adult-group recipient qualifies for SAPN. The payment is $52 − $30 = $22 whether SAPN or ordinary Medicaid enrollment is calculated first.
The non-candidate case is the same shape without the reform: an Indiana adult, 40, with $5,000 of earnings and SNAP workfare, and
snapsupplied.medicaid_enrolled_for_ssi_state_supplementgaveFalseasked alone andTrueaftermedicaid_enrolledonmain, andFalsein both orders here.Fix. The helper honors supplied Medicaid enrollment (
period in holder.get_input_periods(branch_name)). When the January SNAP or TANF exclusion (medicaid_community_engagement_pass_through_eligible) is supplied, it uses ordinary enrollment. When the model must calculate that exclusion, it computes enrollment in a private branch with the exclusion disabled to break the SNAP dependency. The recursion guard is unchanged. Across these variants, all orders now agree:medicaid_enrolledsupplied;Supplied enrollment is still honoured, including a
set_inputafter construction (test_ssp_preserves_medicaid_inputs_set_after_initialization).Not changed here
medicare_irmaa_magi_two_years_priorreads the stored 2014 exclusion without checking that it was supplied. With $10,000 entered in 2012 and no 2014 income, benefit year 2016 gives $0 on a fresh simulation and $10,000 after the 2014 exclusion is calculated. The model's documented pre-2015 fallback expects $0. This predates the PR and is left for a separate fix.Tests
Hypothesis is used for both sites, with
derandomize=True. Each property has its reproducing case as an explicit@hypothesis.example.tests/test_foreign_earned_income_exclusion_leaves.pyTypeError. Main adds two checks that record the source and target index reads in the root and in a named branch. The merged file has 33 static cases.tests/policy/baseline/gov/irs/income/taxable_income/adjusted_gross_income/foreign_earned_income_exclusion.yaml(new)year:2024:2, 2024 returns $10,000, and the later-ending input supplies 2026: $900 × 1.1090326760420632 = $998.13.tests/core/test_ssi_state_supplement_medicaid_dependency.pysnap, pass-through ormedicaid_enrolled), and up to four variables calculated first. It asserts that SSP enrollment, eligibility and benefits match a fresh simulation. The merged file has 35 static cases. Without Hypothesis only the property test skips.is_ssi_recipient_for_medicaid: False, which has the same effect as the reform above, without building a reformed system.tests/policy/baseline/gov/states/in/fssa/ssp/in_ssp_sapn.yaml: new case "Indiana SAPN counts Medicaid enrollment through a supplied SNAP exclusion":medicaid_enrolledtrue,in_ssp_sapn_eligibletrue,in_ssp_sapn$22 ($52 personal needs allowance − $30 reduced SSI − $0 other income).The adult-group example (
test_ssi_state_supplement_medicaid_dependency.py:376–417) is a new test that checks both calculation orders. It expects SSP enrollment and January SAPN eligibility to be true and annualin_sspto be $264 (12 × $22). Replaying its input on main gives false, false and $0 when SSP is calculated first, and true, true and $264 when Medicaid enrollment is calculated first. No existing expected value changed.Earlier Linux runs, one file per process, before the latest merge with main:
test_section_911_batch_inputs.pypassed 14.Test cost
Local macOS measurements at the first version of this PR. User CPU is the steadier measure.
main, for the grouptest_foreign_earned_income_exclusion_leaves.py(remaining)core/test_ssi_state_supplement_medicaid_dependency.py(heavy-a)a2f63c1235)The added cases build small situations only. The Medicaid file's peak comes from the existing all-states poverty test. No job, matrix entry or group assignment changes.
Impact
Microsimulation impact: pending.
Household results:
year:2024:2$900 second, 2026 is $998.13 here and $11,090.33 on main. A calculation that sees only another branch's $10,000 input returns $0 here; main raisesTypeError.Overlapping PRs. #9462 also edits
core/test_ssi_state_supplement_medicaid_dependency.py, and #10532 also editsin_ssp_sapn.yaml. #10164, #10170, #10161 and #10176 have merged. The merge with main keeps both Indiana SAPN cases, the broader Medicaid scope and supplied-input handling, the Section 911 eligibility helper, and the index tracing. The changed paths were traced by hand, and CI runs the suite at this head.axiom: n/a: calculation order and stored inputs; no rule changes
🤖 Generated with Claude Code