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
[Duplicate expense] Distance- Duplicate is map distance expense when original expense is a manual distance expense #84188
Version Number: 9.3.31-0 Reproducible in staging?: Yes Reproducible in production?: N/A - new feature, doesn't exist in prod If this was caught during regression testing, add the test name, ID and link from BrowserStack:#82005 Email or phone of affected tester (no customers):jsodijnsoinjdojoijsoid@gmail.com Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 26.2 / Chrome App Component: Money Requests
Wait for receipt to load, then click Distance field.
Expected Result:
Since the distance expense is duplicated from a manual distance expense (as a result of duplicating split map distance expense), the duplicate should remain as manual distance expense.
Actual Result:
When the distance expense is duplicated from a manual distance expense, the duplicate reverts to map distance expense.
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
Classification: Frontend bug Causing PR: #82005 - "[Duplicate Expenses] Re-enable Distance Expense Support with fixes" by @jjcoffee (High confidence) Related Issues: None
Recommendation: REVERT
PR #82005 introduced logic to handle duplicating split distance expenses, but there is a bug in how it copies transaction data. When duplicating a split distance expense that was converted to manual distance, the duplicate incorrectly reverts to the original map distance type because the code copies the entire transaction.comment object which contains stale distance type information.
Labels: No label changes needed - keeping DeployBlockerCash as this is a frontend bug caused by an App PR.
📋 Detailed Analysis
Evidence
The issue reporter mentions PR #82005 in the reproduction steps, and melvin-bot correctly identified this PR as the cause. The bug is reproducible only on staging where this PR is deployed, and the issue directly relates to the duplicate distance expense feature that was re-enabled in this PR.
The changes specifically handle split distance expenses (lines 549, 599-601)
The PR was merged on 2026-03-04 and is included in the staging deploy checklist
Root Cause
In src/libs/actions/IOU/Duplicate.ts, the duplicateExpenseTransaction function at lines 611-622 (track expense) and 653-664 (distance request) creates an existingTransaction object by copying the original transaction.comment:
existingTransaction: {
...(params.transactionParams??{}),comment: {
...transaction.comment,// BUG: This copies stale distance type infooriginalTransactionID: undefined,source: undefined,},iouRequestType: getRequestType(transaction),// ...}
When a split distance expense is converted from map to manual distance:
The transaction object gets updated with new distance type
But the comment field may still contain the original map distance metadata
When duplicating, the code copies this stale comment data
The duplicate incorrectly uses the original map distance type instead of the current manual type
This is a data consistency issue where the transaction comment is not properly synchronized with the current distance request type when duplicating previously-modified split distance expenses.
Please re-state the problem that we are trying to solve in this issue.
When a user duplicates a manual distance expense (which was itself created by duplicating a split map distance expense), the second duplicate incorrectly reverts to a map distance expense instead of remaining a manual distance expense.
What is the root cause of that problem?
The root cause is in src/libs/actions/IOU/Duplicate.ts at lines 655-660. When building the existingTransaction for the createDistanceRequest call, the code spreads ...transaction.comment which includes the original waypoints from the source transaction. While transactionParams.waypoints is correctly set to undefined for split expenses (line 549), the waypoints leak through via existingTransaction.comment.
This causes two problems:
Waypoint leakage via fastMerge: In getMoneyRequestInformation (src/libs/actions/IOU/index.ts:3569-3580), the existingTransaction (containing the leaked waypoints in its comment) is merged into the optimistic transaction via fastMerge. This causes the saved transaction to retain waypoints in comment.waypoints.
Incorrect iouRequestType: getRequestType(transaction) at line 660 evaluates the original split map distance transaction, which has waypoints, so it returns DISTANCE_MAP. This causes getMoneyRequestInformation (line 3514) to classify the expense as non-manual (isManualDistanceRequest = false), which then sets pendingFields.waypoints = ADD (line 3538). In buildOptimisticTransaction (line 502), !!pendingFields.waypoints triggers map distance treatment.
As a result, the first duplicate is saved with waypoints and classified as map distance. When that expense is duplicated again, isExpenseSplit() returns false (because originalTransactionID and source were cleared), so the waypoints pass through normally, and the expense becomes a map distance expense.
What changes do you think we should make in order to solve the problem?
In src/libs/actions/IOU/Duplicate.ts, when building the existingTransaction.comment (lines 655-658 for the distance case, and lines 613-616 for the track expense case), strip waypoints from the comment when duplicating a split expense:
Add waypoints: waypoints ? transaction.comment?.waypoints : undefined to the comment spread, so that when waypoints is undefined (split expense case), the comment's waypoints are also cleared.
Similarly, set iouRequestType to CONST.IOU.REQUEST_TYPE.DISTANCE_MANUAL when isExpenseSplit(transaction) && isDistanceRequest(transaction), instead of using getRequestType(transaction) which evaluates against the original transaction's waypoints.
This ensures both the existingTransaction.comment.waypoints and existingTransaction.iouRequestType are consistent with the intended manual distance behavior for duplicated split expenses.
What alternative solutions did you explore?
An alternative would be to fix this downstream in getMoneyRequestInformation by stripping waypoints from existingTransaction.comment before the fastMerge. However, fixing it at the source in Duplicate.ts is cleaner because the intent to strip waypoints for split expenses is already established there (line 549), and the fix keeps the data consistent from the start of the flow.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
@MelvinBot Your RCA seems to be correct, but the solution is missing an important detail. Following the OP steps closely, you can see that the split expense is duplicated, becomes a "normal" (non-split) expense and then is duplicated again (where the issue occurs). So waypoints" would not be defined for that case as isExpenseSplit(transaction)` is false.
@JS00001 I reckon this one can be demoted as it's a bit of a convoluted flow. Create Expense -> Split Expense -> Duplicate one of the splits -> Duplicate the duplicate again.
Thanks for the feedback. You're right — let me clarify the data flow and the fix more precisely.
The two-step chain
Step A (first duplication — split→duplicate, isExpenseSplit = true):
At Duplicate.ts:549, waypoints is correctly set to undefined. But at line 655-656, existingTransaction.comment spreads ...transaction.comment which includes the original map waypoints. After fastMerge at IOU/index.ts:3576, these leaked waypoints are baked into the stored first duplicate's comment.waypoints.
Additionally, getRequestType(transaction) at line 660 evaluates the original split child (which has waypoints), returning DISTANCE_MAP. This sets existingTransaction.iouRequestType = DISTANCE_MAP, causing getMoneyRequestInformation to treat it as map distance (pendingFields.waypoints = ADD).
So the first duplicate is actually stored with leaked waypoints in comment.waypoints — the underlying data is map distance, even though the UI may re-classify it when the user clicks the Distance field.
Step B (second duplication — isExpenseSplit = false, where the bug manifests):
As you pointed out, isExpenseSplit(transaction) is false here. So waypoints = transactionDetails?.waypoints at line 549. Since getTransactionDetails calls getWaypoints() which reads transaction?.comment?.waypoints (the leaked ones from step A), transactionDetails?.waypoints returns the leaked waypoints — it is NOT undefined.
This means waypoints at line 549 is defined (the leaked waypoints), which flows through the entire pipeline:
validWaypoints = leaked waypoints → isManualDistanceRequest = false in createDistanceRequest
getRequestType(transaction) = DISTANCE_MAP (because the saved transaction has non-empty comment.waypoints)
existingTransaction.comment at line 655 again spreads ...transaction.comment with leaked waypoints
Result: fully classified as map distance
Updated fix
The fix still needs to target existingTransaction.comment at Duplicate.ts:655-658 (and the equivalent at lines 613-616 for the track expense path), since that's where the leak originates during step A. Stripping waypoints from the comment spread when isExpenseSplit(transaction) is true prevents the leaked data from persisting into the first duplicate, which in turn prevents the second duplication from seeing any waypoints.
Same changes at lines 613-618 for the track expense path.
This fixes both step A (first duplicate gets correct manual distance data) and step B (second duplicate sees clean manual distance data with no waypoints to leak through).
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
Activity
melvin-bot commentedon Mar 4, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #82005
melvin-bot commentedon Mar 4, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Mar 4, 2026
Triggered auto assignment to @JmillsExpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.github-actions commentedon Mar 4, 2026
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
OSBotify commentedon Mar 4, 2026
🔍 Investigation Summary
Classification: Frontend bug
Causing PR: #82005 - "[Duplicate Expenses] Re-enable Distance Expense Support with fixes" by @jjcoffee (High confidence)
Related Issues: None
Recommendation: REVERT
PR #82005 introduced logic to handle duplicating split distance expenses, but there is a bug in how it copies transaction data. When duplicating a split distance expense that was converted to manual distance, the duplicate incorrectly reverts to the original map distance type because the code copies the entire
transaction.commentobject which contains stale distance type information.Labels: No label changes needed - keeping
DeployBlockerCashas this is a frontend bug caused by an App PR.📋 Detailed Analysis
Evidence
The issue reporter mentions PR #82005 in the reproduction steps, and melvin-bot correctly identified this PR as the cause. The bug is reproducible only on staging where this PR is deployed, and the issue directly relates to the duplicate distance expense feature that was re-enabled in this PR.
Verification
I examined the PR diff and confirmed that:
src/libs/actions/IOU/Duplicate.ts(the duplicate expense logic)Root Cause
In
src/libs/actions/IOU/Duplicate.ts, theduplicateExpenseTransactionfunction at lines 611-622 (track expense) and 653-664 (distance request) creates anexistingTransactionobject by copying the originaltransaction.comment:When a split distance expense is converted from map to manual distance:
This is a data consistency issue where the transaction comment is not properly synchronized with the current distance request type when duplicating previously-modified split distance expenses.
MelvinBot commentedon Mar 4, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user duplicates a manual distance expense (which was itself created by duplicating a split map distance expense), the second duplicate incorrectly reverts to a map distance expense instead of remaining a manual distance expense.
What is the root cause of that problem?
The root cause is in
src/libs/actions/IOU/Duplicate.tsat lines 655-660. When building theexistingTransactionfor thecreateDistanceRequestcall, the code spreads...transaction.commentwhich includes the original waypoints from the source transaction. WhiletransactionParams.waypointsis correctly set toundefinedfor split expenses (line 549), the waypoints leak through viaexistingTransaction.comment.This causes two problems:
Waypoint leakage via
fastMerge: IngetMoneyRequestInformation(src/libs/actions/IOU/index.ts:3569-3580), theexistingTransaction(containing the leaked waypoints in itscomment) is merged into the optimistic transaction viafastMerge. This causes the saved transaction to retain waypoints incomment.waypoints.Incorrect
iouRequestType:getRequestType(transaction)at line 660 evaluates the original split map distance transaction, which has waypoints, so it returnsDISTANCE_MAP. This causesgetMoneyRequestInformation(line 3514) to classify the expense as non-manual (isManualDistanceRequest = false), which then setspendingFields.waypoints = ADD(line 3538). InbuildOptimisticTransaction(line 502),!!pendingFields.waypointstriggers map distance treatment.As a result, the first duplicate is saved with waypoints and classified as map distance. When that expense is duplicated again,
isExpenseSplit()returns false (becauseoriginalTransactionIDandsourcewere cleared), so the waypoints pass through normally, and the expense becomes a map distance expense.What changes do you think we should make in order to solve the problem?
In
src/libs/actions/IOU/Duplicate.ts, when building theexistingTransaction.comment(lines 655-658 for the distance case, and lines 613-616 for the track expense case), strip waypoints from the comment when duplicating a split expense:waypoints: waypoints ? transaction.comment?.waypoints : undefinedto the comment spread, so that whenwaypointsisundefined(split expense case), the comment's waypoints are also cleared.iouRequestTypetoCONST.IOU.REQUEST_TYPE.DISTANCE_MANUALwhenisExpenseSplit(transaction) && isDistanceRequest(transaction), instead of usinggetRequestType(transaction)which evaluates against the original transaction's waypoints.This ensures both the
existingTransaction.comment.waypointsandexistingTransaction.iouRequestTypeare consistent with the intended manual distance behavior for duplicated split expenses.What alternative solutions did you explore?
An alternative would be to fix this downstream in
getMoneyRequestInformationby stripping waypoints fromexistingTransaction.commentbefore thefastMerge. However, fixing it at the source inDuplicate.tsis cleaner because the intent to strip waypoints for split expenses is already established there (line 549), and the fix keeps the data consistent from the start of the flow.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.3 remaining items
jjcoffee commentedon Mar 5, 2026
@MelvinBot Your RCA seems to be correct, but the solution is missing an important detail. Following the OP steps closely, you can see that the split expense is duplicated, becomes a "normal" (non-split) expense and then is duplicated again (where the issue occurs). So
waypoints" would not be defined for that case asisExpenseSplit(transaction)` is false.jjcoffee commentedon Mar 5, 2026
@JS00001 I reckon this one can be demoted as it's a bit of a convoluted flow. Create Expense -> Split Expense -> Duplicate one of the splits -> Duplicate the duplicate again.
MelvinBot commentedon Mar 5, 2026
Thanks for the feedback. You're right — let me clarify the data flow and the fix more precisely.
The two-step chain
Step A (first duplication — split→duplicate,
isExpenseSplit= true):At
Duplicate.ts:549,waypointsis correctly set toundefined. But at line 655-656,existingTransaction.commentspreads...transaction.commentwhich includes the original map waypoints. AfterfastMergeatIOU/index.ts:3576, these leaked waypoints are baked into the stored first duplicate'scomment.waypoints.Additionally,
getRequestType(transaction)at line 660 evaluates the original split child (which has waypoints), returningDISTANCE_MAP. This setsexistingTransaction.iouRequestType = DISTANCE_MAP, causinggetMoneyRequestInformationto treat it as map distance (pendingFields.waypoints = ADD).So the first duplicate is actually stored with leaked waypoints in
comment.waypoints— the underlying data is map distance, even though the UI may re-classify it when the user clicks the Distance field.Step B (second duplication —
isExpenseSplit= false, where the bug manifests):As you pointed out,
isExpenseSplit(transaction)isfalsehere. Sowaypoints = transactionDetails?.waypointsat line 549. SincegetTransactionDetailscallsgetWaypoints()which readstransaction?.comment?.waypoints(the leaked ones from step A),transactionDetails?.waypointsreturns the leaked waypoints — it is NOT undefined.This means
waypointsat line 549 is defined (the leaked waypoints), which flows through the entire pipeline:validWaypoints= leaked waypoints →isManualDistanceRequest = falseincreateDistanceRequestgetRequestType(transaction)=DISTANCE_MAP(because the saved transaction has non-emptycomment.waypoints)existingTransaction.commentat line 655 again spreads...transaction.commentwith leaked waypointsUpdated fix
The fix still needs to target
existingTransaction.commentatDuplicate.ts:655-658(and the equivalent at lines 613-616 for the track expense path), since that's where the leak originates during step A. Stripping waypoints from the comment spread whenisExpenseSplit(transaction)is true prevents the leaked data from persisting into the first duplicate, which in turn prevents the second duplication from seeing any waypoints.Specifically, at lines 655-658:
And at line 660, the
iouRequestTypeshould also be corrected for split distance expenses:Same changes at lines 613-618 for the track expense path.
This fixes both step A (first duplicate gets correct manual distance data) and step B (second duplicate sees clean manual distance data with no waypoints to leak through).
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.JS00001 commentedon Mar 5, 2026
Agreed @jjcoffee , going to demote this but lets fix it in a follow up please
JS00001 commentedon Mar 5, 2026
Closing out in favor of #84280, so there's less noise