App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-11-13] [$175] [Exploratory] Distance - Duplicating expense with alternate route doesn't duplicate the route

Open applause-bot[bot] opened this issue 1 month ago β€’ 21 comments

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:

  1. Open the Workspace and log in
  2. Click on the global FAB and click on "Track distance"
  3. Set the start and end points on the map
  4. When the route is calculated, select an alternate route shown on the map
  5. Click on "Next" and click on "Create expense"
  6. Click on the created expense to open it
  7. Click on "More" and click on "Duplicate expense"
  8. 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

Image

View all open jobs on GitHub

Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7277274

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

applause-bot[bot] avatar Oct 04 '26 19:10 applause-bot[bot]

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

applause-bot[bot] avatar Oct 04 '26 19:10 applause-bot[bot]

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!

melvin-bot[bot] avatar Oct 18 '26 21:10 melvin-bot[bot]

Similar issue reported here as well (https://expensify.slack.com/archives/C049HHMV9SM/p1793052323348019)

m-natarajan avatar Oct 27 '26 13:10 m-natarajan

@MelvinBot Please investigate this and assign accordingly

m-natarajan avatar Oct 27 '26 13:10 m-natarajan

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?

  1. In buildDuplicateTransactionParams, for map distance expenses only, set selectedRouteDistance from the source expense. Use getSelectedRouteDistance(transaction) and fall back to transaction.comment.customUnit.routeDistanceMeters. A saved expense often has no routes, so the saved meters value is the reliable source (TransactionUtils/index.ts:1795-1803).
  2. No other wiring is needed. createDistanceRequest (Split.ts:2116) and trackExpense (TrackExpense.ts:2580) already read it from transactionParams. This covers both the workspace and the self-DM duplicate paths.
  3. Optional: copy routes into the duplicate's optimistic transaction so the map shows the alternate route right away.
  4. Add a test in tests/actions/IOUTest/DuplicateTest.ts that checks selectedRouteDistance is 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 selectedRouteDistance on create. We have not confirmed the exact backend error text.
  • No duplicate issue found. I added External so 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.


view run

MelvinBot avatar Oct 27 '26 13:10 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @hoangzinh (External)

melvin-bot[bot] avatar Oct 27 '26 13:10 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022115070823337425135

melvin-bot[bot] avatar Oct 27 '26 13:10 melvin-bot[bot]

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?

  1. In src/libs/actions/IOU/Duplicate.ts, update buildDuplicateTransactionParams for distance requests:
  • Read transaction.comment?.customUnit?.routeDistanceMeters from the source transaction.
  • Assign that value to selectedRouteDistance on the returned DistanceRequestTransactionParams object.
  1. In tests/unit/DuplicateTest.ts, add a unit test verifying that duplicating a distance transaction with transaction.comment.customUnit.routeDistanceMeters correctly includes selectedRouteDistance in 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.

taieddie avatar Oct 27 '26 13:10 taieddie

βœ… Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 27 '26 13:10 melvin-bot[bot]

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 ?

hoangzinh avatar Oct 28 '26 10:10 hoangzinh

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.


view run

MelvinBot avatar Oct 28 '26 10:10 MelvinBot

MelvinBot's proposal makes sense to me

Link to his proposal https://github.com/Expensify/App/issues/102946#issuecomment-6442898535

πŸŽ€πŸ‘€πŸŽ€ C+ reviewed

hoangzinh avatar Oct 28 '26 14:10 hoangzinh

Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Oct 28 '26 14:10 melvin-bot[bot]

@MelvinBot implement this

stitesExpensify avatar Oct 29 '26 19:10 stitesExpensify

πŸ€– 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

MelvinBot avatar Oct 29 '26 20:10 MelvinBot

@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!

melvin-bot[bot] avatar Nov 01 '26 21:11 melvin-bot[bot]

@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]

melvin-bot[bot] avatar Nov 06 '26 09:11 melvin-bot[bot]

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:

  1. Open a workspace chat and click + β†’ Track distance (Map).
  2. Set Start to Times Square, New York and Stop to Barclays Center, Brooklyn, or any start and stop that show more than one route.
  3. On the map, select the alternate (non-default) route. Note its distance.
  4. Continue and create the expense.
  5. Verify the expense shows the alternate route's distance and an amount that matches it (distance Γ— rate).
  6. Open the expense and click More β†’ Duplicate expense.
  7. Open the duplicated expense.
  8. Verify the duplicate shows the same distance, amount, and map route as the original, not the default route.

Do we agree πŸ‘ or πŸ‘Ž

hoangzinh avatar Nov 06 '26 11:11 hoangzinh

Triggered auto assignment to @mallenexpensify (Awaiting Payment)

melvin-bot[bot] avatar Nov 12 '26 21:11 melvin-bot[bot]

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

melvin-bot[bot] avatar Nov 12 '26 21:11 melvin-bot[bot]