Skip to content

[Duplicate expense] Distance- Duplicate is map distance expense when original expense is a manual distance expense #84188

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a map distance expense.
  4. Open the expense.
  5. Click More > Split > Save.
  6. Open any split.
  7. Click More > Duplicate expense.
  8. Open the duplicated expense
  9. Click Distance field.
    → The distance expense changes to manual distance expense, not map distance expense - Expected from [Duplicate Expenses] Re-enable Distance Expense Support with fixes #82005
  10. Close the RHP.
  11. Click More > Duplicate expense.
  12. Open the duplicated "manual" distance expense.
  13. 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.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7093965_1772651503280.10.1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @jjcoffee

Activity

  1. added
    DeployBlockerCash
    Daily
    on Mar 4, 2026
  2. added
    Bug
    on Mar 4, 2026
  3. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    You have been assigned to this deploy blocker because you recently merged this PR: #82005

  4. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    💬 A slack conversation has been started in #expensify-open-source

  5. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    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.

  6. github-actions commented on Mar 4, 2026

    @github-actions
    Contributor

    👋 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:

    1. Identify the pull request that introduced this issue and revert it.
    2. Find someone who can quickly fix the issue.
    3. Fix the issue yourself.
  7. OSBotify commented on Mar 4, 2026

    @OSBotify
    Contributor

    🔍 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.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.

    Verification

    I examined the PR diff and confirmed that:

    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 info
            originalTransactionID: undefined,
            source: undefined,
        },
        iouRequestType: getRequestType(transaction),
        // ...
    }

    When a split distance expense is converted from map to manual distance:

    1. The transaction object gets updated with new distance type
    2. But the comment field may still contain the original map distance metadata
    3. When duplicating, the code copies this stale comment data
    4. 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.

  8. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    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.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:

    1. 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.

    2. 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.

  9. 3 remaining items

  10. jjcoffee commented on Mar 5, 2026

    @jjcoffee
    Contributor

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

  11. jjcoffee commented on Mar 5, 2026

    @jjcoffee
    Contributor

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

  12. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    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.

    Specifically, at lines 655-658:

    comment: {
        ...transaction.comment,
        originalTransactionID: undefined,
        source: undefined,
        waypoints: !isExpenseSplit(transaction) ? transaction.comment?.waypoints : undefined,
    },
    

    And at line 660, the iouRequestType should also be corrected for split distance expenses:

    iouRequestType: isExpenseSplit(transaction) && isDistanceRequest(transaction)
        ? CONST.IOU.REQUEST_TYPE.DISTANCE_MANUAL
        : getRequestType(transaction),
    

    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.

  13. added
    Daily
    and removed
    DeployBlockerCash
    Hourly
    on Mar 5, 2026
  14. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Agreed @jjcoffee , going to demote this but lets fix it in a follow up please

  15. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Closing out in favor of #84280, so there's less noise

  16. added
    Reviewing
    Weekly
    and removed
    Daily
    on Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugEngineeringReviewingWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions