Repository navigation
Hold UC trade tax parts in the trading loss netted world - #2849
Conversation
The netted world in test_means_tests_see_the_loss_only_through_tax held UC's tax and NI totals on earnings at their with-loss values but let the parts in respect of the trade be recomputed for the cut profit. For a loss larger than the profit beside a private pension, that moved the trade's share of the tax onto employed earnings. Hold both parts, pin the minimised family from #2832 and restate invariant 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwQq6HiQgbqpFzJ8CLCXuP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Aggregate impact on certified data: passBase Checks: 0 broken by this change, 1 failing on both sides, 0 fixed. Moves flagged for review: 0 (thresholds in Notes
Moves flagged for reviewNone. Spending by benefit and service
Caseloads
Standard reform costings (change in gov_balance)
The report suppresses a reform's costing and target change in these years, for the reasons below (
Standard reforms: change in each reform's target
Household net income by decileNo household's net income changes in any year. No change in any year: receipts by tax head; government balance, each component counted once; model totals; household income totals; population; poverty rates; people in poverty; inequality; mean household net income in each side's own deciles. Checks failing on both base and head (1)
Counted-once checkEach of 92 components was raised by £1 per unit in 2026-27, and every head of its totals was read household by household: its own head must rise by exactly £1, no other tax head may move, no other benefit may rise, and the model's own total must move by what its heads moved. A head that breaks a rule is measured again twice: with every other head held at its baseline value, and with every other head held at its value after the first £1 while the component rises again. It fails where either still shows the response. 0 failed; 0 were skipped.
Provenance
Dataset: Receipts by tax head: head levels
Spending by benefit and service: head levels
Caseloads: head levels
Government balance, each component counted once: head levels
Model totals: head levels
Household income totals: head levels
Population: head levels
Poverty rates: head levels
People in poverty: head levels
Inequality: head levels
Mean household net income in each side's own deciles: head levels
Standard reform costings (change in gov_balance): head levels
Standard reforms: change in each reform's target: head levels
|
juaristi22
left a comment
There was a problem hiding this comment.
Reviewed cd994ad23f01e42c90c6d760de77d221a4cac7eb. COMPLETE — no findings or material evidence gaps.
The corrected controlled comparison holds both trade tax/NI components alongside the totals, so the loss-netted world isolates the intended loss rule. It preserves the model's stated allocation convention; it does not claim that convention is uniquely required by the legislation.
Validation: 16 focused tests passed. Diagnostics reproduced £32,319.60 for the actual and corrected worlds versus £30,519.60 under the old oracle, and matched all four asserted UC outputs across five families, including four positive final UC awards. The limited UC/ITA source claims were independently checked against five validated official originals. The initial diagnostic-only output-name error was corrected without repeating the passing test suite.
Exact-head CI is green. Approval is deferred because the PR remains a draft; the completed review can be retained when readiness and current-head CI are checked later.
juaristi22
left a comment
There was a problem hiding this comment.
Approval-only follow-up at unchanged cd994ad23f01e42c90c6d760de77d221a4cac7eb: COMPLETE, no findings or material gaps.
The previously completed code/source review, 16 passing tests and qualified final-UC diagnostics remain valid: head, body, dependencies, runtime and saved artifacts are unchanged. No tests were rerun. The controlled tax-allocation convention remains distinguished from a uniquely statutory allocation.
The PR is now ready; applicable exact-head required checks, activity and source evidence were refreshed before approval.
|
Ready for hub review Verdict: APPROVE WITH NITS at This PR merged unchanged at that head on 2026-11-05 at 15:54Z ( The test change is right:
What needs follow-up is the text, a gap and a hub document:
As the brief says, no earlier round reviewed this PR, so no findings carry over. FindingsP1None. P2-1. The body and changelog misstate when the old test failedWhere.
What I ran. A scratch pytest file calls each version's body,
Why.
Replacement, body. From "Before this change" to the end of that paragraph:
Changelog.
P2-2. Invariant 4 calls the split "not a loss rule", but the split moves with the loss and no test pins itWhere.
The split moves with the loss. I swept the loss through a bare
The slice reads The property cannot see a change to the split. The netted world copies the split, so a split that moves wrongly with the loss passes.
No test pins the split for anyone with a trading loss.
The second and third sentences hold only under reading A. "Recomputing the trade's part for the cut profit would move tax" is false under reading B. With the scratch reading-B slice, Fix, YAML. Pin reading A's split. The draft below passes at # UC's income tax in respect of a trade that has a trading loss (UC Regs
# 2013 reg 57(2) step 3). The formula takes earnings as the lowest slice of
# non-savings income and the trade before this year's loss relief
# (uc_income_tax_on_earnings_slice), so it takes the relief off the private
# pension above earnings first. Wages 40,000, profit 9,000, private pension
# 20,000; personal allowance 12,570; basic-rate band 37,700 at 20%; Class 1
# (40,000 - 12,570) x 8% = 2,194.40.
- name: A loss larger than the profit leaves the trade the tax on its profit while the pension takes the relief
# Relief of 16,000 leaves net income 53,000 and taxable income 40,430.
# Other income comes to 53,000 - 49,000 = 4,000 and the tax on earnings to
# (40,430 - 4,000) x 20% = 7,286. Without the trade, other income comes to
# 13,000 and the tax to 27,430 x 20% = 5,486, so the trade bears 1,800.
# Self-employed earnings come to max(0, 9,000 - 9,000 - 1,800) = 0 and
# employed earnings to 40,000 - 5,486 - 2,194.40 = 32,319.60.
period: 2026
absolute_error_margin: 0.01
input:
age: 18
employment_income: 40_000
self_employment_income: 9_000
private_pension_income: 20_000
trading_loss: 16_000
region: LONDON
output:
uc_income_tax_on_earnings: 7_286
uc_income_tax_on_trade: 1_800
uc_individual_earned_income_before_mif: 32_319.60
- name: A loss smaller than the profit leaves the trade the tax on its profit
# Relief of 4,000 leaves taxable income 52,430 and other income 16,000, so
# the tax on earnings comes to (52,430 - 16,000) x 20% = 7,286 and the
# trade bears 7,286 - 5,486 = 1,800. Self-employed earnings come to
# 9,000 - 4,000 - 1,800 = 3,200 and employed earnings to 32,319.60.
period: 2026
absolute_error_margin: 0.01
input:
age: 18
employment_income: 40_000
self_employment_income: 9_000
private_pension_income: 20_000
trading_loss: 4_000
region: LONDON
output:
uc_income_tax_on_earnings: 7_286
uc_income_tax_on_trade: 1_800
uc_individual_earned_income_before_mif: 35_519.60
- name: Relief beyond the pension reduces the trade's part of the tax
# Relief of 25,000 leaves net income 44,000 and taxable income 31,430.
# Other income comes to max(0, 44,000 - 49,000) = 0, so the tax on
# earnings comes to 31,430 x 20% = 6,286. Without the trade, other income
# comes to 4,000 and the tax to 27,430 x 20% = 5,486, so the trade bears
# 800. Self-employed earnings come to max(0, 0 - 800) = 0 and employed
# earnings to 32,319.60.
period: 2026
absolute_error_margin: 0.01
input:
age: 18
employment_income: 40_000
self_employment_income: 9_000
private_pension_income: 20_000
trading_loss: 25_000
region: LONDON
output:
uc_income_tax_on_earnings: 6_286
uc_income_tax_on_trade: 800
uc_individual_earned_income_before_mif: 32_319.60Replacement, docstring head lines 41-45 (
Replacement, body "Invariant", last sentence:
Replacement, body "Tests", first bullet:
P2-3.
|
| Text | Replacement |
|---|---|
| "step 2 adds every trade's profit or loss; step 3 deducts the income tax and contributions paid "in respect of any trade", and a nil or negative result makes self-employed earnings nil." | "DWP adds every trade's profit or loss (step 2), deducts the income tax and contributions the person pays "in respect of any trade" (step 3), and treats a nil or negative result as nil self-employed earnings." |
| "None of these says which non-savings income a trade loss relieves when UC splits one tax bill between the employment and the trade." | "In these provisions neither Parliament (ITA 2007) nor the Secretary of State (UC Regs 2013) says which non-savings income the relief for a trade loss comes off when DWP splits one tax bill between the employment and the trade." |
| "so s. 25(2) does not choose between them." | "so the taxpayer gets the same reduction whichever of them the relief comes off, and has no order to choose under s. 25(2)." |
| "because the step 3 nil floor absorbs the £1,800 that reading A puts on the trade." | "because the formula floors the trade total at nil (reg 57(2) step 3) and so drops the £1,800 that reading A puts on the trade." |
| "These provisions leave both readings defensible, so..." | "Parliament and the Secretary of State leave both readings open in these provisions, so..." (then as P3-4) |
P3-7. The author's report (HANDOFF-777.md, comment 6600510649), for the record
- "Main's old netted world in fact embodies reading B."
- This contradicts "Main's netted world matches no reading" a few lines earlier. The old netted world recomputes the trade's part as reading B does but holds reading A's total of 7,286, so it gives 30,519.60.
- Replacement: "Main's old netted world recomputes the trade's part as reading B does but holds reading A's total, so it matches neither. If the model followed reading B, the old test would pass: the trade's tax would be on its net result, which never exceeds the profit the loss leaves, so the nil floor would never bind."
- The scratch reading-B runs confirm that it would pass.
- "I worked each reading by hand; the model reproduced every tax figure." The model computes only reading A. A scratch slice reproduces reading B's figures exactly; reading B' rests on arithmetic alone.
- "The title is 57 characters." It has 56.
P3-8. Outside families(), cutting the profit can switch off UC's childcare work condition (predates this PR)
What I ran. The head's and main's test bodies on one family the strategy never draws:
- an adult aged 30 with no hours, profit 5,000, a loss of 10,000 and childcare costs of 6,000;
- a child aged 3;
- rent 9,000 in London.
Both fail the UC check: universal_credit_pre_benefit_cap is 15,796.94 with the loss against 10,696.94 netted. The 5,100 gap is the childcare element. With 16 hours worked, both pass.
Why.
in_work(in_work.py:12-16) is true for any hours, pay or profit. With the loss, the profit of 5,000 makes the adult in work. The netted world cuts it to nil, souc_childcare_work_conditionfails.- The module docstring states its invariants "for any people and incomes". Invariant 4 holds only where the profit cut leaves the work condition as it was.
Fix. Either hold in_work at its with-loss value in the netted world, as the test holds uc_mif_applies, or say in invariant 4 that the comparison assumes the cut leaves the work condition unchanged.
Checked and sound
1. Diagnosis.
-
Reproduction.
main's test body at1d4d020aafails on the Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832 family withAssertionError: ('uc_earned_income', array([32319.59765625]), array([30519.59765625]), ...)at test line 1008. The head's body passes. -
The body's Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832 table. A bare
Simulation(family_2832.py 16000) reproduces every figure at1d4d020aa:- with the loss: tax on earnings 7,286.00 and on the trade 1,800.00; NI on earnings 2,194.40 and on the trade 0.00; employed part 32,319.60; self-employed part 0.00 (-1,800.00 before the floor);
uc_earned_income32,319.60; - totals only: trade part 0.00, employed 30,519.60,
uc_earned_income30,519.60; - totals and parts: 32,319.60.
98381bf49gives the same figures. - with the loss: tax on earnings 7,286.00 and on the trade 1,800.00; NI on earnings 2,194.40 and on the trade 0.00; employed part 32,319.60; self-employed part 0.00 (-1,800.00 before the floor);
-
Hypothesis 6.170.11 (pinned in
uv.lock):get_random_for_wrapped_test(core.py:711-728) checks@seedfirst (715-716), thensettings.derandomize(718-719,Random(int_from_bytes(function_digest(test)))), thenglobal_force_seed(721-722)._hypothesis_pytestplugin.py:183-189setsglobal_force_seedfrom--hypothesis-seed. Soderandomize=Truebeats--hypothesis-seed, as the author says.- The
seed()docstring (core.py:365) says "Setting a seed overrides |settings.derandomize|". That holds only for@seed. - With a global seed,
run_enginesetsdatabase_key = None(core.py:1415-1418), so seeded runs neither read nor write the example database. - Under CI's settings, seeds 1 and 2584 drew identical families.
-
Main and head draw differently under CI.
function_digest(internal/reflection.py:83-116) hashes the source fromdefon;_clean_source(56-80) drops decorators and comments. So the head's two code hunks, not its@example, change the digest. Under CI's settings,main's test and the head's test draw different families; only the first, all-zero example is common. -
Seeds. Scratch copies changed only
derandomize=Falseandphases(the defaults lessPhase.shrink), withmax_examples=3. Two independent runs each covered all 20 of the author's seeds.main's test failed only at 2584, onuc_earned_income. The failing family is the sixth of six in that example: one adult aged 36 with children aged 14 and 0; wages 59,045.75, profit 18,902.86, pension 8,080.30, loss 19,543.35.- The head's test passed all 20, drawing the same families seed by seed.
2. The fix.
-
What the formula reads.
uc_individual_earned_income_before_mifreads exactly four tax and NI variables (lines 85-100; a simulation trace agrees):uc_income_tax_on_earnings,uc_income_tax_on_trade,uc_national_insurance_on_earningsanduc_national_insurance_on_trade. The netted world holds all four: the totals throughheld(head lines 969-970) and the parts at 1009-1012 and 1050-1052. -
What else moves. The review compared 18 family lists: the 5 explicit examples, the 3 lists the test generates under CI's settings, and 10 drawn lists, which make 86 families and 234 people.
- Of the inputs that formula reads, only
self_employment_incomeanduc_trading_losses_set_against_profitsdiffer between the worlds. Each moves by min(loss, profit) for 37 people, and the two cancel. The netted world also setstrading_lossto nil, which only the second of those reads. uc_individual_earned_income_before_mifand the fourUC_TESTSagree exactly.- The floor's inputs (
uc_minimum_income_floor,is_uc_assessed_claimant,uc_mif_applies) and the benefit cap threshold agree too. The floor's own notional tax and NI (uc_minimum_income_floor_income_taxanduc_minimum_income_floor_national_insurance) aren't held, but they never move.
- Of the inputs that formula reads, only
-
Three limits, none reached by
families().- The cut equals UC's offset only while
uc_company_self_employed_earningsis nil, whichfamilies()guarantees. - The netted world still recomputes
adjusted_net_incomeand Pension Credit's tax attribution, which move with the loss. UC reaches them through Tax-Free Childcare, non-dependant deductions, Child Benefit (only when the family opts out) and Housing Benefit's savings-credit income, which cancels in the benefit cap. None changed a UC test in the lists compared. - Cutting the profit can switch off the childcare work condition (P3-8).
So invariant 4's "every tax and NI deduction the UC formula reads" is right for the earned income formula.
- The cut equals UC's offset only while
3. Can the test still fail? Each mutant was applied alone to the merge and restored afterwards; two independent runs gave the same results.
| Mutant | Pinned #2832 example | Other 4 explicit examples | CI's settings | Generated only, seeds 1-3 |
|---|---|---|---|---|
| T1 hold the totals only (the author's) | killed: 32,319.60 vs 30,519.60 | survived | killed (by #2832) | not run |
| T2 leave the profit uncut (the author's) | killed: 32,319.60 vs 39,519.60 | all 4 killed | killed | not run |
| T3 hold the income tax part only | survived | survived | survived | not run |
| M1 drop the loss from the reg 57(2) trade total | killed: 39,519.60 vs 32,319.60 | all 4 killed | killed | killed 3/3 |
| M2 also take the unused loss off pay | killed: 25,319.60 vs 32,319.60 | 3 of 4 killed | killed | killed 3/3 |
| M3 also take the whole loss off pay | killed: 17,880.98 vs 32,319.60 | 3 of 4 killed | killed | killed 3/3 |
| M4 move the tax on earnings onto the trade when there is a loss | survived | survived | survived | survived 3/3 |
| M5 net the whole loss, uncapped | survived | survived | survived | survived 3/3 |
- What the property still tests. It tests the loss rule invariant 4 states: reg 57(2) step 2 netting, and no loss against employed earnings or other income. Every mutant tried that changes how the loss reaches UC earned income (T1, T2, M1-M3) fails it. The pinned example alone kills each of those, and generated families alone kill M1-M3.
- The survivors. M5 is equivalent for this test: the nil floor absorbs the excess, and
uc_trading_loss.yamlkills it. T3 is P3-1, and M4 is P2-2. - Tests that pin the split on their own. At the head, only the two cases in
uc_company_analogous_business.yaml(3,886 and 445.80), which have no trading loss and no pension. Onmain,test_uc_income_tax_properties.py:139-142adds a third, also with no loss.test_zero_profit_trade_loss_cannot_raise_tax_or_reduce_programme_award[universal_credit-2026]constrains the split indirectly, for zero-profit families.
4. Readings A and B.
-
Arithmetic. Every figure in the issue, the body,
FOLLOWUP.md, the author's report and the@examplecomment recomputes: 76 of 76. For losses of 16,000, 4,000 and 8,000, all 66 model values compared in the three worlds (reading A and both netted worlds) match the arithmetic to the penny (family_2832.pyat1d4d020aa). The 16,000 and 4,000 runs give the same figures at98381bf49. -
Reading B in code. A scratch reading-B slice changes only
uc_income_tax.py: the trade's part of earnings becomesmax_(0, taxable_self_employment_income - uc_trading_losses_set_against_profits). It reproducesFOLLOWUP.md's figures exactly:- at a loss of 16,000: tax on earnings 5,486, trade part 0,
uc_earned_income32,319.60; - at a loss of 4,000: 6,486, 1,000 and 36,319.60.
I checked B' (33,719.60 and 36,319.60) with arithmetic only; the model has no B'.
- at a loss of 16,000: tax on earnings 5,486, trade part 0,
-
The test under reading B. The head's property passes under B, with CI's settings and with seeds 2584, 1, 2, 3, 5 and 8. As
FOLLOWUP.mdsays,main's totals-only test passes under B too, in the same runs and in direct calls at six losses. It fails under reading A, as a control. -
Other suites under B. None of the suites run under B fails: the trading-loss module (12 passed), three UC property modules (16), the UC income YAML (174),
uc_trading_loss.yaml(8),uc_company_analogous_business.yaml(26) and all 15 YAML files that set a trading loss (276). -
What is quoted. Only two phrases are quoted: "in respect of any trade" (PR body,
FOLLOWUP.md) and "in respect of the employment" (issue, PR body). Everything else, all of ITA 2007 included, is paraphrase. The shared-rate-bands premise cites no provision. -
What the quoted text supports. The quoted words name a source of income, not a way to apportion one tax bill, so they don't decide between A and B. The PR's "None of these says which non-savings income a trade loss relieves..." is consistent with what was quoted. "Defensible" is a judgement that rests on unquoted law.
-
Where A and B differ. They leave the employment the same tax: 5,486 at every loss up to 29,000. They move tax between the trade, which UC deducts, and the pension, which it doesn't. So the quoted reg 55(5)(b) words bear only on B'.
-
Under either reading the test holds, by construction. Several texts describe reading A: the body, invariant 4's second and third sentences (head lines 41-45,
main44-48), the comment at head lines 1003-1008 and the@examplearithmetic. A reading-B ruling would need them reworded (P2-2). Under B', the 32,319.60 figures change too.
5. The pinned example (head lines 918-952), to the penny.
- 37,700 x 20% + 2,730 x 40% = 8,632; (40,430 - 4,000) x 20% = 7,286; 27,430 x 20% = 5,486; 7,286 - 5,486 = 1,800.
- Class 1: the model's primary threshold is 241.73 x 52 = 12,569.96, giving 2,194.4032, which is 2,194.40 to the penny.
- 40,000 - 5,486 - 2,194.40 = 32,319.60; 40,000 - 7,286 - 2,194.40 = 30,519.60.
- All match the model.
- Three facts hold but go unstated:
- the relief cap doesn't bind (max(50,000, 25% of 69,000));
- the personal allowance isn't tapered;
- London takes the rest-of-UK rates.
- The comment says "there is no Class 4" without the reason: the 9,000 profit is below the 12,570 lower profits limit.
6. Text.
- Fix evidence. The review ran
.github/check_fix_pr.py(blob9c9452a38, the same at52b30809fand1d4d020aa) on the live title and body, built aspr_fix_evidence.yamlbuilds them. It used no labels, and the changesA changelog.d/2832.fixed.mdandM policyengine_uk/tests/test_trading_loss_properties.pyfrom merge base6c6e229a5. Output:Fix evidence: PASS ('Hold UC trade tax parts in the trading loss netted world')/- Fix PR has valid reproducer evidence. Changed executable tests: 1., exit 0. - Body versions. The live body is identical to the body saved from the PR on 3 November. I compared it with the brief's
PR_BODY.mdby eye. The version posted on Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832 (comment 6600500271) is an earlier draft that differs in eight lines. - Title. 56 characters, sentence case, no rule broken.
- Format.
uvx ruff@0.17.2 format --checkandcheckon the changed file, andgit diff --check 6c6e229a5 cd994ad23, are clean. - Changelog. The fragment's name and
fixedtype followgithub-prs.md.
7. Tests (-n 4; YAML with policyengine-core test ... -c policyengine_uk):
| Suite | Head cd994ad23 |
Merge with 1d4d020aa |
|---|---|---|
test_trading_loss_properties.py |
12 passed | 12 passed |
test_uc_earned_income_before_work_allowance_properties.py |
4 passed | 4 passed |
policyengine_uk/tests/code_health |
3,089 passed | 3,092 passed |
YAML .../universal_credit/income |
174 passed | 174 passed |
At current main (98381bf49), test_means_tests_see_the_loss_only_through_tax passes (1 passed in 140.59s).
8. CI.
- Check runs.
gh api repos/PolicyEngine/policyengine-uk/commits/cd994ad23.../check-runsnow lists 21 runs, allcompleted/success:- Fix evidence twice (10:05Z and 17:05Z on 3 November);
- once each: Aggregate impact; Changelog fragments; Changes; Documentation build; Install + smoke-import (py3.11 to py3.14); Lint; Release build records the commit; Test / Python 1/7 to 7/7; Test / Result; Test / YAML.
- Aggregate impact. Pass, base
52b30809ffagainst head merge78192e71c3; no household's net income changes in any year. - Commits since CI's base. In
52b30809f..1d4d020aa, 17 commits change files the test reads. All arrive through Disregard WTC before the Housing Benefit childcare deduction #2776 (mergefb83b25af) and touch six Housing Benefit variable files andutils/supplied_inputs.py, all of which the test runs (coverage).- The review dumped 5,532 values from the 18 family lists: the 14 variables the test compares and four more, in all three worlds. All are identical between the merges with
52b30809fand1d4d020aa. - Tax credits are inactive in 2026, so
housing_benefit_wtc_disregardis nil. - The test passes on the merge.
- The review dumped 5,532 values from the 18 family lists: the 14 variables the test compares and four more, in all three worlds. All are identical between the merges with
9. Merges. git merge-tree --write-tree --name-only is clean for cd994ad23 against:
1d4d020aa(tree090e1b98c);7381a46c7, the Treat income derived from capital as capital in the legacy means tests #1995 commit the author's report checked (treea53b1c3c2);- Treat income derived from capital as capital in the legacy means tests #1995's head when I first fetched it on 2026-11-03,
1919788159(tree036d80c6d); - Treat income derived from capital as capital in the legacy means tests #1995's final head,
7ba0ea7af(tree68c0dde8b).
#1995 merged at 2026-11-04 02:50Z (8717d5a26) and this PR at 2026-11-05 15:54Z (93bc52d1c). main's test file carries both changes.
10. The author's writer check. Both other branches, claude/uc-trading-loss-property-8zmhka and -n0kzrs, point at 2947d73d4. Before the author's pick-up comment, #2832 had only the two earlier pick-up comments.
What I couldn't check
- The author's search. I did not rerun the 4 x 250-example search (seeds 7771 to 7774).
- The rest of the writer check. I did not check that no newer
claude/branch touches these files, or that Treat income derived from capital as capital in the legacy means tests #1995 is the only PR naming Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832. - Suites under reading B. I ran no
code_health, no full suite and none of the 11 other Python modules that set a trading loss under reading B. - CI's own draws. I did not compare CI's derandomized draws with mine. Hypothesis takes some values from constants in the modules it has loaded, so local and CI draws can differ.
- Law beyond the quotes. legislation.gov.uk isn't reachable from this session, so I read no law beyond the fragments quoted on Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832, in the PR and in
FOLLOWUP.md. - juaristi22's source checks. Their review cites "five validated official originals", which I couldn't see.
Generated by Claude Code
Fixes #2832
Reproducer: policyengine_uk/tests/test_trading_loss_properties.py::test_means_tests_see_the_loss_only_through_tax
axiom: n/a: test-only change; no rule or parameter value changes
What the code does now
This PR changes no model code.
uc_individual_earned_income_before_miftakesuc_income_tax_on_tradeanduc_national_insurance_on_tradeoff the reg 57(2) trade total before the nil floor, and takes the rest ofuc_income_tax_on_earningsanduc_national_insurance_on_earningsoff employed earnings.uc_income_tax_on_tradetakesuc_income_tax_on_earnings_slicewith the trade, less the same slice without it, and caps the difference atuc_income_tax_on_earnings. The slice takes earnings as the lowest slice of non-savings income, and counts as other incomenet_income, less the exclusions, less the earnings. Trade loss relief lowersnet_incomebut not earnings, so the slice takes the relief off the other income above earnings first.test_means_tests_see_the_loss_only_through_taxcompares UC with the loss against a netted world: the same family with the profit cut bymin(loss, profit)and the tax and NI deductions held at their with-loss values. Before this change the netted world held the totals on earnings but let the formula recompute the parts in respect of the trade for the cut profit. Where the loss exceeds the profit, that moved the trade's share of the tax from the trade total, where the reg 57(2) step 3 nil floor absorbs it, onto employed earnings. The netted world now holdsuc_income_tax_on_tradeanduc_national_insurance_on_tradetoo, so it holds every tax and NI deduction the UC formula reads.The #2832 family
One person aged 18 in London in 2026: wages £40,000, profit £9,000, private pension £20,000, trading loss £16,000.
uc_income_tax_on_earningsuc_income_tax_on_tradeuc_national_insurance_on_earningsuc_national_insurance_on_tradeuc_earned_incomeRelief of £16,000 leaves net income £53,000 and taxable income £40,430. The slice puts earnings of £49,000 lowest, which leaves £4,000 of other income, so the tax on earnings comes to (40,430 - 4,000) x 20% = £7,286. Without the trade, other income comes to £13,000 and the tax to 27,430 x 20% = £5,486, so the trade bears £1,800. Class 1 comes to 27,430 x 8% = £2,194.40. With the loss, self-employed earnings come to max(0, 9,000 - 9,000 - 1,800) = 0 and employed earnings to 40,000 - 5,486 - 2,194.40 = £32,319.60. The netted world before this change recomputed the trade's part as nil, so all £7,286 came off employed earnings: £30,519.60.
The law
None of these says which non-savings income a trade loss relieves when UC splits one tax bill between the employment and the trade. Employment, trade and pension income share the same rate bands, so s. 25(2) does not choose between them.
Readings weighed
uc_earned_incomewith the loss, for the #2832 family (loss £16,000, which exceeds the profit) and the same family with a loss of £4,000:The old netted world matches no reading for the #2832 family. Readings A and B agree there, because the step 3 nil floor absorbs the £1,800 that reading A puts on the trade. They differ by £800 (20% of the loss) for the £4,000 family. These provisions leave both readings defensible, so this change follows the convention that
uc_income_tax_on_earnings_slicestates inpolicyengine_uk/utils/uc_income_tax.py(earnings form the lowest slice, so tax on other income never comes off earnings), fixes the test and leaves the model alone. A comment on #2832 sets out reading B, its households and what it would change.Invariant
Invariant 4 in the test's docstring now says that UC, its benefit cap earnings test and the capped award with the loss equal the same family with the other trades' profits cut by the loss and every tax and NI deduction the UC formula reads held at its with-loss value: the totals on earnings and the parts of them in respect of the trade. The person pays those deductions with the loss, and the parts record the model's split of that payment between the employment and the trade; no loss rule sets them.
Tests
@exampleontest_means_tests_see_the_loss_only_through_taxpins the Trading-loss property test fails when a loss wipes out a profit beside a private pension (UC earned income) #2832 family, with the arithmetic in a comment.test_trading_loss_properties.py: 12 passed, both on this branch and run against currentmain's code.test_uc_earned_income_before_work_allowance_properties.py: 4 passed.policyengine_uk/tests/policy/baseline/finance/benefit/family/universal_credit/income: 174 passed.policyengine_uk/tests/code_health: 3,089 passed. Ruff format, ruff check, ruff F811/F821 andgit diff --check: clean.main, the test with CI's settings butderandomizeoff fails for 1 of 20 Hypothesis seeds (seed 2584); with this change, all 20 pass. With CI's own settings (derandomize=True) the seed has no effect andmainpasses.main's code: holding only the totals fails the pinned example (uc_earned_income32,319.60 against 30,519.60); leaving the profit uncut in the netted world fails the pinned example (32,319.60 against 39,519.60) and four other explicit examples.derandomizeoff, otherwise CI's settings), 1,000 generated families in all, againstmain's code with this change. All passed; no new counterexample.🤖 Generated with Claude Code