Skip to content

Let modified AGI for taxing Social Security go below zero - #11370

Open
peyton-thalman wants to merge 3 commits into
PolicyEngine:mainfrom
peyton-thalman:fix-ss-magi-negative
Open

peyton-thalman wants to merge 3 commits into
PolicyEngine:mainfrom
peyton-thalman:fix-ss-magi-negative

Conversation

@peyton-thalman

@peyton-thalman peyton-thalman commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #11369

What

taxable_ss_magi floored modified AGI at zero. 26 U.S.C. 86(b)(2) and the Form 1040 Social Security Benefits Worksheet have no floor, so when income other than Social Security is below zero (for example a 3,000 net capital loss with nothing else), combined income and taxable benefits came out too high.

Changes

  • taxable_ss_magi.py drops the max_(0, ...) and cites 86(b)(2) and the worksheet (2025 Form 1040 instructions, file page 32).
  • wi_itemized_deduction_credit_social_security_adjustment.py drops the shortfall add-back, which only existed to undo the floor and would otherwise count the negative amount twice. The Wisconsin modified AGI is now magi + adjustment.
  • wi_itemized_deduction_credit.yaml changes one expected value, taxable_ss_magi in "Wisconsin's dependent care difference is added to modified AGI below zero" (renamed from "...added before the floor..."), from 0 to -500. Its taxable Social Security (0), AGI (-500) and every Wisconsin output (2,500, 1,000, 3,000, 1,500) are unchanged.
  • Two new cases in taxable_ss_magi.yaml (single and joint) with the worksheet arithmetic in comments.
  • Changelog fragment changelog.d/fix-ss-magi-negative.fixed.md.

Expected values

Case Variable Old New Source
single, 60,000 benefits, -3,000 LTCG taxable_ss_magi 0 -3,000 86(b)(2)
same tax_unit_taxable_social_security 2,500 1,000 Worksheet lines 3, 5, 7, 9 to 18 (27,000 combined, 2,000 over base, half)
same adjusted_gross_income -500 -2,000 -3,000 + 1,000
joint, 85,000 benefits, 800 interest, -3,000 LTCG taxable_ss_magi 0 -2,200 86(b)(2)
same tax_unit_taxable_social_security 5,250 4,150 40,300 combined, 8,300 over 32,000, half

Tax-Calculator 6.8.5 gives 1,000 taxable and -2,000 AGI for the single case.

Tests run locally

  • taxable_ss_magi.yaml, dependent_taxable_ss_magi.yaml, dependent_taxable_social_security.yaml, tax_unit_combined_income_for_social_security_taxability.yaml, calcfunctions/taxable_social_security.yaml, wi_itemized_deduction_credit.yaml, tax_unit_taxable_social_security_pre_1993.yaml (85 cases) pass.
  • test_capital_gain_distributions_loss_limit.py, test_modified_agi_add_backs.py, core/test_dependent_above_the_line_deductions_invariants.py (31 tests) pass.
  • Partner contract tests (policyengine_us/tests/policy/baseline/partners, 144 files, 4 batches) pass unchanged. No partner case has income below zero. Correction by an agent for a maintainer: partners/analytics_coverage/edge_cases/federal/tax_credits/cdcc/federal.yaml expects -5,000 AGI, but that case has no Social Security, so this change does not move it.
  • No source conflict. The statute and the worksheet agree.

axiom: needed

🤖 Generated with Claude Code

26 U.S.C. 86(b)(2) defines it as adjusted gross income with certain items
added back, and the Form 1040 Social Security Benefits Worksheet combines the
income lines, capital loss included, without a floor. Wisconsin's itemized
deduction credit no longer needs to add back the hidden shortfall.

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

@DTrim99 DTrim99 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Program review

Base repository: PolicyEngine/policyengine-us
PR number: 11370
Reviewed head SHA: d29b819
Merge base SHA: ab596b0
Mode: full
Scope: changed behavior and affected dependencies
Source manifest: /private/tmp/policyengine-command-runs/ea33c0bb2b64/pr-11370-review-sources.json
Review status: COMPLETE

Source Documents

Critical

None.

Should Address

A1 — IRA 219(g) recomputation of taxable Social Security keeps the zero floor this PR removes (OPEN)

  • Location: policyengine_us/variables/gov/irs/income/taxable_income/adjusted_gross_income/above_the_line_deductions/ira/ira_219g_taxable_social_security.py:55 (ss_magi = max_(0, gross - total_deductions)). Its docstring says it uses the "same inputs and thresholds as the engine's taxable_ss_magi / tax_unit_taxable_social_security". Pub. 590-A Appendix B Worksheet 1, which it cites, combines the income lines with no floor, as the Form 1040 worksheet does.
  • Trigger and observed (executed): after this PR, the two copies disagree whenever MAGI before the IRA deduction is below zero. With no IRA contribution, ira_219g_taxable_social_security vs tax_unit_taxable_social_security: case A 2,500 vs 1,000; case B 5,250 vs 4,150; case H 8,500 vs 7,225. ira_219g_magi in case A is -500, while AGI is -2,000.
  • Impact (traced, not executed): the single and joint phase-outs start at $81,000 and $129,000 (2026). With MAGI below zero, 219(g) MAGI is roughly taxable benefits, which are at most about $20,000, so those filers are unaffected. MFS filers living together have a phase-out from $0 to $10,000 (phase_out/start.yaml SEPARATE: 0), and they are affected. Example: an MFS active participant age 68 living with the spouse, with 7,000 wages, a 10,000 rental loss, 20,000 benefits and a 7,000 IRA contribution. Correct 219(g) MAGI is -3,000 + 5,950 = 2,950, giving a deductible limit of about 6,070. The floored copy gives -3,000 + 8,500 = 5,500 and about 3,870, so the IRA deduction is understated by about 2,200. This defect predates the PR: ira_219g_* values are identical PR vs base in every executed case. The PR fixes the same statutory point in one copy and leaves the other inconsistent, which also makes its docstring wrong.
  • Fix: drop the max_(0, ...) at line 55 (or reuse taxable_ss_magi_before_floor minus the 219(g)-excluded deductions), and add a test for MFS filers living together.
  • Proposed severity: SHOULD ADDRESS. It is a same-rationale consistency fix in the sibling path. The deduction impact is traced only, and it falls outside the changed lines.

Coordinator assessment: The policy review found the same thing independently. Section 219(g)(3)(A)(i) applies section 86 with the IRA deduction disregarded, 86(b)(2) has no floor, and the file's docstring says it mirrors taxable_ss_magi. The defect predates this PR. I'm asking for it here because the PR's premise, that 86(b)(2) has no floor, applies equally, and leaving the mirror floored makes the two section 86 computations disagree: 2,500 vs 1,000 taxable benefits in the single case. Dropping max_(0, ...) at line 55 and adding the MFS-living-together case from the report is a small change.

A2 — No test for Wisconsin modified AGI that stays below zero after the adjustment (OPEN)

  • Location: wi_itemized_deduction_credit_social_security_adjustment.py:64 (wi_magi = magi + adjustment; the outer max_(0, ...) is removed).
  • Trigger: taxable_ss_magi + wi_itemized_deduction_credit_income_adjustment < 0 with benefits high enough that a zero floor would cross the base. The only Wisconsin test that touches this has wi_magi = 2,000 > 0, so restoring the outer floor would not fail any test.
  • Observed (executed, case D): the adjustment is 1,000 on the PR (WI MAGI -1,000, combined 27,000, minus federal 0) and 0 on base. The contribution base is 0 on the PR and 500 on base. Restoring only the outer floor would give 1,500 (code trace). The PR value is the one consistent with the no-floor rule. The credit and WI tax are 0 and -115.60 on both, so this case changes no final tax.
  • Fix: add case D (rental income -12,000, social_security_disability 56,000, otherwise the existing case): expected taxable_ss_magi -3,500, tax_unit_taxable_social_security 0, adjustment 1,000, contribution base 0.
  • Proposed severity: SHOULD ADDRESS (missing coverage on a changed branch).

Suggestions

S1 — taxable_ss_magi_before_floor names a floor that no longer exists (OPEN)

  • Location: taxable_ss_magi.py:4. The only remaining caller is line 66, now that the Wisconsin import is removed.
  • Fix: inline it into the formula or rename it (for example, taxable_ss_magi_amount). If code-1 is fixed by reusing the helper, rename it instead of inlining.
  • Proposed severity: SUGGESTION.

Evidence Gaps

No material gaps reported.

Notes

  • Thanks for the careful write-up. The core change is right:
    • 26 U.S.C. 86(b)(2) and the Form 1040 Social Security Benefits Worksheet have no floor on modified AGI.
    • The PR's expected values follow the worksheet line by line. The single case gives combined 27,000, 2,000 over the base and 1,000 taxable. The joint case gives 40,300, 8,300 over 32,000 and 4,150 taxable.
    • The Wisconsin change counts the negative once, so every Wisconsin output in the existing case is unchanged.
  • Every reader of taxable_ss_magi handles a negative value safely: combined income, the pre-1993 path, taxsim_v12, Wisconsin, and CT through the floored excess. Results with positive MAGI match main exactly in the executed cases, and each new test assertion fails under the old formulas.
  • In the data, the change can only lower taxable Social Security and AGI, or leave them unchanged. The records that move are high-benefit recipients with net losses, plus MFS filers living together.
  • Optional: the unversioned i1040gi.pdf link will move to the 2026 instructions. The pinned irs-prior/i1040gi--2025.pdf would keep the page number stable.
  • The axiom line is acceptable for an external contribution under CLAUDE.md.

Validation Summary

Local tests at the reviewed head (review venv, policyengine-core 3.37.2, matching uv.lock; imports resolved to the snapshot): 106 YAML cases (the seven files the PR lists plus the IRA 219(g), IRA phase-out and taxsim_v12 regressions) and 31 pytest tests passed, 0 failed. Diagnostics executed 8 households under the PR and merge-base formulas. Sources: 26 U.S.C. 86 and 219(g), the 2025 Form 1040 instructions (Social Security Benefits Worksheet), Pub. 915 and Wis. Stat. 71.07(5); manifest check passed. CI: 36/36 checks pass at d29b819.

Timing

setup seconds: 12.00s; scope seconds: 60.00s; parallel review seconds: 1330.90s; policy role seconds: 192.90s; code role seconds: 1330.90s; adjudication seconds: 90.00s; consolidation cleanup seconds: 34.70s; elapsed seconds: 1483.00s

Review Severity

COMMENT. Open findings: 0 critical, 2 should address, 1 suggestions.

…view tests

- ira_219g_taxable_social_security: no floor on modified AGI, matching
  taxable_ss_magi (26 U.S.C. 86(b)(2), Pub. 590-A Worksheet 1). Tests for a
  single filer below zero and for separate filers living together.
- Wisconsin: test where modified AGI stays below zero after the adjustment.
- Rename taxable_ss_magi_before_floor to taxable_ss_magi_amount.

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

Copy link
Copy Markdown
Author

Thanks for the thorough review. All three points are addressed in 0f0be0d:

  • A1. Dropped the max_(0, ...) in ira_219g_taxable_social_security, so both section 86 computations now agree. Added two tests: a single filer below zero with no IRA contribution, where both give 500, and your MFS-living-together case, which gives 219(g) MAGI 2,950, a deductible limit of 6,070 and a deduction of 6,070. Both fail with the floor restored.
  • A2. Added your case D to wi_itemized_deduction_credit.yaml: taxable_ss_magi -3,500, adjustment 1,000, contribution base 0.
  • S1. Renamed the helper to taxable_ss_magi_amount.

The changelog now mentions the 219(g) path. Locally, the IRA and Social Security YAML folders, the two edited files and the IRA pytest files all pass.

@MaxGhenis

Copy link
Copy Markdown
Contributor

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

Round 2 at 0f0be0d. The IRA change, Wisconsin case D and the rename read correctly. With the floor gone, two older omissions in taxable_ss_magi now change results. The new IRA copy handles both, so the two paths disagree.

  1. Taxable basic income. taxable_ss_magi_amount leaves out basic_income when gov.contrib.ubi_center.basic_income.taxable is on. adjusted_gross_income and ira_219g_taxable_social_security both add it.
    • Example: 2026, single, age 68, $3,000 of taxable basic income, a $3,000 capital loss and $60,000 of benefits.
    • Expected: MAGI $0, combined income $30,000, taxable benefits $2,500.
    • The head gives -$3,000, $27,000 and $1,000. The floor hid this before.
    • Fix: add the two lines the IRA copy uses.
  2. Section 222 before 2021. Through 2020, section 86(b)(2)(A) set MAGI "without regard to this section and sections 135, 137, 221, 222, 911, 931, and 933" (2019 U.S. Code, 26 U.S.C. 86). revoked_deductions.yaml doesn't list capped_qualified_tuition_expenses_ald, so 2020 MAGI subtracts it.
    • Example: 2020, single, age 68, a $3,000 tuition and fees deduction and $60,000 of benefits.
    • Expected: MAGI $0, taxable benefits $2,500, AGI -$500.
    • The head gives -$3,000, $1,000 and -$2,000.
    • Fix: add the deduction to revoked_deductions. It is zero from 2021, so one entry covers every year.

Suggested tests (hand values; both fail at this head):

- name: Taxable basic income offsets a loss before section 86.
  period: 2026
  input:
    gov.contrib.ubi_center.basic_income.taxable: true
    age: 68
    state_code: TX
    basic_income: 3_000
    long_term_capital_gains: -3_000
    social_security_retirement: 60_000
  output:
    taxable_ss_magi: 0
    tax_unit_taxable_social_security: 2_500
    ira_219g_taxable_social_security: 2_500

- name: Section 86 disregards the tuition and fees deduction in 2020.
  period: 2020
  input:
    age: 68
    state_code: TX
    qualified_tuition_expenses: 3_000
    social_security_retirement: 60_000
  output:
    capped_qualified_tuition_expenses_ald: 3_000
    taxable_ss_magi: 0
    tax_unit_taxable_social_security: 2_500
    adjusted_gross_income: -500

Minor: taxable_ss_magi.py still cites law.cornell.edu for section 86. The official text is on govinfo (2024 U.S. Code, 26 U.S.C. 86).

CI hasn't run at this head. The fork run is waiting for a maintainer's approval.

… 222 and 199 in their years

From the round 2 review. With the floor gone these omissions change results.

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

Copy link
Copy Markdown
Author

Thanks, both confirmed against the govinfo editions of section 86 and fixed in a1545a2.

  1. taxable_ss_magi_amount now adds taxable basic income, the same two lines as the IRA copy.
  2. revoked_deductions now has dated values. capped_qualified_tuition_expenses_ald is disregarded through 2020 (Pub. L. 116-260, div. EE, section 104(b)). The same list was also missing section 199, which section 86(b)(2)(A) named for years after 2004 until Pub. L. 115-97 struck it for years after 2017, so domestic_production_ald is disregarded for 2005 to 2017. It follows the pattern in the student loan excluded_alds.yaml. domestic_production_ald is uprated in the data, so a single undated entry would have changed later years.

Your two tests are added, plus one for section 199 in 2017. All three fail at 0f0be0d. The section 86 references now point to govinfo, and the 1040 instructions link is pinned to the 2025 edition. Locally, the Social Security, dependent income and IRA YAML folders (117 cases) and the IRA and capital gain pytest files (45) pass.

@MaxGhenis

Copy link
Copy Markdown
Contributor

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

Round 3 at a1545a2. Both round 2 fixes and the citations read correctly. By hand, the 2026 and 2020 fixtures give MAGI $0, combined income $30,000 and taxable benefits $2,500, and the 2017 section 199 fixture gives AGI -$500.

One change before merge:

  • Changelog dates. The fragment says MAGI disregards the section 199 deduction "from 2005 through 2017". revoked_deductions.yaml and the above-the-line list both start in 2010, so the model's change starts there. Suggested wording: "from 2010, where the model's deduction lists begin, through 2017".

Not blocking:

  • Basic income with an AGI limit. With basic_income.taxable and agi_limit.in_effect both on, taxable_ss_magi now reads basic_income, whose eligibility reads AGI, which reads taxable benefits. On main, AGI already reads basic_income under the same two switches, so a full tax calculation loops either way. Only a standalone section 86 run, with the gross income sources and deduction list overridden, worked before and loops now. That cycle belongs in its own issue.
  • Tests. Two optional additions. Let the 2026 case compute basic_income from gov.contrib.ubi_center.basic_income.amount.person.flat: 3000 and assert adjusted_gross_income: 2500. Add 2018 and 2021 cases that restore each deduction by reform, so the end dates are tested; each gives MAGI -$3,000, taxable benefits $1,000 and AGI -$2,000.

CI hasn't run at this head. The fork run is waiting for a maintainer's approval.

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.

Modified AGI for taxing Social Security is floored at zero, so a net capital loss larger than other income raises taxable benefits

3 participants