Skip to content

Conversation

@policyengine
Copy link
Contributor

@policyengine policyengine bot commented Dec 12, 2025

Summary

Adds three critical patterns learned from recent PolicyEngine-US bug fixes:

  1. Edge case testing pattern for negative income scenarios (from WV homestead credit #6948)
  2. Bracket parameter pattern for handling negative values (from HI Food/Excise Tax Credit #6953)
  3. Subtraction flooring pattern using max_() (from MT income tax #6965)

Changes

Testing Patterns (from #6948)

  • Added "Tax Credit Programs" section with specific edge cases for tax credits
  • Emphasizes testing negative income combined with zero expenses/deductions
  • Documents pattern that caught a real bug where eligibility logic used > instead of >=

Parameter Patterns (from #6953)

  • Added "Bracket-Based Parameters" section to parameter patterns skill
  • Documents that first bracket threshold must be -.inf (not 0) when negative values are valid
  • Provides clear examples of wrong vs correct patterns
  • Explains when to use -.inf vs when 0 is appropriate

Vectorization Patterns (from #6965)

  • Added Pattern 5: Flooring Subtraction Results to vectorization skill
  • Documents correct use of max_() when subtracting and flooring at zero
  • Real example: Montana income tax "phantom income" bug with capital losses
  • Pattern: max_(A - B, 0) NOT max_(A, 0) - B
  • Added to Quick Reference Card

Context

Testing edge case (#6948): WV homestead excess property tax credit incorrectly calculated $120 refund when household income was negative AND property tax paid was $0. TaxAct correctly showed $0, highlighting the importance of this edge case.

Bracket threshold pattern (#6953): Hawaii Food/Excise Tax Credit used 0 as first bracket threshold, incorrectly excluding taxpayers with negative AGI. Using -.inf correctly handles all cases including business losses.

Subtraction flooring pattern (#6965): Montana income tax used max_(income, 0) - capital_gains which created phantom taxable income when capital losses occurred. The correct pattern max_(income - capital_gains, 0) properly floors the entire subtraction result at zero.

All three are subtle but important patterns that will help prevent similar bugs in future implementations.

🤖 Generated with Claude Code

PolicyEngine-Bot and others added 2 commits December 12, 2025 15:12
Adds critical edge case pattern discovered from WV homestead credit bug:
- Negative household income combined with zero deductible expenses
- This combination often reveals incorrect eligibility calculations
- Tax credits need to handle this case explicitly

Real-world example: WV homestead excess property tax credit incorrectly
calculated $120 credit when income was negative and property tax was $0.
The bug was in eligibility logic that didn't properly handle negative
income thresholds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add critical guidance for bracket-based parameters where negative input
values are possible (e.g., AGI can be negative). The first bracket threshold
must be -.inf rather than 0 to correctly handle all cases.

Based on learning from PolicyEngine/policyengine-us#6953 (Hawaii Food/Excise
Tax Credit), where using 0 as the first threshold incorrectly excluded
taxpayers with negative AGI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@policyengine policyengine bot changed the title Add negative income + zero expenses edge case pattern Add negative income edge cases and bracket threshold patterns Dec 12, 2025
Documents critical pattern: state income taxes should reference federal
income sources (like adjusted_gross_income) rather than redefining
income sources at the state level.

This prevents bugs like PolicyEngine/policyengine-us#6964 where
Mississippi incorrectly allowed unlimited capital losses because it
bypassed federal capital loss limits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@policyengine
Copy link
Contributor Author

policyengine bot commented Dec 14, 2025

Additional learning: State income tax conformity

Added new guidance on state income tax conformity to federal rules.

Key pattern documented:
State income taxes should reference federal income sources (adjusted_gross_income, taxable_income, etc.) rather than redefining income aggregation at the state level.

Context:
This emerged from fixing PolicyEngine/policyengine-us#6964, where Mississippi incorrectly allowed unlimited capital losses because it bypassed federal capital loss limits by defining its own income_sources.yaml parameter.

Changes:

  • Added "State Income Tax Conformity to Federal Rules" subsection to policyengine-implementation-patterns-skill
  • Documents correct pattern: federal base + state additions/subtractions
  • Explains common conformity patterns and why this matters
  • Includes examples of correct vs incorrect implementations

This will help prevent similar bugs in future state income tax implementations.

PolicyEngine-Bot and others added 3 commits December 14, 2025 15:05
Discovered from MT income tax bug fix: when subtracting values and
flooring at zero, must wrap entire subtraction in max_(), not just
one operand.

Pattern prevents "phantom income" bugs where max_(income, 0) - loss
can produce negative results when loss > income.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Captures learning from Montana income tax bug fix (PolicyEngine/policyengine-us#6947):
- Phantom non-zero tax despite zero taxable income
- Root causes: type conversion issues and missing zero-income short-circuits
- Debugging steps for tracing calculation chains

This pattern will help future sessions diagnose similar state tax calculation bugs more quickly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
When implementing state tax credits and income-based programs, statutes
often specify modified income definitions (e.g., "AGI plus exemptions")
rather than standard measures. This is a common source of bugs.

Added warnings and examples to:
- implementation-validator: validation checklist for income measures
- document-collector: guidance on capturing exact income definitions

Real-world example: Arizona Family Tax Credit uses "AGI plus exemptions"
per ARS 43-1073, not just AGI alone.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants