Skip to content

[Tracking] Auto-select distance rate on workspace change (frontend) #100555

Open

Description

@neil-marcellini

(Neil's AI agent)

Problem

When a user changes the workspace of a distance expense — by moving it to a report on another workspace, or by changing the report's workspace — the distance rate field can show a "Rate not valid for this workspace" violation. That confuses users and adds friction.

Solution

Auto-select a valid distance rate on the destination workspace, and show the Concierge system messages explaining what we did. The message design was revised during the F1 review.

This is the frontend half of the plan. The full plan, including the rules for choosing a rate and the backend work, lives in the backend tracking issue: Auto-select distance rate on workspace change. Read that first — the rules below are a summary of it.

⭐ Project board ⭐

Rules

A matching rate is an enabled rate on the destination policy, valid for the expense date, whose value and distance unit equal the expense's current rate and whose currency equals the expense's own currency. The unit comes from the policy's distance custom unit (attributes.unit), so in practice a unit mismatch disqualifies the whole destination policy from matching.

Selection order: matching rate → destination policy's default rate (narrowest, most recent date range). A disabled value-matching rate is not a match, so we fall through to the default rate. When no enabled rate's date range covers the expense, the default is the first enabled rate and the expense gets a customUnitRateOutOfDateRange warning. When the destination has no enabled rate, the expense keeps its rate and the customUnitOutOfPolicy violation.

An expense that matches a rate keeps its price. It moves to the matching rate's ID, its amount and merchant (including manual edits) stay as they are, and it gets no system message.

System messages are posted only when an existing expense's workspace changes, and only for expenses repriced onto the default rate. If the policy changes during the expense creation flow, we auto-select the rate silently.

  • Per expense, both flows: Concierge posts a MODIFIEDEXPENSE on each repriced expense's transaction thread, using the existing rate-change copy: 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).
  • Per report, Change workspace only: when a report's workspace changes and at least one expense was repriced, Concierge also posts one CONCIERGEAUTOSELECTDISTANCERATE on the report: distance rates updated for the new workspace - Test 2. Move expense posts no report-level message.

The server is authoritative. Auth chooses the rate; the app computes the same choice purely for optimistic data and stops sending its own answer.

Deploy ordering

Two constraints from the backend issue that shape the order of these PRs:

  1. Auth lands before the app's optimistic mirror, per command. Auth-first means the user sees the rate change arrive with the server response instead of instantly — fine. App-first is the broken direction: the app would show a rate change Auth never made, and it would flip back on the next reload.
  2. F1 must deploy before Auth starts creating the new Concierge action. Unrecognized action names are filtered out entirely by shouldReportActionBeVisible against a supportedActionTypes allowlist, so a build that predates F1 hides the message entirely and nothing Auth puts on the action changes that.

Implementation plan

F1. Render the Concierge message

Ships first so the action type is recognized before Auth ever creates one.

  • Add the action type to CONST.REPORT.ACTIONS.TYPE (which puts it in the supportedActionTypes allowlist) and an OriginalMessage variant in src/types/onyx/OriginalMessage.ts.
  • Handle it in ActionContentRouter next to CONCIERGE_AUTO_MATCH_VENDOR.
  • Add the copy to en.ts / es.ts: distance rates updated for the new workspace - Hal's Burgers.
  • Fix the existing MODIFIEDEXPENSE copy so a rate-only change says "changed the rate…" instead of "changed the distance…" (the merchant regex didn't allow thousands separators).

The originalMessage is just {policyName}, since a report's expenses can land on different rates. Each expense's own rate change is shown by its MODIFIEDEXPENSE. The LHN preview is built from the translation, and Auth's English message is only a fallback.

✅ Shipped in App#100781.

F2. Shared selection helper

Add DistanceRequestUtils.getRateForPolicyChange({transaction, policy}) implementing the rules above: value + currency + unit match against enabled rates valid for the expense date, then getBestEligibleRateOrPolicyDefault. The date-range ranking is already implemented in getBestEligibleRate and matches Auth's getBestDistanceCustomUnitRateIDForDate, so this is mostly wiring.

✅ Shipped as getRateForPolicyChange.

Because the server is authoritative and the app only mirrors it, add a comment on both implementations pointing at the other — the same convention getRate already uses.

F3. Move expense: guard on policy change

The auto-select block in getChangeTransactionsReportOnyxData fires for any group-policy destination whenever the current rate is invalid, with no check that the policy is changing. Add that check and swap getDefaultMileageRate (which just sorts by index and takes the first) for F2. For each expense repriced onto the default rate, build a Concierge MODIFIEDEXPENSE optimistically on its transaction thread with buildOptimisticModifiedExpenseReportAction. Send its ID as modifiedExpenseReportActionID in that expense's transactionIDToReportActionAndThreadData entry. Skip it for an expense that matched a rate. There is no report-level message for a move.

The rate swap must stay before the violation recompute, since ViolationsUtils.getViolationsOnyxData rejects customUnitOutOfPolicy once the rate resolves.

This is the PR that closes the user-visible bug in Expense-Rate violation disappears after moving expense to another report.

F4. Change workspace: add optimistic rate updates

changeReportPolicy has no rate logic at all. Add optimistic rate/amount/merchant/currency updates for each distance transaction on the report, the matching failure data, the recomputed violations, a Concierge MODIFIEDEXPENSE on each repriced expense's thread, and the Concierge report message. Same for changeReportPolicyAndInviteSubmitter. This is the larger frontend piece because it loops the report's transactions rather than one.

F5. Stop sending the rate ID

Remove transactionIDToUpdatedCustomUnitRateID from the ChangeTransactionsReport params. Keep computing the rate locally for optimistic data.

F6. Move IOU report to a workspace: add optimistic rate updates

moveIOUReportToPolicy and moveIOUReportToPolicyAndInviteSubmitter have no rate logic, though Auth already reprices these expenses and posts both Concierge messages. Add the same optimistic data as F4, reusing its code: rate/amount/merchant/currency updates, failure data, recomputed violations, a Concierge MODIFIEDEXPENSE per repriced expense and the report message. Needs Auth to accept the optimistic IDs first (Expensify#705352). Tracked in App#107065.

PRs

Every PR carries its own tests.

  • F1 — register the action type, render it, add copy. Must deploy before backend PR 3. Depends on backend PR 2 for the exact action type string, so agree that up front.
  • F2 — the shared helper. No callers changed, so this can land any time.
  • F3 — move-expense guard, helper swap, optimistic MODIFIEDEXPENSE per repriced expense. Depends on F1, F2, and backend PR 3 being deployed. Closes the reported bug.
  • F4 — change-workspace optimistic rate updates, MODIFIEDEXPENSE per repriced expense, and the Concierge report message. Depends on F1, F2, and backend PR 4 being deployed.
  • F5 — stop sending transactionIDToUpdatedCustomUnitRateID. Depends on backend PR 3 being deployed.
  • F6 — IOU-to-workspace optimistic rate updates (App#107065). Depends on F4 and Expensify#705352 being deployed.

Activity

  1. neil-marcellini commented on Sep 7, 2026

    @neil-marcellini
    ContributorAuthor
  2. melvin-bot commented on Sep 8, 2026

    @melvin-bot

    @neil-marcellini — to hire @dmkt9 on Upwork, add the External label so a job is created and the offer is sent automatically.

  3. neil-marcellini commented on Sep 8, 2026

    @neil-marcellini
    ContributorAuthor

    I assigned all App issues to C+ and they can start now if their issue is not on HOLD.

  4. neil-marcellini commented on Sep 16, 2026

    @neil-marcellini
    ContributorAuthor

    Working on it and making decent progress.

  5. neil-marcellini commented on Sep 22, 2026

    @neil-marcellini
    ContributorAuthor

    Holding on the backend now. I'll try to unblock it soon.

  6. neil-marcellini commented on Sep 29, 2026

    @neil-marcellini
    ContributorAuthor

    I almost have the backend PR ready, hopefully I'll get it up for review today.

  7. neil-marcellini commented on Oct 6, 2026

    @neil-marcellini
    ContributorAuthor

    Still not quite there.

  8. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    This issue has not been updated in over 15 days. @neil-marcellini 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!

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

Metadata

Metadata

Labels

EngineeringInternalRequires API changes or must be handled by Expensify staffMonthlyKSv2ReviewingHas a PR in review

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions