Skip to content

Expense - Error after editing amount/distance/rate or adding distance split in self DM #91878

Closed

Description

@applause-bot

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.84-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: #84382
Email or phone of affected tester (no customers): soidjnosnjdoijsioj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5 / Chrome
App Component: Money Requests

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to self DM.
  3. Create a distance expense.
  4. Open the expense.
  5. Click More > Split > Save.
  6. Open any split.
  7. Click Amount.
  8. Edit the amount OR Click Add split and edit the amount > Save.

Expected Result:

Distance expense will be saved after editing amount or adding split with new amount.

Actual Result:

Error shows up after editing amount or adding split with new amount.
This issue also happens when user edits distance or rate instead of amount in Step 7-8.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7164514_1779905211329.2.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Svetlana Lazutkina
Bug ID: 7164514

Issue OwnerCurrent Issue Owner: @ZhenjaHorbach

Activity

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

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/c166b6a7775d39237237dc4d0efb88323a98d15fba231a676e47b29423347101

  3. melvin-bot commented on May 27, 2026

    @melvin-bot

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

  4. melvin-bot commented on May 27, 2026

    @melvin-bot

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

  5. github-actions commented on May 27, 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. MelvinBot commented on May 27, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    There are two distinct failure paths introduced by #84382, both triggered when editing distance splits in self-DM:

    1. isUnitRateIDOutOfPolicy validation blocks Save (affects all edit types)

    In SplitExpensePage.tsx:218-239, every distance split item is validated against the effective policy's mileage rates before the save is allowed. For self-DM splits, useSplitEffectivePolicy must resolve the policy through a multi-step fallback chain (customUnitID lookup → customUnitRateID lookup → policyForMovingExpenses). If this chain fails to resolve a policy, effectivePolicy is undefined and isUnitRateIDOutOfPolicy is set to true at line 229-231, which blocks the save with the modal: "Please fix the distance rate error and try again."

    Critically, when re-entering the split flow for existing splits, initSplitExpense rebuilds the draft at lines 138-151 without passing customUnit or existingTransaction to buildOptimisticTransaction — unlike the initial split creation at lines 239-256 which includes both. This means the re-entry draft lacks comment.customUnit on the draft transaction itself, making the useSplitEffectivePolicy fallback depend solely on the transaction parameter (the original parent). If the original transaction's customUnitRateID doesn't match any loaded policy (e.g., workspace was deleted or rates changed), policy resolution fails.

    2. Zero-amount validation blocks Save for "Add split" (distance-specific)

    In addSplitExpenseField, amount redistribution is explicitly skipped for distance requests (if (!isDistanceRequest && shouldRedistribute)), so newly added splits start with amount: 0. The computeSplitSaveErrorMessage check then rejects the save with "Please enter a valid amount before continuing" — even though for distance expenses the amount is meant to be derived from distance × rate, not entered directly.

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

    Fix 1: Pass customUnit and existingTransaction when rebuilding draft for existing splits

    In initSplitExpense (SplitExpenses.ts:138-151), add customUnit and existingTransaction to the buildOptimisticTransaction call for the re-entry path, matching what the initial-creation path already does:

    • customUnit: originalTransaction?.comment?.customUnit
    • existingTransaction: originalTransaction
    • odometerStart: originalTransaction?.comment?.odometerStart
    • odometerEnd: originalTransaction?.comment?.odometerEnd

    This ensures useSplitEffectivePolicy can resolve the policy from the draft transaction's customUnit even when re-editing existing splits.

    Fix 2: Handle zero-amount validation for distance "Add split"

    In computeSplitSaveErrorMessage (SplitExpenseUtils.ts:108), skip the zero-amount check for distance requests (similar to how the total-mismatch checks already skip with !isDistance), OR have addSplitExpenseField calculate an initial distance and amount for the new split item based on the resolved mileage rate, rather than leaving it at zero.

    What alternative solutions did you explore? (Optional)

    An alternative for Fix 1 is to modify useSplitEffectivePolicy to always attempt a direct policy search by customUnitRateID from the split items themselves (not just from the draft transaction), but this would be more invasive and add complexity to the hook. Fixing the data passed to buildOptimisticTransaction is more surgical and addresses the root cause directly.

    Investigation details

    Key code paths investigated:

    • Split flow entry: initSplitExpense (SplitExpenses.ts:89-265) — creates draft and navigates to SplitExpensePage. Initial creation (line 239) passes customUnit; re-entry for existing splits (line 138) does not.
    • Policy resolution: useSplitEffectivePolicy (useSplitEffectivePolicy.ts:27-59) — resolution chain: report.policyID → customUnitID → customUnitRateID → policyForMovingExpenses.
    • Rate validation: SplitExpensePage lines 218-239 and lines 279-287.
    • Amount editing: updateSplitExpenseAmountField (SplitExpenseItems.ts:634-706) — handles inline amount changes, recalculates distance for distance splits.
    • Add split: addSplitExpenseField (SplitExpenseItems.ts:287-360) — skips redistribution for distance at line 349.
    • Rate resolution fallback: resolveSplitMileageRate (SplitExpenseItems.ts:90-139) — derives rate from amount / quantity when policy is unavailable.

    Alternative explanation considered and not fully ruled out: The error could originate from the backend rejecting the split update API call, with the error surfaced via draftTransaction.errors and the useEffect at line 241-247. Without access to backend logs for the specific test scenario, this can't be confirmed or eliminated, but the frontend validation paths above are more likely given the described behavior.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  7. lakchote commented on May 28, 2026

    @lakchote
    Contributor

    Since we've added the guard to hide the selfDM splits feature in production in the PR #91932, I'm going to remove the deploy blocker label @mountiny

  8. 15 remaining items

  9. lakchote commented on Jun 26, 2026

    @lakchote
    Contributor

    I have a BE PR up for review to fix this cc @pecanoro

  10. lakchote commented on Jun 26, 2026

    @lakchote
    Contributor

    Not overdue, see above

  11. lakchote commented on Jun 29, 2026

    @lakchote
    Contributor

    Not overdue, the BE fix has been merged and deployed

  12. lakchote commented on Jul 7, 2026

    @lakchote
    Contributor

    Not overdue ^

  13. melvin-bot commented on Jul 9, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @lakchote, @ZhenjaHorbach eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  14. lakchote commented on Aug 31, 2026

    @lakchote
    Contributor

    I think we can close this one

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

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions