[Due for payment 2026-11-13] [$175] [Exploratory] Distance - Duplicating expense with alternate route doesn't duplicate the route
If you havenβt already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.5.1-9 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/folder/57599980/test-cases/41237143 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Desktop / Windows 11 App Component: Money Requests
Action Performed:
- Open the Workspace and log in
- Click on the global FAB and click on "Track distance"
- Set the start and end points on the map
- When the route is calculated, select an alternate route shown on the map
- Click on "Next" and click on "Create expense"
- Click on the created expense to open it
- Click on "More" and click on "Duplicate expense"
- Observe the distance and the map of the duplicated expense
Expected Result:
The alternate route should be duplicated as well as all other data from the original expense.
Actual Result:
The alternate route is not copied into the duplicate of the original expense. It causes a difference in the distance between two expenses that should be the same and triggers an error.
Workaround:
Unknown
Platforms:
- [x] Android: App
- [ ] Android: mWeb Chrome
- [x] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/990e4e8e-334f-4387-8608-96aaa0e31493
Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7277274
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022115070823337425135
- Upwork Job ID: 2115070823337425135
- Last Price Increase: 2026-10-27
Issue Owner
Current Issue Owner: @mallenexpensify
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/843c8daf70550ea9b8512beb5c59514a517f589397c1be0fa47b84964a9f3161
https://platform.applause.com/services/links/v1/external/723df821af156b2fc4cd8e42db78fbd443a1476eaa9e1b518f8de867e7f4cb38
this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Similar issue reported here as well (https://expensify.slack.com/archives/C049HHMV9SM/p1793052323348019)
@MelvinBot Please investigate this and assign accordingly
Proposal
Please re-state the problem that we are trying to solve in this issue.
When you duplicate a map distance expense that uses the alternate route, the duplicate gets the primary route. The distance changes, and the amount no longer matches the distance.
What is the root cause of that problem?
The backend learns which route you picked only from the selectedRouteDistance API param. Normal create and edit flows send it, for example useDistanceSubmission.ts:190. Without it, the backend uses the primary route. The param's own comment says this: Split.ts:125-126.
The duplicate flow never sets selectedRouteDistance. buildDuplicateTransactionParams copies only the waypoints. It sets distance only for split, odometer, or manual expenses (L665-L668). So the duplicate sends the waypoints and the alternate route's amount (L755-L761). The backend then recalculates the distance using the primary route. That mismatch between amount and distance explains the error in the video.
What changes do you think we should make in order to solve the problem?
- In
buildDuplicateTransactionParams, for map distance expenses only, setselectedRouteDistancefrom the source expense. UsegetSelectedRouteDistance(transaction)and fall back totransaction.comment.customUnit.routeDistanceMeters. A saved expense often has noroutes, so the saved meters value is the reliable source (TransactionUtils/index.ts:1795-1803). - No other wiring is needed.
createDistanceRequest(Split.ts:2116) andtrackExpense(TrackExpense.ts:2580) already read it fromtransactionParams. This covers both the workspace and the self-DM duplicate paths. - Optional: copy
routesinto the duplicate's optimistic transaction so the map shows the alternate route right away. - Add a test in
tests/actions/IOUTest/DuplicateTest.tsthat checksselectedRouteDistanceis sent when you duplicate an alternate-route expense.
What alternative solutions did you explore? (Optional)
Sending distance for map expenses as well. We rejected this because map expenses rely on waypoints plus the selected route. selectedRouteDistance is the field built for this case.
Notes
- The fix is App-only. The backend already accepts
selectedRouteDistanceon create. We have not confirmed the exact backend error text. - No duplicate issue found. I added
Externalso a C+ can review this.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/102946) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @hoangzinh (External)
Job added to Upwork: https://www.upwork.com/jobs/~022115070823337425135
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01af851c9a7f771775
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user duplicates a distance expense that was created using an alternate route, the duplicated expense reverts to the primary route and recalculates the distance, resulting in a distance mismatch error.
What is the root cause of that problem?
When duplicating a distance expense, buildDuplicateTransactionParams in src/libs/actions/IOU/Duplicate.ts constructs DistanceRequestTransactionParams to pass to createDistanceRequest. While it copies waypoints, receipt information, and base parameters, it does not set selectedRouteDistance.
The original transaction stores the selected alternate route's distance in meters under transaction.comment?.customUnit?.routeDistanceMeters. Because selectedRouteDistance is omitted during duplicate construction, the server request and optimistic payload treat the request as defaulting to the primary route (route0), discarding the alternate route chosen on the original transaction.
What changes do you think we should make in order to solve the problem?
- In
src/libs/actions/IOU/Duplicate.ts, updatebuildDuplicateTransactionParamsfor distance requests:
- Read
transaction.comment?.customUnit?.routeDistanceMetersfrom the source transaction. - Assign that value to
selectedRouteDistanceon the returnedDistanceRequestTransactionParamsobject.
- In
tests/unit/DuplicateTest.ts, add a unit test verifying that duplicating a distance transaction withtransaction.comment.customUnit.routeDistanceMeterscorrectly includesselectedRouteDistancein the output parameters.
What alternative solutions did you explore? (Optional)
I also considered resolving the route distance from transaction.routes before falling back to transaction.comment.customUnit.routeDistanceMeters. However, saved transactions do not persist an active selection index on transaction.routes. Querying transaction.routes first defaults to route0 whenever candidate routes remain cached in Onyx after creation, which duplicates the primary route instead. Reading transaction.comment.customUnit.routeDistanceMeters directly ensures the actual persisted distance is preserved.
β Contributor details stored successfully. Thank you for contributing to Expensify!
Use getSelectedRouteDistance(transaction) and fall back to transaction.comment.customUnit.routeDistanceMeters
@MelvinBot , in your solution, why do we need to fall back to transaction.comment.customUnit.routeDistanceMeters ?
Because getSelectedRouteDistance usually returns undefined for a saved expense. The fallback is what actually fixes the bug.
getSelectedRouteDistance reads transaction.routes[selectedRouteKey].distance (TransactionUtils/index.ts:1795-1803). routes is frontend-only data from the route fetch. Only the selected route's distance survives a save, as comment.customUnit.routeDistanceMeters (getSelectedRouteKey.ts:4-6). So if the expense is loaded from the server (another device, or after a cache clear), routes is missing. The helper then returns undefined unless isReusedRoute is set.
When routes is present, getSelectedRouteKey picks the route closest to routeDistanceMeters (getSelectedRouteKey.ts:22-38). That returns the same value.
So getSelectedRouteDistance adds nothing for the duplicate flow. A simpler fix works: for map distance expenses only (isMapDistanceRequest), send selectedRouteDistance: transaction.comment?.customUnit?.routeDistanceMeters. I'd update the proposal to that.
MelvinBot's proposal makes sense to me
Link to his proposal https://github.com/Expensify/App/issues/102946#issuecomment-6442898535
πππ C+ reviewed
Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@MelvinBot implement this
π€ Draft PR created: Keep the alternate route when duplicating a map distance expense Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.
The fix follows the approved proposal. For map distance expenses, the duplicate now sends selectedRouteDistance, taken from the source expense's comment.customUnit.routeDistanceMeters. I added tests for workspace and self-DM duplicates. The tests, typecheck, lint, and spell check pass.
I couldn't test the flow in the web app because the test browser session went blank before the test started. Please test it manually before review.
view run Β· no recording available
@hoangzinh @stitesExpensify this issue is now 4 weeks old, please consider:
- Finding a contributor to fix the bug
- Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
- If you have any questions, don't hesitate to start a discussion in #expensify-open-source
Thanks!
@hoangzinh
The solution for this issue has been :rocket: deployed to production :rocket: in version 9.5.32-7 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:
- https://github.com/Expensify/App/pull/105414
If no regressions arise, payment will be issued on 2026-11-13. :confetti_ball:
The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]
Contributor+ Checklist:
-
[x] [Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to the comment on the PR: https://github.com/Expensify/App/pull/96169#issuecomment-6683670536
-
[x] [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
-
[x] [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
Regression Test Proposal
Test:
- Open a workspace chat and click + β Track distance (Map).
- Set Start to Times Square, New York and Stop to Barclays Center, Brooklyn, or any start and stop that show more than one route.
- On the map, select the alternate (non-default) route. Note its distance.
- Continue and create the expense.
- Verify the expense shows the alternate route's distance and an amount that matches it (distance Γ rate).
- Open the expense and click More β Duplicate expense.
- Open the duplicated expense.
- Verify the duplicate shows the same distance, amount, and map route as the original, not the default route.
Do we agree π or π
Triggered auto assignment to @mallenexpensify (Awaiting Payment)
Payment Summary
Resolving PRs:
-
https://github.com/Expensify/App/pull/105414
-
Reviewer: @hoangzinh owed $175 via NewDot
BugZero Checklist (@mallenexpensify)
- [ ] I have confirmed assignees, roles, and Upwork contracts look correct
- [ ] I have paid out Upwork contracts / manual NewDot requests
- [ ] [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon