Skip to content

Make above-the-line deduction sums deterministic - #9446

Merged
MaxGhenis merged 1 commit into
mainfrom
max/ald-deterministic-order-20260912
Sep 12, 2026
Merged

Make above-the-line deduction sums deterministic#9446
MaxGhenis merged 1 commit into
mainfrom
max/ald-deterministic-order-20260912

Conversation

@MaxGhenis

Copy link
Copy Markdown
Contributor

Why

adjusted_gross_income_person and student_loan_interest_ald_magi build their list of tax-unit deductions as list(set(all_alds) - set(PERSON_ALDS)). Set iteration order over strings follows the process hash seed, so the float32 accumulation order, and therefore the last digits of AGI, could differ between processes. The canonical SPM acceptance matrix's seed-invariance (byte-identical vectors under PYTHONHASHSEED 0 and 42) rests on the accepted candidate wheel having this fix; the fix lived on the determinism branch and never reached the merged #9428, so the published 2.0.0 sums in hash-seed order.

What

  • sorted(...) in both formulas (two lines).
  • policyengine_us/tests/core/test_ald_determinism.py: both formulas, with and without deductions, in both list orders, plus a subprocess check under two hash seeds.
  • Changelog fragment (fixed).

The candidate's exact policyengine-core==3.32.5 pin is deliberately not ported: the wrapper bundle pins core exactly; the country keeps >=3.30.1.

Verification

uv run python -m pytest policyengine_us/tests/core/test_ald_determinism.py: see the run recorded below the fold in the rollout runbook; ruff format check clean.

🤖 Generated with Claude Code

Person-level adjusted gross income and the student-loan-interest MAGI built
their list of tax-unit deductions from a set difference, so the float32
accumulation order followed the process hash seed and results could differ
across runs at the last digits. Sort the unique deduction names instead.

This is the fix the accepted canonical candidate wheel carried (the acceptance
matrix's seed-invariance rests on it) but which never reached the merged
branch; the published 2.0.0 sums in hash-seed order. The regression tests
cover both formulas, with and without deductions, in both orders, and a
subprocess check across two hash seeds.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.29%. Comparing base (f9b5549) to head (064c3c9).
⚠️ Report is 69 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##              main    #9446       +/-   ##
============================================
- Coverage   100.00%   62.29%   -37.71%     
============================================
  Files            2        2               
  Lines           20       61       +41     
  Branches         0        3        +3     
============================================
+ Hits            20       38       +18     
- Misses           0       22       +22     
- Partials         0        1        +1     
Flag Coverage Δ
unittests 62.29% <100.00%> (-37.71%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@MaxGhenis
MaxGhenis merged commit 328b34d into main Sep 12, 2026
34 of 35 checks passed
@MaxGhenis
MaxGhenis deleted the max/ald-deterministic-order-20260912 branch September 12, 2026 03:16
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.

1 participant