Fix AMT capital-gains overflow into the 20% bracket below the threshold#8293
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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>
MaxGhenis
approved these changes
May 14, 2026
Contributor
MaxGhenis
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
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
make formatcleanTest changes (existing tests updated)
Three
amt_tax_including_cg.yamlcases asserted outputs that the buggy formula produced. Form 6251 line-by-line traces give the corrected values:🤖 Generated with Claude Code