Skip to content

[$250] Distance - Split Expense shows “Amount differs from calculated distance” for long distances #83570

Closed

Description

@jponikarchuk

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: V9.3.26-4
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #82257
Email or phone of affected tester (no customers): dreamnitethedragon+yydyd373@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Redminote 10S Android 13
App Component: Money Requests

Action Performed:

  1. Launch app
  2. Go to workspace chat
  3. Create a distance manual expense with maximum distance digits allowed eg: 4444444444
  4. Open the expense
  5. Tap more - split the expense

Expected Result:

Amount differs from calculated distance error must not be shown in expense preview when splitting with long distance.

Actual Result:

Amount differs from calculated distance error is shown in expense preview when splitting with long distance.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7089193_1772106957595.Screenrecorder-2026-02-26-17-24-33-576.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @ikevin127
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022027003994472612862
  • Upwork Job ID: 2027003994472612862
  • Last Price Increase: 2026-02-26

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 26, 2026
  2. melvin-bot commented on Feb 26, 2026

    @melvin-bot

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

  3. melvin-bot commented on Feb 26, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    Triggered auto assignment to @NicMendonca (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.

  5. github-actions commented on Feb 26, 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.
  6. OSBotify commented on Feb 26, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #82257 - "feat: handle the Distance and Rate fields for splits" by @ZhenjaHorbach (High confidence)
    Related Issues: #78891

    Recommendation: REVERT

    PR #82257 introduced functionality to handle distance and rate fields for split expenses. However, when splitting a distance expense with large distance values (e.g., 4444444444 meters), the split transactions incorrectly show the "Amount differs from calculated distance" violation in the expense preview.

    Labels: No label changes made. Keeping DeployBlockerCash as this is a Frontend (App) bug that is reproducible on staging but not production.

    Detailed Analysis

    Evidence

    Verification

    PR #82257 modified the following key files related to this bug:

    • src/libs/actions/IOU/Split.ts - Added extensive split transaction handling for distance requests
    • src/libs/TransactionUtils/index.ts - Lines 899-904 set modifiedAmount on split distance transactions
    • src/components/ReportActionItem/MoneyRequestView.tsx - Modified split expense initialization
    • src/pages/iou/SplitExpenseEditPage.tsx - Added distance/rate editing for splits
    • src/libs/TransactionPreviewUtils.ts - Lines 252-260 show the modifiedAmount violation for distance requests

    Root Cause

    When splitting a distance expense with large distance values, the code in TransactionUtils/index.ts (lines 899-904) sets the modifiedAmount field on each split transaction:

    if (isSplitTransaction && isDistanceRequest(transaction) && transactionChanges.amount) {
        const amount = transactionChanges.amount ?? Number(transaction.modifiedAmount) ?? transaction.amount ?? 0;
        const updatedAmount = (isFromExpenseReport || isUnReportedExpense) && transactionChanges.amount ? -amount : amount;
        updatedTransaction.amount = updatedAmount;
        updatedTransaction.modifiedAmount = updatedAmount;  // This triggers the violation
        updatedTransaction.modifiedMerchant = transactionChanges.merchant;
    }

    The presence of modifiedAmount on a distance transaction causes TransactionPreviewUtils.ts (lines 252-260) to display the "Amount differs from calculated distance" violation, even though this is expected behavior for split transactions with custom amounts. The violation check does not account for split transactions being allowed to have amounts that differ from the calculated distance.

  7. MelvinBot commented on Feb 26, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user creates a manual distance expense with a very large distance (e.g., 4444444444) and then splits the expense, the "Amount differs from calculated distance" error (a modifiedAmount violation with type: 'distance') appears on the split child transaction previews. This error should not appear for legitimate splits of distance expenses.

    What is the root cause of that problem?

    The root cause is in src/libs/actions/IOU/Split.ts at line 1168. When building the transactionParams for split child transactions in updateSplitTransactions(), the amount field is set to the full original parent transaction amount, while modifiedAmount is set to the split portion amount:

    amount: Math.abs(originalTransaction?.amount ?? 0),      // ← full parent total
    modifiedAmount: splitExpense.amount ?? 0,                 // ← split share
    

    This means every split child of a distance expense is created with amount ≠ modifiedAmount. The backend interprets this as the user having manually modified the amount away from the calculated distance, and generates a modifiedAmount violation with data.type = 'distance'.

    There is a compounding issue: updateSplitExpenseDistanceFromAmount() at line 1904-1905 reverse-calculates the distance from the split amount using .toFixed(2) truncation, which is lossy. Even if amount were corrected, the truncated quantity * rate may not equal the original split amount for large values, further triggering the backend validation.

    What changes do you think we should make in order to solve the problem?

    Primary fix in src/libs/actions/IOU/Split.ts line 1168: Change the amount field in transactionParams from the full original transaction amount to the split portion amount (same as modifiedAmount), so the child transaction doesn't appear to have a modified amount:

    amount: splitExpense.amount ?? 0,         // ← use split portion, not full parent total
    modifiedAmount: splitExpense.amount ?? 0,  // ← split share (unchanged)
    

    Secondary fix in updateSplitExpenseDistanceFromAmount() (line 1904-1905): After truncating the distance to 2 decimal places, recalculate the amount from the truncated distance to ensure consistency:

    const quantity = Number(distanceInUnits.toFixed(CONST.DISTANCE_DECIMAL_PLACES));
    // Recalculate amount from truncated distance to ensure amount == Math.round(quantity * rate)
    const consistentAmount = Math.round(quantity * rate);
    

    Then use consistentAmount as the split child's amount. This ensures the quantity * rate calculation the backend performs will always match the amount sent.

    What alternative solutions did you explore? (Optional)

    1. Suppress the violation client-side for split children — This would hide the symptom in TransactionPreviewUtils.ts (lines 252-260) but wouldn't fix the underlying data inconsistency being sent to the backend.
    2. Remove modifiedAmount entirely for split children — This could work but may break other features that rely on modifiedAmount to track the split share vs original amount.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  8. 12 remaining items

  9. added and removed on Feb 26, 2026
  10. lakchote commented on Feb 26, 2026

    @lakchote
    Contributor

    Demoting as it's an edge case. Needs BE changes.

  11. melvin-bot commented on Feb 26, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  12. ikevin127 commented on Feb 26, 2026

    @ikevin127
    Contributor

    Please tag me if I'm needed here 🙌

  13. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    @suneox, @lakchote, @NicMendonca, @ZhenjaHorbach Still overdue 6 days?! Let's take care of this!

  14. suneox commented on Mar 6, 2026

    @suneox
    Contributor

    We're still waiting for BE update

  15. lakchote commented on Mar 9, 2026

    @lakchote
    Contributor

    Not overdue - blocked on the backend update needed for the distance split fix.

  16. lakchote commented on Mar 11, 2026

    @lakchote
    Contributor

    This has been fixed by #83170

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions