You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-05-22] [$250] Expense - "Rate not valid for this workspace" error, reappears after selecting a valid rate. #84238
Race condition between two sequential API calls: CHANGE_TRANSACTIONS_REPORT (move) and UPDATE_MONEY_REQUEST_DISTANCE_RATE (rate selection).
When a distance expense is moved from Self DM to a workspace, changeTransactionsReport (Transaction.ts:1046-1058) updates the reportID but does not update the customUnitRateID — it stays as the Self DM P2P rate (e.g. _FAKE_P2P_ID_). The optimistic violation check at ViolationsUtils.ts:421-434 correctly detects this as invalid and adds CUSTOM_UNIT_OUT_OF_POLICY.
When the user then selects a valid rate, updateMoneyRequestDistanceRate (UpdateMoneyRequest.ts:650-723) optimistically clears the violation. However, changeTransactionsReport has no successData for transaction violations (Transaction.ts:1060-1067), so the backend's Pusher response delivers its own violation calculations — computed with the original stale P2P rate — which overwrites the optimistic clear from the rate update, making the error reappear.
What changes do you think we should make in order to solve the problem?
In changeTransactionsReport, when moving a distance expense to a workspace, auto-select a valid default rate for the destination workspace and update the transaction's customUnitRateID in the optimistic data. This mirrors what the backend should do and prevents the stale P2P rate from persisting.
Specifically, in Transaction.ts around the optimistic data for the move:
Detect when the transaction is a distance request and the destination is a paid group policy
Check if the current customUnitRateID is valid for the destination policy (using getDistanceRateCustomUnitRate)
If not valid, find the workspace's default distance rate and include the updated customUnitRateID in the optimistic transaction data and in the API params sent to the backend
This ensures the violation check in ViolationsUtils.getViolationsOnyxData uses the corrected rate, and the backend processes the move with the correct rate from the start — eliminating the race condition entirely
What alternative solutions did you explore? (Optional)
An alternative would be to add successData for transaction violations in changeTransactionsReport that nullifies the violations so they get re-fetched from the server after the full queue processes. However, this only masks the timing issue and doesn't fix the underlying problem that the rate stays invalid after a move. Auto-selecting a valid rate at move time is the more correct fix since it addresses the actual data inconsistency.
Investigation details
Race condition timeline:
CHANGE_TRANSACTIONS_REPORT sent (transaction still has P2P rate)
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.
PR Expensify/App#73101 ("Unreported Expense - Category field") by koko57, merged October 22, 2025.
A commit in that PR added && !isSelfDM to the customUnitOutOfPolicy validation block in ViolationsUtils.ts:422. This guard causes the entire custom-unit-rate violation logic to be skipped when isSelfDM is true — so when a distance expense originates in Self DM and is later moved to a workspace, the CUSTOM_UNIT_OUT_OF_POLICY violation can never be cleared client-side, even after the user selects a valid rate.
Details
PR Expensify/App#72457 (merged Oct 16, 2025) first introduced the isSelfDM parameter to getViolationsOnyxData, but only used it for category violations (missingCategory).
PR Expensify/App#73101 (merged Oct 22, 2025) extended the !isSelfDM guard to the customUnitOutOfPolicy block, inadvertently breaking distance-rate violation clearing for expenses moved from Self DM.
The diff: - if (customUnitRateID && customUnitRateID.length > 0) { → + if (customUnitRateID && customUnitRateID.length > 0 && !isSelfDM) {
[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.
[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
[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.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Activity
MelvinBot commentedon Apr 13, 2026
Proposal
What is the root cause of that problem?
Race condition between two sequential API calls:
CHANGE_TRANSACTIONS_REPORT(move) andUPDATE_MONEY_REQUEST_DISTANCE_RATE(rate selection).When a distance expense is moved from Self DM to a workspace,
changeTransactionsReport(Transaction.ts:1046-1058) updates thereportIDbut does not update thecustomUnitRateID— it stays as the Self DM P2P rate (e.g._FAKE_P2P_ID_). The optimistic violation check atViolationsUtils.ts:421-434correctly detects this as invalid and addsCUSTOM_UNIT_OUT_OF_POLICY.When the user then selects a valid rate,
updateMoneyRequestDistanceRate(UpdateMoneyRequest.ts:650-723) optimistically clears the violation. However,changeTransactionsReporthas nosuccessDatafor transaction violations (Transaction.ts:1060-1067), so the backend's Pusher response delivers its own violation calculations — computed with the original stale P2P rate — which overwrites the optimistic clear from the rate update, making the error reappear.What changes do you think we should make in order to solve the problem?
In
changeTransactionsReport, when moving a distance expense to a workspace, auto-select a valid default rate for the destination workspace and update the transaction'scustomUnitRateIDin the optimistic data. This mirrors what the backend should do and prevents the stale P2P rate from persisting.Specifically, in
Transaction.tsaround the optimistic data for the move:customUnitRateIDis valid for the destination policy (usinggetDistanceRateCustomUnitRate)customUnitRateIDin the optimistic transaction data and in the API params sent to the backendViolationsUtils.getViolationsOnyxDatauses the corrected rate, and the backend processes the move with the correct rate from the start — eliminating the race condition entirelyWhat alternative solutions did you explore? (Optional)
An alternative would be to add
successDatafor transaction violations inchangeTransactionsReportthat nullifies the violations so they get re-fetched from the server after the full queue processes. However, this only masks the timing issue and doesn't fix the underlying problem that the rate stays invalid after a move. Auto-selecting a valid rate at move time is the more correct fix since it addresses the actual data inconsistency.Investigation details
Race condition timeline:
CHANGE_TRANSACTIONS_REPORTsent (transaction still has P2P rate)UPDATE_MONEY_REQUEST_DISTANCE_RATEsent, optimistically clears violationKey code paths:
changeTransactionsReportviolation computation:Transaction.ts:1114-1124— uses unmodified transaction with old rateCUSTOM_UNIT_OUT_OF_POLICYcheck:ViolationsUtils.ts:421-434OnyxUpdates.ts:81-93SequentialQueue.ts:356-359Possibly related open issues:
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Apr 13, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @ShridharGoel (
External)32 remaining items
melvin-bot commentedon May 21, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)ShridharGoel commentedon May 22, 2026
@MelvinBot Find the PR which caused this bug
MelvinBot commentedon May 22, 2026
PR Expensify/App#73101 ("Unreported Expense - Category field") by
koko57, merged October 22, 2025.A commit in that PR added
&& !isSelfDMto thecustomUnitOutOfPolicyvalidation block inViolationsUtils.ts:422. This guard causes the entire custom-unit-rate violation logic to be skipped whenisSelfDMis true — so when a distance expense originates in Self DM and is later moved to a workspace, theCUSTOM_UNIT_OUT_OF_POLICYviolation can never be cleared client-side, even after the user selects a valid rate.Details
isSelfDMparameter togetViolationsOnyxData, but only used it for category violations (missingCategory).!isSelfDMguard to thecustomUnitOutOfPolicyblock, inadvertently breaking distance-rate violation clearing for expenses moved from Self DM.- if (customUnitRateID && customUnitRateID.length > 0) {→+ if (customUnitRateID && customUnitRateID.length > 0 && !isSelfDM) {ShridharGoel commentedon May 22, 2026
BugZero Checklist:
[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: Unreported Expense - Category field #73101 (comment)
Link to the comment on the Issue:
[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
[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.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/640662
Regression Test Proposal
Precondition:
Have self DM and a workspace. Workspace should have at least some distance rates which are different from the personal space's distance rates.
Test:
Do we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-73d3-af6c-3eae-832667dab5d4melvin-bot commentedon May 22, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon May 25, 2026
Payment Summary
Contributor+: @ShridharGoel due $250 via NewDot
^ Test case created. Thx
garrettmknight commentedon May 28, 2026
$250 approved for @ShridharGoel