Skip to content

Fix AMT capital-gains overflow into the 20% bracket below the threshold#8293

Merged
PavelMakarchuk merged 2 commits into
mainfrom
fix-amt-cg-bracket-overflow
May 14, 2026
Merged

Fix AMT capital-gains overflow into the 20% bracket below the threshold#8293
PavelMakarchuk merged 2 commits into
mainfrom
fix-amt-cg-bracket-overflow

Conversation

@PavelMakarchuk
Copy link
Copy Markdown
Collaborator

Summary

Form 6251 Part III had two compounding bugs that produced an AMT add-on for filers whose AMTI minus exemption sat well below the 20% LTCG bracket threshold ($583,750 MFJ).

Bug 1 — Line 27 (primary): the code read loss_limited_net_capital_gains (the LTCG amount) for Form 6251 Line 27, but the form references "amount from line 5 of QDCG Worksheet or line 21 of Schedule D Tax Worksheet (as figured for the regular tax)" — i.e., the regular-tax ordinary-income portion, the same source already used for Line 20. Reading LTCG instead of ordinary income shrank the 15% bracket window from (20%-threshold − 0%-bracket-room − ordinary) down to (20%-threshold − 0%-bracket-room − LTCG), which is much smaller, so excess gains overflowed into Line 33 (the 20% bracket).

Bug 2 — Line 23/24 (structural): the code computed disregarded_gains = min(L22, L21) × cg_first_rate — the tax at the 0% bracket (always $0) — but then used it in Line 24 (L22 − L23) and Line 32 (L23 + L30) as if it were the amount. With the 0% rate this collapses to "the 0% bracket is invisible to the subsequent computation," which interacted with Bug 1 to compound the error.

Switching Line 23 to the amount and Line 27 to dwks14 (the regular-tax ordinary income, which the code already reads for Line 20) restores faithful Form 6251 math.

Fixes #8292. TAXSIM ticket: #424.

Verification

Reproducer (MFJ, $390,720 LTCG, $65,148 qualified dividends, federal AGI ~$510K, AMTI − exemption = $376,452 — well below the $583,750 20% threshold):

Year Pre-fix AMT Post-fix AMT
2018 $13,197 $0
2019 $13,027 $0
2020 $12,684 $0
2021 $12,453 $0
2022 $11,752 $0
2023 $10,025 $0
2024 $8,634 $0
2025 $8,329 $0

Form 6251 line-by-line trace for the 2024 case confirms tentative AMT = ~$46,063 (< regular tax $60,473 ⇒ AMT add-on = $0).

Test plan

  • All 55 AMT baseline tests pass (3 existing tests that locked in the pre-fix output were updated to the correct Form 6251 values; 1 new integration test added)
  • All 80 federal-income-tax baseline tests pass
  • Reproducer returns AMT = $0 across 2018-2025
  • make format clean
  • CI green

Test changes (existing tests updated)

Three amt_tax_including_cg.yaml cases asserted outputs that the buggy formula produced. Form 6251 line-by-line traces give the corrected values:

  • "Income with capital gains in first bracket": $22,700 → $18,200 (correct: 0% bracket consumes the full preferential base)
  • "AMT with capital gains in second bracket": $144,086 → $137,392.25 (correct: 0% bracket consumes $44,625; rest at 15%)
  • "AMT with unrecaptured section 1250 gains": $230,586 → $223,892.25 (same 0% consumption; §1250 piece unchanged)

🤖 Generated with Claude Code

Form 6251 Part III Line 27 references the regular-tax ordinary-income
portion (QDCG Worksheet line 5 or Schedule D Tax Worksheet line 21).
The code instead read `loss_limited_net_capital_gains` (the LTCG
amount itself), which shrank the 15% bracket window and pushed gains
into the 20% bracket even when AMTI minus exemption sat far below
the $583,750 MFJ threshold. Line 23 was also storing the tax (= $0
at the current 0% rate) instead of the amount, which the form re-uses
in Line 24 and Line 32.

Both errors compounded across all years 2018-2025. Switching Line 23
to the amount and Line 27 to `dwks14` (already used for Line 20)
restores faithful Form 6251 math.

Updated three existing tests that locked in the pre-fix output and
added an integration test reproducing the taxsim #424 case.

Fixes #8292

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8cb60e7) to head (ddd5a38).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8293   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         1    -2     
  Lines           63        41   -22     
=========================================
- Hits            63        41   -22     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Five new cases exercise:
- 0% bracket threshold (entire base in 0%)
- 20% bracket threshold (entire base at 15%)
- Above 20% threshold (real 20% bracket usage)
- Mixed preferential + non-zero regular-tax ordinary income
  (locks in the Line 27 fix specifically)
- Joint filer with substantial cap gains below joint 20% threshold

Each test's expected value was manually computed from Form 6251
Part III line-by-line and matches PE output to the cent. All 60
AMT tests and 821 federal-income tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

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

Reviewed the AMT line-mapping change and boundary tests. The patch keeps Line 23 as an amount for later Form 6251 lines, switches Line 27 to the regular-tax ordinary-income value, and adds tests covering the 0%/15%/20% capital-gains boundaries plus the TAXSIM reproducer. No blockers from my review.

@PavelMakarchuk PavelMakarchuk merged commit 44f8a93 into main May 14, 2026
25 checks passed
@PavelMakarchuk PavelMakarchuk deleted the fix-amt-cg-bracket-overflow branch May 14, 2026 13:43
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.

AMT applies 20% capital gains rate below the $583,750 MFJ threshold

2 participants