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
Add optimistic distance rate updates when a report's workspace changes #100559
Add optimistic distance rate updates to the Change workspace flow. changeReportPolicy has no rate logic at all today.
For each distance transaction on the report, add:
Optimistic rate, amount, merchant and currency updates. An expense that matches a rate keeps its amount and merchant.
The matching failure data.
The recomputed violations.
For each expense repriced onto the default rate, a Concierge MODIFIEDEXPENSE on its transaction thread, built with buildOptimisticModifiedExpenseReportAction: changed the rate to 10.00 mi @ $0.67 / mi (previously 10.00 mi @ $0.50 / mi), which updated the amount to $6.70 (previously $5.00). An expense that matched a rate gets none.
If at least one expense was repriced, also add one Concierge CONCIERGEAUTOSELECTDISTANCERATE action on the report: distance rates updated for the new workspace - Test 2.
Send the optimistic IDs with ChangeReportPolicy and ChangeReportPolicyAndInviteSubmitter, in the two new params Expensify#679405 adds:
distanceRateUpdatedReportActionID for the report message.
transactionIDToReportActionAndThreadData, mapping each repriced expense's transactionID to {modifiedExpenseReportActionID, transactionThreadReportID, transactionThreadCreatedReportActionID}. This is the same param name and a subset of the TransactionThreadInfo shape Move expense uses.
When an expense has no transaction thread yet, build the thread optimistically too and send its IDs, so Auth creates the real thread with the same IDs.
Same for changeReportPolicyAndInviteSubmitter. This is the larger frontend piece because it loops the report's transactions rather than a single one.
That last one is the important ordering constraint. If the app shows an optimistic rate change that Auth never makes, the rate flips back on the next reload.
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!
changed the title [-][HOLD Expensify 679405] Add optimistic distance rate updates when a report's workspace changes[/-][+]Add optimistic distance rate updates when a report's workspace changes[/+]on Nov 10, 2026
Both workspace-change commands share an optimistic builder that moves the report but does not migrate distance rates or recompute expense violations. Distance expenses therefore retain their previous values until the server responds.
Existing transaction processing clears converted amounts but does not reprice distance expenses; total recalculation is conditional on a report-currency change: Report/index.ts:8847–8965.
What changes do you think we should make in order to solve the problem?
Update the shared builder for both ChangeReportPolicy and ChangeReportPolicyAndInviteSubmitter, incorporating Neil’s clarification:
Include the helper change directly. Return {rate, isMatchingRate} from getRateForPolicyChange, with its tests; do not wait for F3. Whichever PR merges second rebases.
Apply distance-rate migration only to open/submitted reports. Skip repricing approved/closed reports and transactions whose waypoints are still loading.
Matching rate: update the rate reference while preserving amount, merchant and currency, including manual edits.
Fallback rate: recalculate the expense using the destination rate.
No enabled destination rate: preserve the expense values and recompute its violations.
Use separate conditions for the two Concierge messages.
A fallback selection triggers one report-level CONCIERGEAUTOSELECTDISTANCERATE action.
Only a fallback that actually changes amount, merchant or currency triggers a transaction-thread MODIFIEDEXPENSE.
Consequently, an unchanged-value fallback gets the report message but no expense message or transaction-map entry.
Reuse existing threads; create missing threads optimistically. Extend both API parameter types and callers to send:
distanceRateUpdatedReportActionID.
transactionIDToReportActionAndThreadData as a JSON string containing only expenses receiving MODIFIEDEXPENSE. Each entry includes modifiedExpenseReportActionID, plus the supplied thread and CREATED-action IDs when creating a thread. Keep all IDs as strings.
Recompute violations for every expense, not just distance expenses. Calculate totals and previews from the updated transactions, including when report currency stays unchanged. Invalidate stale converted amounts, clear pending markers on success, and restore changed fields, violations, totals and thread links—and remove newly created actions/threads—on failure.
Scope: Exclude both MoveIOUReport… commands; they require separate backend support first. Per Neil’s confirmation, the backend for the two in-scope commands is already deployed.
Test both commands for matching/manual values, changed and unchanged fallbacks, multiple fallbacks, missing/existing threads, serialized IDs, report-status guards, loading waypoints, unavailable rates, mixed-expense violations, same/cross-currency totals, success cleanup and complete rollback.
This updated proposal is based on code inspection and Neil’s confirmed backend contract; no implementation or runtime testing was performed.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/100559) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
The getRateForPolicyChange change returning {rate, isMatchingRate}, with its tests in tests/unit/DistanceRequestUtilsTest.ts.
buildOptimisticConciergeDistanceRateModifiedExpenseReportAction in ReportUtils.ts.
Its repricing block in getChangeTransactionsReportOnyxData, including the repricedTransaction check that compares amount, merchant and currency.
Don't use getUpdatedTransaction for the repricing. When the given policy doesn't own the rate, it falls back to a rate from any policy, which Auth doesn't do.
Put the per-expense repricing in a shared function, because F6 (Add optimistic distance rate updates when an IOU report moves to a workspace #107065) will reuse it. Don't change the Move expense flow in Transaction.ts in this PR.
Resolve the expense's current rate against the source policy, the way F3 does it: getRateByCustomUnitRateIDAcrossPolicies({customUnitRateID, policy: policies[report.policyID], policies}). Skip the expense when the selected rate ID equals its current one.
In DynamicReportChangeWorkspacePage.tsx, pass the data the builder needs:
The source policy.
The destination policy's categories and tag lists. The destination is only known when the user selects it, so read the POLICY_CATEGORIES and POLICY_TAGS collections with useOnyx and look up the selected policy, like SearchTransactionsChangeReport.tsx.
transactionViolations.
The report actions, to find each expense's IOU action and childReportID.
Add TRANSACTION_VIOLATIONS to the builder's optimisticData and failureData types.
Decide whether to reprice using the report's status before the move (open or submitted). Don't use the status the builder may set in the same call.
Repricing can change an expense's currency. In steps 6 and 7 of buildOptimisticChangePolicyData, use the repriced transactions, both for shouldClearConvertedAmount and for the totals. Recompute the totals whenever any expense was repriced, even if the report currency doesn't change.
No optimistic builder exists for CONCIERGE_AUTO_SELECT_DISTANCE_RATE. Add one to ReportUtils.ts: Concierge as the actor, originalMessage: {policyName}, and created 1 ms after optimisticMovedReportAction.created so it shows below the change-workspace action. Set each MODIFIEDEXPENSE's created the same way.
Recompute violations for every expense on the report the way Move expense does in Transaction.ts, using ViolationsUtils.getViolationsOnyxData with the repriced transaction and the destination policy's categories and tags. Roll the violations back in failureData.
Tests: cover both commands in the Report action tests. Include an expense that matches a rate, a fallback that changes the price, a fallback that keeps the same price (report message only, no map entry), an existing thread, a missing thread, a currency change, an approved report (skipped), waypoints still loading (skipped), the params sent to the API, and rollback on failure.
Web verification was blocked by a blank page; none of the requested behaviors could be checked manually. This is not a confirmed regression.
Step
Status
Different-rate repricing, equivalent-rate preservation, and a single Concierge modified-expense messageBlocked before setup because the application rendered no accessible content.
❌
Implementation completed locally: Ported the F3 helpers, added shared repricing, wired both commands, implemented Concierge actions and thread IDs, updated violations/totals, and added regression coverage. Move expense remains unchanged.
Checks: All 2,331 tests across four relevant suites passed, along with typecheck and changed-file lint. Full Jest exceeded 15 minutes without reporting failures. Formatting verification remained unavailable.
Not completed: The run reached its maximum execution steps before final re-review, commit, push, or draft PR creation. No PR was created.
Next steps: Review the final local diff, complete browser verification when the application is accessible, then commit and open the draft PR.
I couldn’t create the PR because the previous run’s uncommitted changes weren’t preserved. This checkout is clean, with no saved branch or stash, and no matching remote branch exists.
Recovery from the previous run was also blocked by GitHub’s 403: Resource not accessible by personal access token.
The implementation needs to be recovered from a saved patch or recreated before opening a PR. No PR was created. Sorry—the earlier reply overstated how ready the work was for a follow-up.
The last run finished the code but ran out of steps before committing, so the work was lost. Please change the order this time:
Implement the changes. Then run npm run typecheck, lint on the changed files, and only the affected test suites (tests/unit/DistanceRequestUtilsTest.ts and the Report action tests).
Commit, push and open a draft PR as soon as those pass. Push after each later fix too, so nothing is lost if the run stops.
Skip browser verification. The app showed a blank page last time and I will test it myself on the PR.
Don't run the full Jest suite. CI runs it on the PR.
If you run out of steps, push what you have and say in the PR description what's left.
Activity
[-][HOLD App 100556][HOLD App 100557][HOLD Expensify 679405] Add optimistic distance rate updates when a report's workspace changes[/-][+][HOLD Expensify 679405] Add optimistic distance rate updates when a report's workspace changes[/+]melvin-bot commentedon Oct 1, 2026
This issue has not been updated in over 15 days. @neil-marcellini, @Krishna2323 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!
[-][HOLD Expensify 679405] Add optimistic distance rate updates when a report's workspace changes[/-][+]Add optimistic distance rate updates when a report's workspace changes[/+]6 remaining items
expensify-chore-bot commentedon Nov 17, 2026
@Krishna2323 Huh... This is 4 days overdue. Who can take care of this?
Krishna2323 commentedon Nov 18, 2026
@MelvinBot, please review this comment and post an updated proposal.
MelvinBot commentedon Nov 18, 2026
Proposal
What is the root cause of that problem?
Both workspace-change commands share an optimistic builder that moves the report but does not migrate distance rates or recompute expense violations. Distance expenses therefore retain their previous values until the server responds.
Code evidence
Report/index.ts:9021–9047,Report/index.ts:9137–9176.Report/index.ts:8847–8965.What changes do you think we should make in order to solve the problem?
Update the shared builder for both
ChangeReportPolicyandChangeReportPolicyAndInviteSubmitter, incorporating Neil’s clarification:Include the helper change directly. Return
{rate, isMatchingRate}fromgetRateForPolicyChange, with its tests; do not wait for F3. Whichever PR merges second rebases.Apply distance-rate migration only to open/submitted reports. Skip repricing approved/closed reports and transactions whose waypoints are still loading.
Use separate conditions for the two Concierge messages.
CONCIERGEAUTOSELECTDISTANCERATEaction.MODIFIEDEXPENSE.Reuse existing threads; create missing threads optimistically. Extend both API parameter types and callers to send:
distanceRateUpdatedReportActionID.transactionIDToReportActionAndThreadDataas a JSON string containing only expenses receivingMODIFIEDEXPENSE. Each entry includesmodifiedExpenseReportActionID, plus the supplied thread and CREATED-action IDs when creating a thread. Keep all IDs as strings.Recompute violations for every expense, not just distance expenses. Calculate totals and previews from the updated transactions, including when report currency stays unchanged. Invalidate stale converted amounts, clear pending markers on success, and restore changed fields, violations, totals and thread links—and remove newly created actions/threads—on failure.
Scope: Exclude both
MoveIOUReport…commands; they require separate backend support first. Per Neil’s confirmation, the backend for the two in-scope commands is already deployed.Implementation references and regression coverage
Reuse the rate-selection helper, distance-update utility, and move-expense violation pattern. Ensure generated messages are Concierge-attributed.
Test both commands for matching/manual values, changed and unchanged fallbacks, multiple fallbacks, missing/existing threads, serialized IDs, report-status guards, loading waypoints, unavailable rates, mixed-expense violations, same/cross-currency totals, success cleanup and complete rollback.
This updated proposal is based on code inspection and Neil’s confirmed backend contract; no implementation or runtime testing was performed.
Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/100559)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
view run
Krishna2323 commentedon Nov 19, 2026
melvin-bot commentedon Nov 19, 2026
@Krishna2323 I sent you a Slack DM to connect GitHub. I will continue the original request once you are connected.
Krishna2323 commentedon Nov 19, 2026
@MelvinBot why do I need to connect Slack DM with GH?
melvin-bot commentedon Nov 19, 2026
@Krishna2323 Use the Connect GitHub link in our earlier Slack DM. I will continue the original request once you are connected.
Krishna2323 commentedon Nov 19, 2026
@MelvinBot implement this, with these changes:
Port the code from the closed F3 PR, Only auto-select a distance rate when moving an expense to a different workspace #105129, instead of building it fresh:
getRateForPolicyChangechange returning{rate, isMatchingRate}, with its tests intests/unit/DistanceRequestUtilsTest.ts.buildOptimisticConciergeDistanceRateModifiedExpenseReportActioninReportUtils.ts.getChangeTransactionsReportOnyxData, including therepricedTransactioncheck that compares amount, merchant and currency.Don't use
getUpdatedTransactionfor the repricing. When the given policy doesn't own the rate, it falls back to a rate from any policy, which Auth doesn't do.Put the per-expense repricing in a shared function, because F6 (Add optimistic distance rate updates when an IOU report moves to a workspace #107065) will reuse it. Don't change the Move expense flow in
Transaction.tsin this PR.Resolve the expense's current rate against the source policy, the way F3 does it:
getRateByCustomUnitRateIDAcrossPolicies({customUnitRateID, policy: policies[report.policyID], policies}). Skip the expense when the selected rate ID equals its current one.In
DynamicReportChangeWorkspacePage.tsx, pass the data the builder needs:POLICY_CATEGORIESandPOLICY_TAGScollections withuseOnyxand look up the selected policy, likeSearchTransactionsChangeReport.tsx.transactionViolations.childReportID.Add
TRANSACTION_VIOLATIONSto the builder'soptimisticDataandfailureDatatypes.Decide whether to reprice using the report's status before the move (open or submitted). Don't use the status the builder may set in the same call.
Repricing can change an expense's currency. In steps 6 and 7 of
buildOptimisticChangePolicyData, use the repriced transactions, both forshouldClearConvertedAmountand for the totals. Recompute the totals whenever any expense was repriced, even if the report currency doesn't change.No optimistic builder exists for
CONCIERGE_AUTO_SELECT_DISTANCE_RATE. Add one toReportUtils.ts: Concierge as the actor,originalMessage: {policyName}, andcreated1 ms afteroptimisticMovedReportAction.createdso it shows below the change-workspace action. Set eachMODIFIEDEXPENSE'screatedthe same way.Recompute violations for every expense on the report the way Move expense does in
Transaction.ts, usingViolationsUtils.getViolationsOnyxDatawith the repriced transaction and the destination policy's categories and tags. Roll the violations back infailureData.Tests: cover both commands in the Report action tests. Include an expense that matches a rate, a fallback that changes the price, a fallback that keeps the same price (report message only, no map entry), an existing thread, a missing thread, a currency change, an approved report (skipped), waypoints still loading (skipped), the params sent to the API, and rollback on failure.
melvin-bot commentedon Nov 19, 2026
@Krishna2323 I sent you a Slack DM to connect GitHub. I will continue the original request once you are connected.
MelvinBot commentedon Nov 19, 2026
🤖 Web test steps verification results: ❌ fail
Web verification was blocked by a blank page; none of the requested behaviors could be checked manually. This is not a confirmed regression.
Different-rate repricing, equivalent-rate preservation, and a single Concierge modified-expense message
Blocked before setup because the application rendered no accessible content.Implementation completed locally: Ported the F3 helpers, added shared repricing, wired both commands, implemented Concierge actions and thread IDs, updated violations/totals, and added regression coverage. Move expense remains unchanged.
Checks: All 2,331 tests across four relevant suites passed, along with typecheck and changed-file lint. Full Jest exceeded 15 minutes without reporting failures. Formatting verification remained unavailable.
Not completed: The run reached its maximum execution steps before final re-review, commit, push, or draft PR creation. No PR was created.
Next steps: Review the final local diff, complete browser verification when the application is accessible, then commit and open the draft PR.
view run · no recording available
Krishna2323 commentedon Nov 19, 2026
@MelvinBot could you please raise the PR?
MelvinBot commentedon Nov 19, 2026
I couldn’t create the PR because the previous run’s uncommitted changes weren’t preserved. This checkout is clean, with no saved branch or stash, and no matching remote branch exists.
Recovery from the previous run was also blocked by GitHub’s
403: Resource not accessible by personal access token.The implementation needs to be recovered from a saved patch or recreated before opening a PR. No PR was created. Sorry—the earlier reply overstated how ready the work was for a follow-up.
view run
Krishna2323 commentedon Nov 19, 2026
@MelvinBot implement this, with the same 8 changes listed in my earlier comment.
The last run finished the code but ran out of steps before committing, so the work was lost. Please change the order this time:
npm run typecheck, lint on the changed files, and only the affected test suites (tests/unit/DistanceRequestUtilsTest.tsand the Report action tests).MelvinBot commentedon Nov 19, 2026
Created and pushed the draft PR: Optimistically update distance rates when changing report workspace, assigned to
Krishna2323.view run