Skip to content

Fix leakage in constrained non-household amount targets#765

Merged
anth-volk merged 6 commits intomainfrom
maria/entity_leakage_fix
Apr 18, 2026
Merged

Fix leakage in constrained non-household amount targets#765
anth-volk merged 6 commits intomainfrom
maria/entity_leakage_fix

Conversation

@juaristi22
Copy link
Copy Markdown
Collaborator

@juaristi22 juaristi22 commented Apr 16, 2026

Fixes #763

Summary

The unified calibration matrix builder was leaking non-qualifying dollars into constrained amount targets whose native entity is not household. Before this change, the builder would pre-aggregate those targets to household, evaluate constraints at person level, promote the result to a household-level any(), and then assign the full household amount whenever any qualifying person was present. In mixed-eligibility households, that overstated rows such as filer-only total_self_employment_income.

What This Changes

This PR changes constrained non-household amount targets to be filtered at their native entity before they are rolled up to household contributions in the matrix.

Concretely, the builder now:

  • records each target variable's native entity (person, tax_unit, spm_unit, or household)
  • precomputes non-household amount targets both at household level and at their native entity level during state and county precomputation
  • builds reusable entity-to-household and person-to-entity index maps for person, tax-unit, and SPM-unit targets
  • assembles clone-level entity arrays alongside household and person arrays
  • updates _calculate_target_values_standalone() so baseline constrained amount targets with non-household native entities select qualifying entity amounts first and only then sum those qualifying amounts back to household

This preserves the existing behavior for household-native amount targets and leaves count-target semantics unchanged.

Effect On Issue #763

For the motivating case from the issue:

  • Person A: total_self_employment_income = 10,000, filer
  • Person B: total_self_employment_income = 5,000, non-filer

The constrained filer-only target now contributes 10,000 instead of the previous 15,000. More generally, any constrained amount target whose native entity is person, tax_unit, or spm_unit now includes only qualifying entity amounts.

Regression Coverage

This PR adds regression tests covering:

  • person-entity amount targets filtering before household rollup
  • tax-unit amount targets contributing once per qualifying unit
  • household-native amount targets preserving current household any() semantics
  • person-entity amount targets remaining scoped to the correct household
  • SPM-unit amount targets contributing once per qualifying unit
  • count targets preserving existing entity-aware behavior

@anth-volk
Copy link
Copy Markdown
Collaborator

Integ tests take long enough that I ported two minor CI/CD fixes from #749 to this PR.

juaristi22 and others added 6 commits April 18, 2026 00:07
Evaluate constrained person-, tax-unit-, and SPM-unit amount targets at their native entity before rolling amounts up to households in the unified matrix builder, preventing mixed-eligibility households from leaking non-qualifying dollars into rows such as filer-only total_self_employment_income.
@anth-volk anth-volk force-pushed the maria/entity_leakage_fix branch from c140707 to 755257c Compare April 17, 2026 22:17
@anth-volk
Copy link
Copy Markdown
Collaborator

Taking liberty of merging. Error is spurious ACA issue previously identified.

@anth-volk anth-volk merged commit 2141ee4 into main Apr 18, 2026
8 of 9 checks passed
@anth-volk anth-volk deleted the maria/entity_leakage_fix branch April 18, 2026 01:49
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.

Calibration matrix builder leaks non-qualifying entity amounts into constrained non-household amount targets

2 participants