You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$250] Split expense - Third split is added as 0 after click 'Add split' #87378
Please re-state the problem that we are trying to solve in this issue.
When splitting a $10 expense where Split A is manually set to $3 and Split B auto-calculates to $7, clicking "Add Split" creates a third split with $0 instead of redistributing the remaining $7 evenly among the two unedited splits (B=$3.50, C=$3.50).
What is the root cause of that problem?
This is a regression from PR #87124 (which fixed #82455). That PR added a condition at src/libs/actions/IOU/Split.ts:2647 that skips redistribution when manually-edited splits exist AND the existing splits already sum to the total:
The problem: splitsAlreadyMatchTotal checks the existing splits (before the new one is added). Since existing splits almost always sum to the total, and any user edit sets hasManuallyEditedSplits = true, redistribution is skipped every time a user adds a split after editing any amount. The new split stays at its initialized value of $0.
The redistributeSplitExpenseAmounts function (Split.ts:2554-2581) already handles this correctly — it preserves manually-edited amounts and distributes the remainder among unedited splits. It just never gets called.
What changes do you think we should make in order to fix the problem?
Modify the condition at Split.ts:2647 to check whether the updated splits (including the new $0 split) sum to the total, rather than the existing splits:
Since the new split has amount=0 and existing splits summed to the total, updatedSum will still equal the total numerically — but the key insight is that now there's an unedited split with $0 that needs a share. A cleaner alternative: always redistribute when addSplitExpenseField is called, since the entire purpose of this function is to add a new split that needs an amount. The edge case PR #87124 solved (edited amount exceeding total) is already handled correctly by redistributeSplitExpenseAmounts — it computes remaining = total - editedSum, which would be negative when edits exceed the total, and distributes that among unedited splits.
The simplest fix: remove the redistribution skip in addSplitExpenseField entirely — always call redistributeSplitExpenseAmounts (for non-distance requests):
// Remove lines 2639-2650 (the conditional logic) and replace with:if(!isDistanceRequest){redistributedSplitExpenses=redistributeSplitExpenseAmounts(updatedSplitExpenses,total,currency);}
This preserves the original intent (user-edited amounts stay fixed, unedited splits share the remainder) while ensuring newly-added splits receive a proper amount.
What alternative solutions did you explore? (Optional)
The condition could be patched more narrowly (e.g., adding || updatedSplitExpenses.some(s => s.amount === 0 && !s.isManuallyEdited)), but since redistributeSplitExpenseAmounts already handles all edge cases correctly, the simplest approach is to always call it.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
changed the title [-]Split expense - Third split is added as 0 after click 'Add split'[/-][+][$250] Split expense - Third split is added as 0 after click 'Add split'[/+]on Apr 8, 2026
Please re-state the problem that we are trying to solve in this issue.
When a user splits a $10 expense, edits split A to $3 (which auto-updates split B to $7), and then clicks "Add Split", the third split is created with an amount of $0. The expected behavior is that the remaining $7 should be redistributed among the two unedited splits so each becomes $3.50.
What is the root cause of that problem?
The gating condition that was added to addSplitExpenseField in src/libs/actions/IOU/Split.ts skips redistribution in exactly this scenario:
redistributeSplitExpenseAmounts is skipped and the newly appended split keeps its initial value of 0.
In practice the guard collapses to "whenever any split has ever been edited, keep the new split at zero". That is because updateSplitExpenseAmountField rebalances the unedited splits every time the edited one changes, so by the time the user clicks "Add Split" the existing splits almost always sum to the total. The only way for splitsAlreadyMatchTotal to be false is if the user has edited multiple splits to under- or over-shoot the total, which is a different code path that redistributeSplitExpenseAmounts would handle anyway.
redistributeSplitExpenseAmounts itself is already correct — it filters out edited splits via split.isManuallyEdited, computes remaining = total - editedSum, and distributes only the remainder among the unedited splits (including the freshly appended zero one):
Additionally, the existing Jest case should preserve edited splits when adding a new split at tests/unit/SplitExpenseAutoAdjustmentTest.ts was intended to cover exactly this behavior — its comment block reads "New split + Split 2: share remaining 700 -> 350 each" — but it only asserts that split 1 stays locked at 300 and that the total still equals 1000. It never asserts the value of the unedited splits, so the regression passed the test with [300, 700, 0] even though that contradicts the comment. This assertion gap is why the bug landed undetected.
What changes do you think we should make in order to solve the problem?
Remove the shouldRedistribute gate in addSplitExpenseField and always run redistributeSplitExpenseAmounts on the updated array for non-distance requests. The lines that compute existingSum, hasManuallyEditedSplits, splitsAlreadyMatchTotal, and shouldRedistribute can all be dropped.
Verifying this is safe by re-running both relevant scenarios against redistributeSplitExpenseAmounts:
Bug scenario — [A = $3 edited, B = $7 unedited] → append C = $0 unedited:
editedSum = $3
uneditedSplits = [B, C], uneditedCount = 2
remaining = $10 − $3 = $7
Distributed via calculateIOUAmount → B = $3.50, C = $3.50
Final: [A = $3, B = $3.50, C = $3.50] ✅ matches expected result
The scenario PR #87124 was originally guarding — [A = $5 edited, B = $5 edited] → append C = $0 unedited:
editedSum = $10
uneditedSplits = [C], uneditedCount = 1
remaining = $10 − $10 = $0
C = calculateIOUAmount(0, 0, USD, true, true) = $0
Final: [A = $5, B = $5, C = $0] ✅ same outcome as the skip branch
So unconditionally calling redistributeSplitExpenseAmounts fixes the reported bug without regressing the all-edited case. The existing test should keep new split at 0 when manual edits exist and sum matches total continues to pass unchanged.
As part of the fix, the assertions in the should preserve edited splits when adding a new split test should also be tightened to explicitly check that split2 and the new split are both 350, matching the test's own comment. That closes the regression-detection gap that let this bug slip through.
What alternative solutions did you explore? (Optional)
One alternative is to keep the guard but recompute splitsAlreadyMatchTotal against updatedSplitExpenses (which includes the new zero split) instead of existingSplits. In the bug scenario the sum is still numerically $10, so this alone does not help — it would need to be combined with an extra check like "any unedited split has amount === 0". That adds branching for no benefit: redistributeSplitExpenseAmounts is already effectively a no-op when the unedited splits do not need to change (remaining === 0 makes calculateIOUAmount return 0), so the guard is unnecessary. Dropping it is simpler and strictly more correct.
Please re-state the problem that we are trying to solve in this issue.
When a user starts a brand-new split from an expense, manually changes one split amount, and then taps Add split, the newly added split is created with 0 instead of sharing the remaining amount with the still auto-managed split rows.
What is the root cause of that problem?
The bug is in the SplitExpensePage -> addSplitExpenseField() path, not in redistributeSplitExpenseAmounts() itself.
Here is the real sequence in the current code:
In the initial split flow, initSplitExpense() creates the two starting split rows with isManuallyEdited: false in (src/libs/actions/SplitExpenses.ts).
When the user edits split A, updateSplitExpenseAmountField() marks only that row as isManuallyEdited: true and then correctly redistributes the remainder to the unedited rows in (src/libs/actions/IOU/Split.ts).
When the user taps Add split, SplitExpensePage calls addSplitExpenseField() in (src/pages/iou/SplitExpensePage.tsx).
After step 2, the draft already matches the total, and at least one split is manually edited, so shouldRedistribute becomes false. That skips redistributeSplitExpenseAmounts(), and the new split stays at its initialized amount of 0.
The guard is too broad because it collapses two different product states into one:
Initial split flow: only some rows are manually edited, and the remaining auto-managed rows should still rebalance.
Re-opened existing split flow: initSplitExpense() seeds child transactions with isManuallyEdited: true in (src/libs/actions/SplitExpenses.ts), so when all existing rows already sum to the total, the new split should stay 0 to preserve the behavior introduced for #82455.
So the actual root cause is that addSplitExpenseField() checks whether any existing split is manually edited, when it should only skip redistribution when all existing splits are manually edited and the draft already balances.
What changes do you think we should make in order to solve the problem?
Keep the current architecture and helper usage, but narrow the addSplitExpenseField() guard so we only skip redistribution for the #82455 case: when every existing split is already user-managed and the current draft already sums to the original amount.
That gives us the correct behavior in both codepaths:
Initial split flow: at least one existing split is still auto-managed, so adding a new split redistributes the remaining amount across the unedited rows.
Re-opened existing split flow: all existing child splits are already marked isManuallyEdited: true, so adding a new split keeps it at 0 when the draft already balances.
This is stronger than removing the guard entirely because it fixes this regression without reintroducing the behavior that #87124 intentionally preserved.
Implementation
// File: src/libs/actions/IOU/Split.ts
@@
- const hasManuallyEditedSplits = existingSplits.some((split) => split.isManuallyEdited);+ const hasUneditedSplits = existingSplits.some((split) => !split.isManuallyEdited);
const splitsAlreadyMatchTotal = Math.abs(existingSum) === Math.abs(total);
let redistributedSplitExpenses = updatedSplitExpenses;
- // Skip redistribution only when manual edits exist AND splits sum to total- const shouldRedistribute = !splitsAlreadyMatchTotal || !hasManuallyEditedSplits;+ // Only keep the new split at 0 when the draft already balances and every existing split is user-managed.+ const shouldRedistribute = !splitsAlreadyMatchTotal || hasUneditedSplits;
if (!isDistanceRequest && shouldRedistribute) {
redistributedSplitExpenses = redistributeSplitExpenseAmounts(updatedSplitExpenses, total, currency);
}
This works because redistributeSplitExpenseAmounts() already has the correct behavior for mixed states: it preserves isManuallyEdited rows and only redistributes the remainder across unedited rows. The change simply makes sure we still call that helper in the initial split flow, while preserving the intentional skip for previously-saved split expenses where all rows are already locked.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
None
What alternative solutions did you explore? (Optional)
Removing the guard entirely and always redistributing is weaker because it would also change the re-opened existing-split behavior that #82455 intentionally protected.
Recomputing the sum against updatedSplitExpenses is also weaker, because appending a new 0 split does not change the numeric sum, so that still does not distinguish between “some rows are still auto-managed” and “all rows are already manually owned.”
⚠️@MassoudFSharifi Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
The split flow preserves manually edited rows and redistributes only the unedited rows. When a user edits A to $3, A becomes manually edited and B stays unedited. After that, clicking Add split appends a new unedited split C with amount 0.
The bug is in the redistribution guard: it skips redistribution whenever splits already match the total and there is at least one manual edit. In this case, that condition is too broad because B and C are still unedited and should be redistributed to share the remaining amount.
What changes do you think we should make in order to solve the problem?
We should only skip redistribution when all existing splits are manually edited and already sum to the total. If at least one existing split is unedited, the remaining amount should be redistributed across unedited splits (including the newly added split), which gives the expected $3 / $3.50 / $3.50 result for a $10 total after editing A to $3.
@ahmedGaber93 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Activity
MelvinBot commentedon Apr 8, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When splitting a $10 expense where Split A is manually set to $3 and Split B auto-calculates to $7, clicking "Add Split" creates a third split with $0 instead of redistributing the remaining $7 evenly among the two unedited splits (B=$3.50, C=$3.50).
What is the root cause of that problem?
This is a regression from PR #87124 (which fixed #82455). That PR added a condition at
src/libs/actions/IOU/Split.ts:2647that skips redistribution when manually-edited splits exist AND the existing splits already sum to the total:The problem:
splitsAlreadyMatchTotalchecks the existing splits (before the new one is added). Since existing splits almost always sum to the total, and any user edit setshasManuallyEditedSplits = true, redistribution is skipped every time a user adds a split after editing any amount. The new split stays at its initialized value of $0.The
redistributeSplitExpenseAmountsfunction (Split.ts:2554-2581) already handles this correctly — it preserves manually-edited amounts and distributes the remainder among unedited splits. It just never gets called.What changes do you think we should make in order to fix the problem?
Modify the condition at Split.ts:2647 to check whether the updated splits (including the new $0 split) sum to the total, rather than the existing splits:
Since the new split has amount=0 and existing splits summed to the total,
updatedSumwill still equal the total numerically — but the key insight is that now there's an unedited split with $0 that needs a share. A cleaner alternative: always redistribute whenaddSplitExpenseFieldis called, since the entire purpose of this function is to add a new split that needs an amount. The edge case PR #87124 solved (edited amount exceeding total) is already handled correctly byredistributeSplitExpenseAmounts— it computesremaining = total - editedSum, which would be negative when edits exceed the total, and distributes that among unedited splits.The simplest fix: remove the redistribution skip in
addSplitExpenseFieldentirely — always callredistributeSplitExpenseAmounts(for non-distance requests):This preserves the original intent (user-edited amounts stay fixed, unedited splits share the remainder) while ensuring newly-added splits receive a proper amount.
What alternative solutions did you explore? (Optional)
The condition could be patched more narrowly (e.g., adding
|| updatedSplitExpenses.some(s => s.amount === 0 && !s.isManuallyEdited)), but sinceredistributeSplitExpenseAmountsalready handles all edge cases correctly, the simplest approach is to always call it.Related issues
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 8, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ahmedGaber93 (
External)[-]Split expense - Third split is added as 0 after click 'Add split'[/-][+][$250] Split expense - Third split is added as 0 after click 'Add split'[/+]melvin-bot commentedon Apr 8, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022041862880505545592
wildan-m commentedon Apr 8, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user splits a $10 expense, edits split A to $3 (which auto-updates split B to $7), and then clicks "Add Split", the third split is created with an amount of $0. The expected behavior is that the remaining $7 should be redistributed among the two unedited splits so each becomes $3.50.
What is the root cause of that problem?
The gating condition that was added to
addSplitExpenseFieldinsrc/libs/actions/IOU/Split.tsskips redistribution in exactly this scenario:App/src/libs/actions/IOU/Split.ts
Lines 2639 to 2650 in 946de58
Walking through the condition with the reported reproduction data (total = $10, existing splits
[A = $3 edited, B = $7 unedited]):existingSum = 3 + 7 = 10splitsAlreadyMatchTotal = Math.abs(10) === Math.abs(10)→truehasManuallyEditedSplits = true(A was edited)shouldRedistribute = !true || !true→falseredistributeSplitExpenseAmountsis skipped and the newly appended split keeps its initial value of0.In practice the guard collapses to "whenever any split has ever been edited, keep the new split at zero". That is because
updateSplitExpenseAmountFieldrebalances the unedited splits every time the edited one changes, so by the time the user clicks "Add Split" the existing splits almost always sum to the total. The only way forsplitsAlreadyMatchTotalto befalseis if the user has edited multiple splits to under- or over-shoot the total, which is a different code path thatredistributeSplitExpenseAmountswould handle anyway.redistributeSplitExpenseAmountsitself is already correct — it filters out edited splits viasplit.isManuallyEdited, computesremaining = total - editedSum, and distributes only the remainder among the unedited splits (including the freshly appended zero one):App/src/libs/actions/IOU/Split.ts
Lines 2554 to 2581 in 946de58
Additionally, the existing Jest case
should preserve edited splits when adding a new splitattests/unit/SplitExpenseAutoAdjustmentTest.tswas intended to cover exactly this behavior — its comment block reads "New split + Split 2: share remaining 700 -> 350 each" — but it only asserts that split 1 stays locked at 300 and that the total still equals 1000. It never asserts the value of the unedited splits, so the regression passed the test with[300, 700, 0]even though that contradicts the comment. This assertion gap is why the bug landed undetected.App/tests/unit/SplitExpenseAutoAdjustmentTest.ts
Lines 93 to 133 in 946de58
What changes do you think we should make in order to solve the problem?
Remove the
shouldRedistributegate inaddSplitExpenseFieldand always runredistributeSplitExpenseAmountson the updated array for non-distance requests. The lines that computeexistingSum,hasManuallyEditedSplits,splitsAlreadyMatchTotal, andshouldRedistributecan all be dropped.Verifying this is safe by re-running both relevant scenarios against
redistributeSplitExpenseAmounts:Bug scenario —
[A = $3 edited, B = $7 unedited]→ appendC = $0 unedited:editedSum = $3uneditedSplits = [B, C],uneditedCount = 2remaining = $10 − $3 = $7calculateIOUAmount→B = $3.50,C = $3.50[A = $3, B = $3.50, C = $3.50]✅ matches expected resultThe scenario PR #87124 was originally guarding —
[A = $5 edited, B = $5 edited]→ appendC = $0 unedited:editedSum = $10uneditedSplits = [C],uneditedCount = 1remaining = $10 − $10 = $0C = calculateIOUAmount(0, 0, USD, true, true) = $0[A = $5, B = $5, C = $0]✅ same outcome as the skip branchSo unconditionally calling
redistributeSplitExpenseAmountsfixes the reported bug without regressing the all-edited case. The existing testshould keep new split at 0 when manual edits exist and sum matches totalcontinues to pass unchanged.As part of the fix, the assertions in the
should preserve edited splits when adding a new splittest should also be tightened to explicitly check thatsplit2and the new split are both350, matching the test's own comment. That closes the regression-detection gap that let this bug slip through.What alternative solutions did you explore? (Optional)
One alternative is to keep the guard but recompute
splitsAlreadyMatchTotalagainstupdatedSplitExpenses(which includes the new zero split) instead ofexistingSplits. In the bug scenario the sum is still numerically$10, so this alone does not help — it would need to be combined with an extra check like "any unedited split hasamount === 0". That adds branching for no benefit:redistributeSplitExpenseAmountsis already effectively a no-op when the unedited splits do not need to change (remaining === 0makescalculateIOUAmountreturn 0), so the guard is unnecessary. Dropping it is simpler and strictly more correct.Compare branch
https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/87378-split-add-zero?expand=1
wildan-m commentedon Apr 8, 2026
Proposal updated — added compare branch with implementation.
MassoudFSharifi commentedon Apr 8, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user starts a brand-new split from an expense, manually changes one split amount, and then taps
Add split, the newly added split is created with0instead of sharing the remaining amount with the still auto-managed split rows.What is the root cause of that problem?
The bug is in the
SplitExpensePage -> addSplitExpenseField()path, not inredistributeSplitExpenseAmounts()itself.Here is the real sequence in the current code:
initSplitExpense()creates the two starting split rows withisManuallyEdited: falsein (src/libs/actions/SplitExpenses.ts).updateSplitExpenseAmountField()marks only that row asisManuallyEdited: trueand then correctly redistributes the remainder to the unedited rows in (src/libs/actions/IOU/Split.ts).Add split,SplitExpensePagecallsaddSplitExpenseField()in (src/pages/iou/SplitExpensePage.tsx).addSplitExpenseField()currently computes:hasManuallyEditedSplits = existingSplits.some((split) => split.isManuallyEdited)splitsAlreadyMatchTotal = Math.abs(existingSum) === Math.abs(total)shouldRedistribute = !splitsAlreadyMatchTotal || !hasManuallyEditedSplitsshouldRedistributebecomesfalse. That skipsredistributeSplitExpenseAmounts(), and the new split stays at its initialized amount of0.The guard is too broad because it collapses two different product states into one:
initSplitExpense()seeds child transactions withisManuallyEdited: truein (src/libs/actions/SplitExpenses.ts), so when all existing rows already sum to the total, the new split should stay0to preserve the behavior introduced for#82455.So the actual root cause is that
addSplitExpenseField()checks whether any existing split is manually edited, when it should only skip redistribution when all existing splits are manually edited and the draft already balances.What changes do you think we should make in order to solve the problem?
Keep the current architecture and helper usage, but narrow the
addSplitExpenseField()guard so we only skip redistribution for the#82455case: when every existing split is already user-managed and the current draft already sums to the original amount.That gives us the correct behavior in both codepaths:
isManuallyEdited: true, so adding a new split keeps it at0when the draft already balances.This is stronger than removing the guard entirely because it fixes this regression without reintroducing the behavior that
#87124intentionally preserved.Implementation
This works because
redistributeSplitExpenseAmounts()already has the correct behavior for mixed states: it preservesisManuallyEditedrows and only redistributes the remainder across unedited rows. The change simply makes sure we still call that helper in the initial split flow, while preserving the intentional skip for previously-saved split expenses where all rows are already locked.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
None
What alternative solutions did you explore? (Optional)
Removing the guard entirely and always redistributing is weaker because it would also change the re-opened existing-split behavior that
#82455intentionally protected.Recomputing the sum against
updatedSplitExpensesis also weaker, because appending a new0split does not change the numeric sum, so that still does not distinguish between “some rows are still auto-managed” and “all rows are already manually owned.”github-actions commentedon Apr 8, 2026
abbasifaizan70 commentedon Apr 8, 2026
Proposal
What is the root cause of that problem?
The split flow preserves manually edited rows and redistributes only the unedited rows. When a user edits A to
$3, A becomes manually edited and B stays unedited. After that, clicking Add split appends a new unedited split C with amount0.The bug is in the redistribution guard: it skips redistribution whenever splits already match the total and there is at least one manual edit. In this case, that condition is too broad because B and C are still unedited and should be redistributed to share the remaining amount.
App/src/libs/actions/IOU/Split.ts
Lines 2639 to 2648 in 24db80a
What changes do you think we should make in order to solve the problem?
We should only skip redistribution when all existing splits are manually edited and already sum to the total. If at least one existing split is unedited, the remaining amount should be redistributed across unedited splits (including the newly added split), which gives the expected
$3 / $3.50 / $3.50result for a$10total after editing A to$3.App/src/libs/actions/IOU/Split.ts
Lines 2639 to 2648 in 24db80a
App/tests/unit/SplitExpenseAutoAdjustmentTest.ts
Lines 93 to 133 in 24db80a
21 remaining items
melvin-bot commentedon Apr 21, 2026
@ahmedGaber93 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
ahmedGaber93 commentedon Apr 21, 2026
Waiting on @garrettmknight input #87378 (comment)
melvin-bot commentedon Apr 22, 2026
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
melvin-bot commentedon Apr 22, 2026
@ahmedGaber93 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
melvin-bot commentedon Apr 24, 2026
@ahmedGaber93 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
ahmedGaber93 commentedon Apr 26, 2026
Not overdue #87378 (comment)
garrettmknight commentedon Apr 27, 2026
Missed the initial ping, sorry. gents. I think the behavior here is expected and after testing in Classic reflects the pattern there, too.
ahmedGaber93 commentedon Apr 28, 2026
@garrettmknight Great! Should we close it then? CC @blimpich