App icon indicating copy to clipboard operation
App copied to clipboard

[$175] [Exploratory] Distance - Can't select the rate after change the report to another Workspace

Open applause-bot[bot] opened this issue 1 month ago • 24 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.25-0 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/test-runs/81167638/folder/57605203/46440229/1923342598?sort=%2Bidentifier 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: Windows 11/Chrome App Component: Chat Report View

Action Performed:

Preconditions The user has at least two workspaces: Workspace 1: An existing workspace. Workspace 2: A new workspace with no prior expenses. Both workspaces have "Delayed Submissions" and "Approvals" enabled. Steps:

  1. Log in as the workspace admin
  2. Navigate to the chat for "Workspace 1"
  3. Create a Distance expense
  4. On the expense preview, Click on the "Submit" button
  5. Navigate to the "Workspaces"
  6. Click on the "More"
  7. Click on the "Delete" (or Archive if use Expensifail account)
  8. Navigate to the deleted Workspace chat
  9. Open the expense report that was just created
  10. Click on the "More" and select "Change Workspace" - Select Workspace 2
  11. Go back and open the Reports with distance expense
  12. Click on the Rate - Select the valid rate

Expected Result:

The error "rate not valid for this workspace" disappears

Actual Result:

Error "rate not valid for this workspace" reappears again

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/a00e3cb8-5bd4-4d05-b9c2-f05a8bc95e55

View all open jobs on GitHub

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

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

applause-bot[bot] avatar Oct 29 '26 06: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/e2182d34ae5a07744d71cd63569f0fead8600985d3e02f8e03ac904e974069b5

applause-bot[bot] avatar Oct 29 '26 06:10 applause-bot[bot]

Issue Analysis

Root Cause: This appears to be a backend/internal issue. A separate internal investigation is needed.

I reproduced the bug on web. The App removes the "Rate not valid for this workspace" violation when you pick a Workspace 2 rate, but it stays on screen. The violation most likely comes back from the server, not the App.

Recommended Fix: The fix needs changes outside the App repo. Please escalate to an internal engineer. Planned App work in [HOLD Expensify 679405] Add optimistic distance rate updates when a report's workspace changes would likely prevent this state. That work auto-selects a valid rate during Change workspace, so you would not need to pick one.

Error still shown after selecting the valid rate
Investigation details

Repro (web, dev build): I followed the issue steps with two new workspaces, a submitted 10 mi distance expense, deleting Workspace A, then Change workspace to Workspace B.

  • After Change workspace, the expense shows "Rate out of policy / Rate not valid for this workspace".
  • I picked "Default Rate, $0.76 / mile" and saved. Reopening the picker shows that rate selected, so the save worked. The error was still there after about 13 seconds.
Rate not valid error after Change workspace

Why the App is not the source:

Likely contributing state:

  • changeReportPolicy only updates the policyID of the report and its threads (Report/index.ts:8367). It leaves the transaction's comment.customUnit on the old workspace.
  • A rate change updates only customUnitRateID (getUpdatedTransaction.ts:282-284). The transaction keeps Workspace A's customUnitID with a Workspace B rate ID. If the server checks the rate against stale data, it adds the violation back.

Not verified: I could not check server logs in this run. To confirm, check whether the UpdateMoneyRequestDistanceRate response adds customUnitOutOfPolicy back to the transaction's violations. One App-side case is still possible: the thread's policyID might not have moved to Workspace B. The logs would show this, because the request would then send a Workspace A rate ID.

Related issues:


Next Steps: Reply with @MelvinBot <your feedback> to refine this analysis.


view run · no recording available

MelvinBot avatar Nov 03 '26 00:11 MelvinBot

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

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

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

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

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

melvin-bot[bot] avatar Nov 03 '26 23:11 melvin-bot[bot]

@abzokhattab plz take over as C+

mallenexpensify avatar Nov 03 '26 23:11 mallenexpensify

Sure ... taking a-look in the morning

abzokhattab avatar Nov 03 '26 23:11 abzokhattab

This is caused by changeReportPolicy not updating the transaction's comment.customUnit fields (customUnitID / customUnitRateID) when moving to a new workspace. After "Change Workspace", the transaction still carries the old workspace's customUnitID. When the user then picks a valid rate from the new workspace, only customUnitRateID updates .. the server sees the customUnitID mismatch and re-adds the customUnitOutOfPolicy violation.

This is the exact scenario that #100559 (F4 in the tracking issue #100555) is designed to fix ,, it will make changeReportPolicy auto-select a valid rate and update all custom unit fields during the workspace change itself. That work is on HOLD pending backend changes in Expensify#679405.

Putting this on HOLD for #100559.

abzokhattab avatar Nov 04 '26 13:11 abzokhattab

Proposal

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

When a distance expense report is created in Workspace 1, Workspace 1 is deleted, and the expense report is moved to Workspace 2 via More > Change Workspace, opening the distance expense's Rate page and selecting a valid distance rate from Workspace 2 fails to clear the "Rate not valid for this workspace" (customUnitOutOfPolicy) violation — the error reappears shortly after saving.

What is the root cause of that problem?

There are two connected client-side issues in the distance rate update flow after a report's workspace is changed:

  1. getUpdatedTransaction updates customUnitRateID without updating customUnitID to the new workspace's distance custom unit (src/libs/TransactionUtils/getUpdatedTransaction.ts, lines 282–292): When the distance expense was originally created in Workspace 1, transaction.comment.customUnit stored Workspace 1's customUnitID and customUnitRateID. When the report is moved to Workspace 2 via changeReportPolicy, transaction.comment.customUnit.customUnitID still holds Workspace 1's customUnitID. When the user then opens the Rate picker and selects a valid rate from Workspace 2, setMoneyRequestDistanceRate -> updateMoneyRequestDistanceRate (src/libs/actions/IOU/UpdateMoneyRequest.ts) calls getUpdatedTransaction:

e5ash avatar Nov 07 '26 15:11 e5ash

Proposal

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

After deleting the original workspace (Workspace 1) and moving a submitted distance expense report to another workspace (Workspace 2), the distance expense displays a Rate not valid for this workspace (customUnitOutOfPolicy) violation. When the user opens the Rate selector and chooses the valid rate from Workspace 2, the violation remains and the new rate cannot be saved.

What is the root cause of that problem?

There are two interacting issues across changeReportPolicy and updateMoneyRequestDistanceRate:

  1. In src/libs/actions/Report/index.ts (changeReportPolicy / changeReportPolicyAndInviteSubmitter), when an expense report is moved to a new workspace (policy), the optimistic Onyx updates do not migrate distance transactions' comment.customUnit.customUnitRateID to the destination workspace's default P2P/distance rate, leaving the deleted workspace's stale customUnitRateID on the transaction along with the customUnitOutOfPolicy violation.
  2. When the user subsequently selects a valid rate from Workspace 2 on the moved report, updateMoneyRequestDistanceRate in src/libs/actions/IOU/UpdateMoneyRequest.ts (lines 2220–2335) calls getUpdateMoneyRequestParams (UpdateMoneyRequest.ts:1166), which dispatches API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DISTANCE_RATE, ...). However, in src/pages/iou/request/step/IOURequestStepDistanceRate.tsx (lines 118–155), policy is resolved via usePolicy(report?.policyID). When the transaction was inspected from a transaction thread report (report), report.policyID on the child transaction thread report can still reference the old deleted workspace ID if changeReportPolicy only updated the parent iouReport.policyID and not the child transaction thread report's policyID in Onyx. As a result, IOURequestStepDistanceRate either looks up rates on the wrong policy or passes policy with a mismatched policyID to updateMoneyRequestDistanceRate, and the backend rejects or returns the customUnitOutOfPolicy violation.

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

  1. In src/pages/iou/request/step/IOURequestStepDistanceRate.tsx, resolve the effective policyID from parentReport?.policyID ?? report?.policyID (where parentReport is ONYXKEYS.COLLECTION.REPORT for transaction?.reportID) so that moving the parent expense report to Workspace 2 always uses Workspace 2's policy and distance rates even if the transaction thread report still carries the old policyID.
  2. In src/libs/actions/Report/index.ts (buildOptimisticMovedReportData / changeReportPolicy), also update any existing child transaction thread reports' policyID in optimisticData to newPolicy.id, and when moving distance transactions whose customUnitRateID does not exist on newPolicy, clear or remap customUnitOutOfPolicy consistently once a valid rate on newPolicy is selected.

What alternative solutions did you explore? (Optional)

We also considered automatically remapping the distance rate inside changeReportPolicy on the client, which helps when moving to a workspace with a default rate, but resolving parentReport?.policyID in IOURequestStepDistanceRate.tsx and syncing child transaction thread policyIDs ensures manual rate selection always targets the moved report's current workspace.

ghost avatar Nov 08 '26 15:11 ghost

📣 @jeff-graham-ai! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 08 '26 15:11 melvin-bot[bot]

I don't have the capacity to follow up on this. reassigning

abzokhattab avatar Nov 09 '26 14:11 abzokhattab

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

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

Feel free to take over this issue @nkdengineer

abzokhattab avatar Nov 09 '26 14:11 abzokhattab

@nkdengineer this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

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

@nkdengineer Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

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

Can't reproduce anymore.

nkdengineer avatar Nov 16 '26 09:11 nkdengineer

@nkdengineer Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@nkdengineer Still overdue 6 days?! Let's take care of this!

Not overdue. Waiting for reset.

nkdengineer avatar Nov 24 '26 08:11 nkdengineer