Skip to content

Tax NZ Superannuation and Jobseeker Support - #33

Draft
MaxGhenis wants to merge 6 commits into
mainfrom
benefit-income-tax
Draft

MaxGhenis wants to merge 6 commits into
mainfrom
benefit-income-tax

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Agent-written for Max, by Claude Code for Max Ghenis.

Part of #18. This PR carries out steps 2 and 3 of its plan. It meets step 4 in the documentation only, since no variable gives income after tax yet, and step 5 for Jobseeker Support, whose rate metadata now says the rates come before the income test and that the model assumes MSD pays the tax on them. The Jobseeker Support variable already called its amount net cash and now names that assumption, and the NZ Super rates were already labelled gross. Main already reads a bare year as the tax year ending 31 March, which settles step 1. Step 6, the Working for Families income measure, follows in a separate PR.

What this fixes

taxable_income added employment, self-employment and investment income and nothing else, so a person on NZ Superannuation or Jobseeker Support paid no income tax on it. The Income Tax Act 2007 makes both income: a main benefit under section CF 1(1)(c) and NZ Superannuation under section CF 1(1)(e).

Changes

  • taxable_income adds nz_superannuation, which the rates already give gross, from the 2022-23 tax year (period 2023).
  • The new jobseeker_support_tax is the income tax that the model assumes MSD pays on Jobseeker Support. Section 350(2) of the Social Security Act 2018 lets MSD pay that tax to Inland Revenue instead of deducting it, section 350(3) computes it on the payment grossed up so that what remains after tax equals the payment, and section 351(b)(iv) makes it the person's income. taxable_income adds jobseeker_support and this tax.
  • grossed_up_tax inverts the tax schedule in closed form. It adds up, bracket by bracket and in exact rational arithmetic, the tax on each full bracket and the amount that bracket leaves after tax. It compares the payment with those exact amounts to find its bracket, and adds the tax at the bracket's threshold to the payment's excess over the bracket's lowest amount after tax, times the bracket's rate over one minus that rate. For a finite payment, the result lies within four units in the last place of the exact tax on the converted thresholds and rates, or within 1e-300 of it where a subnormal float loses precision. A payment at or below zero gives no tax, and a NaN gives NaN. It raises a ValueError for a schedule it cannot invert (thresholds and rates that are not one-dimensional or differ in shape, no brackets, a NaN or infinite threshold, a first threshold other than 0, thresholds that do not rise, or a rate that is NaN or outside [0, 1)) and for a tax more than four units in the last place above the largest 64-bit float, and it may raise one for a tax within four such units of that float. It raises no FloatingPointError under any NumPy error setting. It reads the thresholds and rates as NumPy converts them to 64-bit floats and checks the converted arrays, which for the model's schedule are the brackets Core builds for the period.
  • jobseeker_support_tax raises a TypeError when a reform makes the income tax schedule anything other than a marginal-rate scale, such as a linear average-rate scale, which the gross-up cannot invert.
  • The model offsets a loss in one modelled source against the others and floors the total at zero (sections BC 4 and BC 5), so a self-employment loss now reduces taxable income that includes a benefit.
  • For a period that starts before 1 April 2022, when the benefit rates start, nz_superannuation and jobseeker_support raise an error for everyone unless an amount is given, so taxable income keeps the three old sources and leaves out both benefits, as before. It raises a ValueError for the whole calculation when receiving_nz_super or receiving_jobseeker_support marks anyone as a recipient. Core reads the two flags as it reads any input. An amount of either benefit given for such a period without a flag stays out of taxable income, as on main. Period 2022 still taxes other income as before.
  • The documentation of income_tax, jobseeker_support, the Jobseeker Support rates and the README now says that the model assumes MSD pays the tax on Jobseeker Support. It describes income_tax as the year's liability before credits and jobseeker_support_tax as a separate estimate of what MSD pays. The README and the docs say that income tax starts in 2021-22 and that the two benefits enter it in 2022-23. The README now gives the schedule for each tax year, and its clause 1(d) example now leaves out the people clause 1(c) covers. The changelog fragment for the NZ Super rates no longer says that no variable reads nz_superannuation.

Assumptions and limits

  • The model assumes MSD uses its section 350(2) power for every Jobseeker Support recipient, as NZ Superannuation and Jobseeker Support are left out of taxable income #18's plan proposed.
  • It grosses up the year's jobseeker_support on the personal tax schedule for the tax year, apart from the person's other income. Section 350(3) uses the rate that the Commissioner determines for each payment, in consultation with MSD's chief executive, under section RD 11(3), so the tax on each payment can differ from this annual figure. For 2024-25, the annual gross-up uses the year's composite schedule.
  • The model grosses up each partner's share of a couple rate as that partner's own payment, since regulation 191(4) of the Social Security Regulations 2018 makes each share that partner's income.
  • No variable gives income after tax, so nothing yet subtracts income_tax from benefits. income_tax - jobseeker_support_tax is the balance after MSD's payment, and it is negative when a loss brings the liability below that payment: $19,372.60 of Jobseeker Support beside a $40,000 self-employment loss gives $2,785.70 of jobseeker_support_tax and no income_tax.
  • family_income still leaves out both benefits, so Working for Families is unchanged.

Tests

test_benefit_income_tax.yaml holds #18's cases 1 to 6 for 2026-27, to the cent, with each derivation from Table 1 in a comment:

Case Inputs taxable_income income_tax
1 Age 70, NZ Super, living alone 33,663.24 4,799.07
2 Case 1 and $30,000 of wages 63,663.24 11,319.47
3 Age 70, NZ Super, with a partner who earns $30,000 25,591.28; the partner's 30,000 3,386.47; the partner's 4,158
4 Jobseeker Support of $19,372.60 22,158.30 2,785.70, all paid by MSD
5 Case 4 and $10,000 of wages 32,158.30 4,535.70, of which MSD pays 2,785.70
6 $30,000 of wages 30,000 4,158

It also covers a Jobseeker grant at the clause 1(d) rate, which gives case 4's figures; a $40,000 self-employment loss beside NZ Super, which gives 0; the same loss beside case 4's Jobseeker Support, which leaves $2,785.70 of jobseeker_support_tax and no income_tax; and NZ Super in 2022-23, which gives $3,917.98 of tax.

The YAML cases compare to a cent.

test_benefit_income_tax.py checks:

  • for each tax year from 2021-22 to 2027-28, at each bracket boundary of the payment after tax, a cent either side and between, that the schedule's tax on the grossed-up amount equals the tax grossed_up_tax gives, to $0.000001;
  • for each tax year from 2022-23, in simulations, that taxable_income less jobseeker_support_tax is the payment and income_tax less jobseeker_support_tax is 0 for a person with no other income, to 3 cents, since a simulation stores 32-bit floats;
  • that wages leave jobseeker_support_tax unchanged, and that each person's payment is grossed up on its own;
  • that each partner of a linked childless couple gets $16,482.44 and $2,172.64 of jobseeker_support_tax, with one grant (clause 1(j)(i), half to each) and with two (clause 1(g)(i) to each), and that a reform raising only the clause 1(g)(i) rate to $401 a week moves the couple with two grants to $20,852 and $3,099.52 each and leaves the couple with one grant where it was;
  • exact gross-ups on a two-bracket schedule, a NaN payment, a rate of 1e-20 that keeps its tax of 1e-17 on $1,000, a 50% rate that gives $1e308 of tax on $1e308, the 2025-26 schedule with its top three rates just below 1, which gives no tax on nothing, a schedule with a $1e17 bracket checked against exact rational arithmetic, and the ValueError for a tax too large for a 64-bit float;
  • the ValueError for each kind of schedule that cannot be inverted, including NaN and infinite values, shapes that differ, the 2024-25 schedule with a NaN rate, and the same NaN rate set by a reform through Core's Parameter.update, and the TypeError for a reform that gives the schedule average rates;
  • the exact tax against rational arithmetic at each exact boundary and the two floats either side, for a schedule whose 100 after tax sits exactly at a boundary (no tax on $100, about $25 on the next float), one whose boundary rounds up to $90 ($15 on $90), a six-bracket reform with three rates just below 1 (no tax on nothing), and a subnormal tied second boundary ([0.0, 5e-324], [0.75, Q]) returning 0.0 at zero;
  • widths whose 64-bit sum passes the largest float, under np.errstate(all="raise"), a first bracket one subnormal float wide, ten taxes near the largest float that each come within four units in the last place or raise, thresholds whose differences overflow and signalling NaN thresholds and rates, which raise the schedule's ValueError under np.errstate(all="raise"), a signalling NaN payment, which gives NaN, and wider np.longdouble inputs under np.errstate(all="raise") (skipped where longdouble is 64-bit) matching quiet-mode outputs or raising ValueError;
  • the period-2022 behaviour: each receipt flag stops the calculation for a population with one recipient, an amount given without a flag is left out, an earner with no benefit inputs is taxed as before, false flags and zero amounts are accepted, a branch reads its own flag, else the one it inherits, and a flag given for year:2021-07 raises for that year;
  • on Core 3.38.0, for both benefits and both flags: an input for year:2025-04 leaves periods 2022, 2023 and 2027 at the wage-only tax; inputs for year:2025-04 and year:2021-04 count in those years; an input kept on disk under a memory limit is read, so a false flag gives the wage-only tax and a true one raises; and a branch made after its parent calculated taxes its own benefit while the parent keeps its result. Each of these 16 tests fails on Core 3.20.0.

The two new test files hold 109 cases, 99 in Python (with the wider-longdouble case skipped where longdouble is 64-bit) and 10 in YAML, and the full suite passes on Core 3.38.0 at ef3a5ea0: 1,928 passed, 1 expected failure recorded on main (test_core_version.py:338). A 52-mutation check kills all 52 changes across taxable_income, jobseeker_support_tax, jobseeker_support and the 2024-25 rates (the 50 prior changes plus keeping only invalid="ignore" in the float64 cast guard and taking the tie sign from the rounded remainder np.sign(rest)). A sweep against exact rational arithmetic, over 63,532 payments on 1,027 schedules at each boundary, the floats either side and random amounts, finds 0 failures within the documented bound. ruff format --check passes on the two changed Python files; CI checks ruff 0.15.5.

Revisions

  • First version.
  • 63e9c99 answers the first review. taxable_income reads a stored benefit amount on the simulation's own branch first and compares whole periods; grossed_up_tax rejects NaN, infinite and mismatched schedules; the documentation describes income_tax and jobseeker_support_tax as separate amounts whose difference can be negative; and new tests cover a linked couple, a working partner, a loss beside Jobseeker Support, branches, anchored years and disk storage.
  • 128f88b answers the second review. taxable_income checks only the receipt flags for a period before April 2022 and leaves a supplied amount out, as main does, in place of 63e9c99's private read of Core's storage. grossed_up_tax adds up each bracket's amount after tax and computes the tax directly, so a near-1 rate, a tiny rate or a large amount no longer loses or invents tax, and jobseeker_support_tax rejects a schedule that is not a marginal-rate scale. The description states Core 3.20.0's limits with the Core versions that fix them, the linked-couple test names the clause each grant takes and adds a reform that tells them apart, and the README gives the schedule for each tax year.
  • a733144 merges main, which now requires Core 3.38.0.
  • bb0d13d answers the third review. grossed_up_tax adds up each bracket's tax and amount after tax in exact rational arithmetic, finds the bracket by comparing the payment with those exact amounts, and keeps the part of each boundary that rounding to a float drops, so a payment at or beside a rounded boundary owes the exact tax. It converts and checks the schedule without a NumPy floating-point error, and sets zero, NaN and overflowing results without one. New tests cover rounded boundaries, widths whose sum passes the largest float, a first bracket one subnormal float wide, taxes near the largest float, strict NumPy error settings and, on Core 3.38.0, years from April, disk storage and branches made after a calculation. A payment at or below zero becomes 0 before the bracket search, so the output mask keeps only NaN. The description drops Core 3.20.0's limits, which Core 3.38.0 removes, and the mutation note no longer claims a change equivalent.
  • ef3a5ea answers the fourth review. grossed_up_tax suppresses over and under alongside invalid in np.errstate during float64 casting so wide floating-point inputs raise no FloatingPointError before schedule validation or nonpositive payment clamping; new tests cover wider np.longdouble inputs under np.errstate(all="raise") (skipped where longdouble is 64-bit) and the subnormal tied boundary at zero ([0.0, 5e-324], [0.75, Q]).

axiom: no RuleSpec change (model formulas, tests and documentation)

🤖 Generated with Claude Code

MaxGhenis and others added 2 commits December 1, 2026 00:54
taxable_income adds the gross nz_superannuation, and jobseeker_support
with the new jobseeker_support_tax (Income Tax Act 2007, sections
CF 1(1)(c) and (e)). jobseeker_support_tax is the income tax that the
model assumes MSD pays on Jobseeker Support under section 350 of the
Social Security Act 2018. It grosses the year's payment up on the
personal tax schedule, apart from other income, and section 351(b)(iv)
makes it the person's income.

For a period that starts before 1 April 2022, taxable income keeps the
old sources and raises an error for a person marked as a recipient of
either benefit or given a nonzero amount of one.

Part of #18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- taxable_income reads a benefit amount stored for the period on the
  simulation's own branch, else on the branch it was made from, else on
  disk, and compares whole periods. Core's lookup read the default branch's
  amount in a named branch, and failed for a period-2022 calculation when
  either benefit had an input for a year that starts in April.
- grossed_up_tax rejects a schedule with a NaN or infinite threshold, a NaN
  rate, or thresholds and rates of different shapes.
- The income_tax documentation, the README and the docs describe income_tax
  as the year's liability before credits and jobseeker_support_tax as a
  separate estimate, whose difference can be negative. The README and the
  docs say income tax starts in 2021-22 and the benefits enter it in 2022-23.
- New tests cover a linked couple's two Jobseeker shares, a partnered NZ
  Super recipient beside a working partner, a loss beside Jobseeker Support,
  branch, anchored-year and disk reads, and invalid schedules.
- The Jobseeker Support rate description says the rates come before the
  income test, and the README's clause 1(d) example leaves out 2013
  transferees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis

MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

Answer to the first review, which requested changes at 3606387. I fixed each P1, P2 and P3 in 63e9c99. I reproduced every RAN witness at 3606387 first, and each result below comes from a run at 63e9c99 on this Mac.

P1, the branch read. taxable_income now reads a stored benefit amount through _given, which looks for the amount stored for the period on the simulation's own branch first, then for one stored on another branch, which a branch inherits from the simulation it was made from, then on disk. That is the order Core's lookup uses. Your witness now gives the branch's own amount: default $0 and branch $10,000 raises in the branch, and default $10,000 and branch $0 gives $50,000 and $8,020 there, for either benefit. test_before_april_2022_each_branch_reads_its_own_amount checks an amount on the branch only, on the simulation only, and on both with each one zero, reading the simulation and the branch from fresh copies. Reading the default branch, using Core's Holder.get_array without the branch name, or dropping the inherited amount each fails it.

P1, a year that starts in April. _given compares each storage key's whole period, so an amount given only for year:2025-04 leaves a period-2022 earner at $50,000 and $8,020 for either benefit, as on main. test_before_april_2022_an_amount_for_another_year_is_ignored checks both benefits, and restoring Core's lookup, with or without the branch name, fails it. test_an_amount_for_a_year_from_july_2021_raises checks that an amount given for year:2021-07 still counts for that year, on the simulation and on a branch; splitting storage keys at each colon fails the branch case.

The same Core defect reaches further than the guard, and _given cannot fix it there. Core 3.20 lists stored periods by splitting each key at every colon, so any calculation of a variable with an input only for such a year fails for another period, on main as here. On main, employment_income given only for year:2025-04 fails for period 2022. At 63e9c99, a receipt flag given only for year:2025-04 fails period 2022, and Jobseeker Support given only for that year fails periods 2023 and 2027, where main returned $50,000 because it read neither. Those come from Core's own calculate, so the description now lists them under assumptions and limits. Core's lookup also recurses without end on an amount stored only on disk; _given reads the disk storage directly, and test_before_april_2022_an_amount_stored_on_disk_raises checks it.

P1, the tax MSD pays and the year's liability. The income_tax documentation, the README and the description now call income_tax the year's liability before credits and jobseeker_support_tax a separate estimate of what MSD pays, and say their difference is negative when a loss brings the liability below that payment. The new YAML case gives your witness: $19,372.60 of Jobseeker Support beside a $40,000 self-employment loss leaves $2,785.70 of jobseeker_support_tax, $0 of taxable income and $0 of tax. Suppressing the MSD tax beside a loss fails it.

P1, NaN in the schedule. grossed_up_tax now checks, in positive form, that thresholds are one-dimensional and finite, that there is one rate for each, and that each rate lies in [0, 1), so NaN fails every check it reaches. The test adds a NaN rate in each position, NaN thresholds, an infinite threshold, rates longer and shorter than thresholds, two-dimensional and zero-dimensional schedules, and the 2024-25 schedule with its 12.82% rate made NaN. Removing the finiteness, shape or dimension check, or returning to the negative form, fails it. Every tax year's live schedule from 2021-22 to 2027-28 still passes the inverse test.

P1, a linked couple. test_each_partner_of_a_linked_couple_is_grossed_up_on_their_own builds two partnered adults in one benefit unit and household on the clause 1(j)(i) rate, with one grant and with two. Each gets $16,482.44, $2,172.64 of jobseeker_support_tax, $18,655.08 of taxable income and $2,172.64 of tax. Dropping the paid partner's gross-up fails it, and so does grossing up the couple's total and splitting the tax. The comment on the older test now says it gives the four payments directly.

P2, the partnered NZ Super case. The YAML case now gives the retiree a partner who earns $30,000. The retiree owes $3,386.47 and the partner $4,158; taxing the couple's $55,591.28 together would give $8,897.88. Summing taxable income over the household fails it.

P2, the documentation. The README and the docs now say income tax starts in 2021-22 and that the two benefits enter it in 2022-23. The Jobseeker Support rate description says the rates come before the applicable income test, and the README's clause 1(d) example now leaves out people transferred to Jobseeker Support on 15 July 2013.

P2, the test module. Its header now names the years: the inverse from 2021-22 to 2027-28, and simulations from 2022-23. test_income_tax.yaml already pins the 2024-25 rates: with 12.8201% in place of 12.82%, three of its cases fail on their own, so I added no second copy of the table.

P3, wording. The grossed_up_tax docstring and the description now name the bracket's lowest amount after tax and its threshold. taxable_income says the model offsets a loss in one modelled source against the others and assumes no further deductions or available losses, and jobseeker_support_tax says the model grosses up each partner's share separately. The description credits this PR with the rate metadata and the stated assumption, since the variable already called its amount net cash.

Your suggestion to tax supplied period-2022 amounts on the 2021-22 schedule is a design change beyond the findings, so this PR keeps the error.

Checks. The two test files hold 67 cases, and the suite passes, 1,692 tests. The mutation table covers 43 changes, including your three survivors, and each fails at least one test. Ruff 0.16.7 flags only README.md and docs/index.md, as on main.

The second review of 63e9c99 is under way, alongside CI.

- taxable_income decides whether a period that starts before 1 April 2022
  has a benefit recipient from the receiving_nz_super and
  receiving_jobseeker_support flags alone. The supplied-amount check, which
  read Core's storage directly, is gone, and an amount given without a flag
  is left out, as on main.
- grossed_up_tax sums each bracket's tax and its amount left after tax,
  finds the bracket by that amount, and raises when the tax on a finite
  amount overflows a float. A tiny rate keeps its tax, a rate just below
  one keeps a finite tax, and a large bracket keeps its small after-tax
  width.
- jobseeker_support_tax raises a TypeError when a reform makes the income
  tax schedule anything other than a marginal-rate scale.
- The documentation, README and changelog say the model assumes MSD pays
  the tax, and name the clause each couple rate comes from.
- New tests cover a NaN rate set through a reform, an average-rate
  schedule, two grants on the clause 1(g)(i) rate, and the float limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis

MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

Answer to the second review, which requested changes at 63e9c99. 128f88b answers each finding, and #34 tracks the Core upgrade. Each result below comes from a run at 128f88b on this Mac, beside main at ba0a233 where it matters.

P1s on the inherited, disk, ancestor, colon and neutralized reads. _given is gone. For a period that starts before 1 April 2022, taxable_income now reads only receiving_nz_super and receiving_jobseeker_support, through Core's ordinary lookup, and raises when either marks anyone. It reads no benefit amount for such a period, so branch, disk and ancestor order no longer decide what the guard sees. This withdraws the supplied-amount check that my first reply described: an amount of either benefit given for such a period without a flag now stays out of taxable income, as on main. Your witnesses now give main's result for either benefit. A parent with $10,000 stored and a child branch with no flag gives $50,000 of taxable income and $8,020 of tax, and so does a $10,000 amount stored before a reform neutralizes the benefit. test_before_april_2022_an_amount_without_a_flag_is_left_out and test_before_april_2022_each_branch_reads_its_own_flag check these.

P1, a year that starts in April. This stays a Core 3.20.0 defect, and #33 still reaches it in more places than main. With either benefit set only for year:2025-04 through set_input, periods 2023 and 2027 raise "got: 'year'", where main returns the wage-only result. On main, a situation dict that gives employment_income or jobseeker_support such a key already fails when Core builds the simulation, so these failures need set_input after the build, or a route I did not test, such as a dataset. I found no way around the defect in the model that avoids Core's private storage, which your P2 asked me to drop. Core 3.30.3 fixed the parsing (PolicyEngine/policyengine-core#525), and the description's limits now say which inputs fail, for which periods, and where main returned. Core 3.20.0 also recurses without end on a value stored only on disk. A receipt flag stored only on disk now fails period 2022 where main returned, but Core builds the flags' holders with the simulation, before a caller can set a memory limit. In my run, a limit set after the build left the flag in memory, so only an assignment to Core's private disk storage reaches that case, and the description and #34 leave it out.

P1, a branch made after a calculation. This is Core-wide. On main as at 128f88b, calculating income_tax for a $50,000 earner in 2026-27, making a branch and then giving it $10,000 of jobseeker_support leaves the branch at $50,000 of taxable income and $7,658 of tax. The description now says so and asks callers to give a branch its inputs before calculating on it or its parent. Core 3.33.0 makes an input on a branch drop the values calculated from the input it replaces (PolicyEngine/policyengine-core#560), and #34 asks the upgrade to confirm that this covers a value the branch inherited.

P1, the gross-up's arithmetic. grossed_up_tax now adds up each bracket's tax and its amount after tax as rate * width and (1 - rate) * width, finds the bracket by the amount after tax, and computes the tax as the tax at the bracket's threshold plus the excess times rate / (1 - rate). It returns 0 for an amount at or below zero before any bracket arithmetic, and raises a ValueError when the tax on a finite amount overflows. A rate of 1e-20 now gives 1e-17 on $1,000 where 63e9c99 gave 0, and a 50% rate gives 1e308 on 1e308 where 63e9c99 gave infinity. I could not reproduce the $66,449.16 on $0: with every choice of three brackets set to the largest float below 1 in the schedules for periods 2024 to 2027, both 63e9c99 and 128f88b give 0 on $0. The new tests also check a $1e17 bracket against exact rational arithmetic, since subtracting a tax near 1e17 from its threshold loses the small widths. Restoring 63e9c99's subtraction, either half of it, or the zero, NaN or overflow handling fails a test.

P1, an average-rate schedule. jobseeker_support_tax raises a TypeError unless the schedule is a MarginalRateTaxScale. Your reform, with thresholds of $0 and $100 and average rates of 10% and 30%, gave $5, $50 and $10 on $45 at 63e9c99 and now raises. test_an_average_rate_schedule_raises builds that reform through Core, and removing the check fails it.

P1, the two-grant clause. You are right, and my first reply was wrong to say both couples take the clause 1(j)(i) rate. A couple with one grant takes clause 1(j)(i), split half to each partner, and a couple with two takes clause 1(g)(i) for each. The comment and the description now say so. test_two_grants_take_the_clause_1g_rate raises only the clause 1(g)(i) rate to $401 a week: the couple with two grants moves to $20,852 and $3,099.52 each, and the couple with one stays at $16,482.44 and $2,172.64. Routing two grants through half the clause 1(j)(i) rate now fails it.

P1, the pooling mutations. You are right that a13 and d02 projected a person-level sum a second time and failed on the group size before any amount check, so my first reply overstated what they showed. a13 now sums income over the household once, and d02 splits the benefit unit's total once. Both now fail on the tests' amount assertions.

P2, Core's private attributes and version range. The model no longer reads any private Core attribute. #34 asks for a lower bound in pyproject.toml at the version the upgrade picks.

P2, the schedule contract. The grossed_up_tax docstring now says it reads the thresholds and rates as NumPy converts them to 64-bit floats and checks the converted arrays, which for the model's schedule are the brackets Core builds for the period. test_a_nan_rate_set_by_a_reform_raises sets the 2024-25 NaN rate through Core's Parameter.update and expects the ValueError from period 2025's calculation.

P2, the README, tolerances and population wording. The README gives the thresholds to 2023-24 and from 2025-26, names 2024-25's composite schedule, and its clause 1(d) example now leaves out only the people clause 1(c) covers. The description gives each tolerance on its own: a cent for the YAML cases, $0.000001 for the inverse and 3 cents for simulations. The changelog and the documentation say a recipient stops the whole calculation.

P3, voice and attribution. The changelog, README, labels and documentation now say the model assumes MSD pays the tax, use active subjects and sentence case, and drop the explanatory colons and semicolons you named.

Checks. The two test files hold 70 cases, and the suite passes, 1,695 tests. The mutation table makes 43 changes, and each fails at least one test except one: searching for the bracket from the left gives the same tax at a boundary, since the lower bracket's whole excess times its rate over one minus its rate is that bracket's tax. Ruff 0.16.7 flags only README.md and docs/index.md, as on main.

A scoped third review of the nine P1s comes next, alongside CI.

Edited after posting: the anchored-year paragraph now names the routes I tested, and it no longer lists the disk-only case as a limit, since Core 3.20.0 reaches it for a receipt flag only through private attributes.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

Answer to the third review, which requested changes at 128f88b. a733144 merges main, which now requires Core 3.38.0 (#35), and bb0d13d answers each finding. The suite passes on Core 3.38.0, 1,926 tests, with the one expected failure that main records, and each result below comes from a run on this Mac.

P1 4, years from April and flags on disk. Main now locks Core 3.38.0. Its 3.30.3 release parses a key such as year:2025-04, and it reads a value kept on disk under a memory limit. Sixteen new tests cover both benefits and both flags on the routes your probes took. A benefit given through set_input for year:2025-04 leaves periods 2023 and 2027 at the wage-only tax of $8,020 and $7,658, and a flag given that way leaves period 2022 at $8,020. A situation dict with a year:2025-04 or year:2021-04 key, which Core builds through build_from_entities, counts the benefit or the flag in that year. Under MemoryConfig(0.0), set after the build, the tests check that the input sits on disk and not in memory. A flag kept there is read, so a false flag gives the wage-only tax and a true one raises the recipient error, and a benefit kept on disk is taxed. A branch made after its parent calculated taxes its own benefit, and the parent keeps $7,658. Each of the 16 fails on Core 3.20.0. The ten tests of a year from April fail where Core splits the key at its colon, the four disk tests fail because a memory limit set after the build leaves each input in memory, and the two branch tests fail because the branch keeps its parent's result. The description no longer lists Core 3.20.0's limits.

P1 6, the gross-up at rounded boundaries. grossed_up_tax now adds up each bracket's tax and amount after tax in exact rational arithmetic and keeps the part of each boundary that rounding to a float drops. It finds the bracket by comparing the payment with the exact boundaries, and among boundaries that round to one float it counts those at or below the payment by the sign of that dropped part. Your three reforms now give the exact tax. Thresholds [0, 100, 125] with rates [0, q, 0] give $0 on $100 and about $25 on the next float, thresholds [0, 100] with rates [0.1, q] give $15 on $90, and your six-bracket reform gives no tax on nothing. test_a_rounded_net_boundary_takes_the_exact_bracket and test_amounts_around_each_net_boundary_owe_the_exact_tax check these, with the two floats either side of each boundary, against rational arithmetic. Breaking every tie toward the upper bracket (b04b) or the lower one (b04c), or rounding away the dropped part (b23), fails them. A sweep against exact arithmetic over 63,532 payments on 1,027 schedules finds every result within four units in the last place of the exact tax, or within 1e-300 where a subnormal float loses precision. An adversarial search of my own found 16 more counterexamples, with taxes near the largest float, thresholds whose differences overflow and signalling NaN inputs. The code handles each, and the tests include each kind.

P1, the overflow in the accumulation. The sums now run in exact arithmetic. Thresholds [0, 3 × 2⁹⁷⁰, largest float] with zero rates give 0 on 0, 1 and the largest float under np.errstate(all="raise"), which test_widths_that_add_past_the_largest_float_give_no_overflow checks. The function converts and checks the schedule with no floating-point error under any NumPy setting.

P1, the claim about b04. The claim was wrong. At 128f88b, searching from the left gave $0 on the [0, 100, 125] reform where the code gave $25, so that mutant came closer to the exact tax than the code did. The new code takes the exact bracket, and b04b and b04c now fail. The renamed b04, which counts only boundaries whose exact value lies strictly below their float, now fails too, since a payment of 0 sits exactly on the first boundary and takes the last bracket under it. The description now makes no claim that any change is equivalent.

P2, my reply's coverage wording. My second reply overstated two tests. test_before_april_2022_an_amount_without_a_flag_is_left_out covers an ordinary amount given without a flag, and test_before_april_2022_each_branch_reads_its_own_flag covers flags on fresh branches. The inherited, nested-branch, disk and neutralized amounts ran only as probes. Core 3.38.0 now lets a test keep a flag on disk, and test_a_flag_kept_on_disk_is_read covers that route. The nested branch and the neutralizing reform remain covered by the probes alone.

P2, b05. A payment at or below zero now becomes 0 before the bracket search, and 0 takes the first bracket with no excess, so the output mask for those payments changed nothing. bb0d13d removes it and keeps the mask for NaN. The mutation check now removes the input clamp (b05c) and the NaN mask (b05) separately, and each fails a test. test_a_first_bracket_one_subnormal_wide_owes_nothing_on_nothing holds your subnormal schedule.

The mutation check makes 50 changes, and each fails at least one test. Round 4 covers the four open P1s.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Claude Code for Max Ghenis.

Answer to the scoped round-4 review (subfleet:20261203-085341-nzhub-rev-pe-nz-33-r4, codex-5, gpt-6.2-sol, hard), which closed 3 of the 4 round-3 P1s at bb0d13da and returned VERDICT: REQUEST_CHANGES with 1 new P1, 1 P2, and 1 P3 note (notes/reviews/pe-nz-33-r4-20261203-085341.md, jobs/pe-nz-33-r4-rev-1203/out.md; prior reviews: jobs/lane-1130/review-33.out.md, review-33b.out.md, review-33c.out.md). ef3a5ea0 answers each item:

  1. P1 (jobseeker_support_tax.py:45, wide floating-point cast errors under np.errstate(all="raise")): Updated the cast guard to with np.errstate(over="ignore", under="ignore", invalid="ignore"): before validation and nonpositive clamping, and added test_wider_floating_inputs_match_quiet_mode_under_strict_numpy (skipped when np.longdouble has the same precision as 64-bit float). Verified locally under x86_64 extended precision (nmant == 63) that underflowing/overflowing np.longdouble rates, thresholds, and payments under np.errstate(all="raise") match quiet mode or raise ValueError.
  2. P2 (jobseeker_support_tax.py:14-16, subnormal tie mutation coverage): Added test_a_subnormal_tied_boundary_with_strict_rounding_owes_nothing_on_zero (thresholds=[0.0, 5e-324], rates=[0.75, Q], net 0.0 returning [0.0]), which kills np.sign(rest) (b04d-rounded-rest-sign).
  3. P3 (Ruff 0.16.7 vs 0.15.5 on main's Markdown docstrings): Left README.md and docs/index.md untouched; both changed Python files pass ruff format --check and CI lint (47125402206) passes using the repo toolchain.

Checks at ef3a5ea0:

  • GitHub Actions run 47125402206: 11/11 passed (lint, Check changelog fragment, and ubuntu-latest/macos-latest/windows-latest across Python 3.11-3.13).
  • Local Core 3.38.0 full suite: 1,928 passed, 1 xfailed (test_core_version.py:338 from main); test_benefit_income_tax.py: 99 passed; test_benefit_income_tax.yaml: 10 passed.
  • Oracle sweep (oracle_sweep_b.py): 63,532 points across 1,027 schedules, 0 failures.
  • Mutation check (52 mutants — mutants_r4.py updated for the new cast guard plus b27b-only-invalid-ignore and b04d-rounded-rest-sign): 52 of 52 killed.
  • Core 3.20.0 witness: 16 failed, 83 deselected on the Core-3.38 tests.

Per pr-lifecycle.md's 4-round limit, round 5 is not opened while the round-4 P1 remains unreviewed-closed; keeping #33 as a draft and queuing a decision card for Max (NZ hub as executor).

This branch has not been deployed

No deployments
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