Skip to content

Rules - Track expense submitted to WS is always set to "Reimbursable" despite opposite rule. #84229

Closed

Description

@mitarachim

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.31.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: #83005
Email or phone of affected tester (no customers): ibellicotest+2250@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Windows 11 / Chrome
App Component: Money Requests

Action Performed:

Prerequisite: Account has a workspace with "Rules" enabled.
Prerequisite 2: Account has Self DM.

  1. Open the staging.new.expensify.com website.
  2. Navigate to "Workspaces" > "Rules"
  3. Scroll down to "Merchant" section.
  4. Click on "Add Merchant Rule"
  5. In "For expenses with" add any merchant name. (For example: Test)
  6. In "Apply these updates", add any category, any description, and set reimbursable field to "No".
  7. Save the just created rule.
  8. Navigate to Self DM.
  9. Create a manual expense.
  10. Click on "Submit it to someone"
  11. Add the merchant used for the created rule and submit the expense to the workspace where rule was created.
  12. Open the expense report.
  13. Note that all updates were correclty applied, but expense is still displayed as "Reimbursable"
  14. Note that system message shows "Marked the expense as non-reimbursable" despite expense being displayed as reimbursable.

Expected Result:

After submitting a track expense to a workspace, with a merchant used for a rule, all the fields included on the rule should be automatically updated.

Actual Result:

Track expenses are always set to "Reimbursable" when submitted to workspace, despite a rule being created setting the expense to "Non-reimbursable". The rest of the fields are correctly updated.
Also, system message after expense creation, displays a "Marked the expense as non-reimbursable" despite expense being displayed as "Reimbursable".

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7094168_1772666692582.Reimbursable.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @JS00001

Activity

  1. added
    DeployBlockerCash
    on Mar 5, 2026
  2. added
    Daily
    Bug
    DeployBlocker
    on Mar 5, 2026
  3. melvin-bot commented on Mar 5, 2026

    @melvin-bot

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

  4. melvin-bot commented on Mar 5, 2026

    @melvin-bot

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

  5. melvin-bot commented on Mar 5, 2026

    @melvin-bot

    Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  6. github-actions commented on Mar 5, 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.
  7. OSBotify commented on Mar 5, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Backend bug
    Causing PR: #83005 - "Enable merchant rules v3" by @luacmartins (High confidence)
    Related Issues: None found

    Recommendation: ROLL FORWARD

    The fix needs to happen in the backend. PR #83005 only removed a frontend check that was hiding merchant rules from production - it did not introduce the bug, it merely exposed an existing backend issue.

    Reverting #83005 would only hide the merchant rules feature again from users, it would not fix the underlying backend bug. The backend needs to be fixed to correctly apply the reimbursable field from rules when processing track expenses.

    Labels: Removing DeployBlockerCash label as this requires a backend fix, keeping DeployBlocker label.

    📋 Detailed Analysis

    Evidence

    PR #83005 merged on 2026-03-03 and only made one change: removed the production environment check that was hiding merchant rules. The PR diff shows:

    -    const {isProduction} = useEnvironment();
    -    if (isProduction) {
    -        return null;
    -    }

    This change simply enabled visibility of an existing feature - it did not modify any business logic for applying rules.

    Verification

    I traced the code path for track expenses being submitted to workspaces:

    1. Frontend (App) - src/libs/actions/IOU/index.ts:

      • Track expenses are submitted via categorizeTrackedExpense() function
      • The reimbursable field is correctly passed in transactionParams (lines 7555-7573)
      • This is sent to the backend via CATEGORIZE_TRACKED_EXPENSE API command
    2. Backend responsibility:

      • The backend receives the transaction data
      • Backend is supposed to check merchant rules and apply updates
      • Backend creates the system message "Marked the expense as non-reimbursable" (proving it knows about the rule)
      • But the backend fails to actually update the transaction's reimbursable field

    Root Cause

    The issue description states:

    • System message shows: "Marked the expense as non-reimbursable"
    • But expense displays as: "Reimbursable"

    This proves the backend IS processing the rule (hence the correct system message) but has a bug where it's not persisting the reimbursable field update to the transaction itself. This is a backend data consistency issue.

    The bug was always present in the backend code but was not visible until PR #83005 enabled the feature for production users. This is analogous to turning on a light switch and discovering a pre-existing wiring issue - the switch didn't cause the problem, it revealed it.

  8. removed
    DeployBlockerCash
    on Mar 5, 2026
  9. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a track expense is submitted to a workspace that has a merchant rule with reimbursable set to "No", the expense still displays as "Reimbursable". The system message correctly shows "Marked the expense as non-reimbursable", indicating the rule is being processed, but the actual transaction field is not updated. Other rule fields (category, description) are applied correctly.

    What is the root cause of that problem?

    There are two contributing issues, both on the frontend:

    1. Early return skips policy default reimbursable (IOURequestStepConfirmation.tsx:392-393)

    When submitting a tracked expense to a workspace (isMovingTransactionFromTrackExpense = true), an early return prevents setMoneyRequestReimbursable from being called with the target workspace's defaultReimbursable value. The tracked expense keeps reimbursable: true from its original self-DM context:

    if (isMovingTransactionFromTrackExpense) {
        return;  // skips setMoneyRequestReimbursable below
    }
    const defaultReimbursable = ... (policy?.defaultReimbursable ?? true) ...;
    setMoneyRequestReimbursable(transactionID, defaultReimbursable);
    

    2. Hardcoded reimbursable: true in API params (IOU/index.ts:6156)

    In convertTrackedExpenseToRequest, the params for ADD_TRACKED_EXPENSE_TO_POLICY hardcode reimbursable: true. While ...workspaceParams is spread after (line 6164), workspaceParams.reimbursable (line 6719) also comes from the tracked transaction which is always true:

    const params = {
        ...
        reimbursable: true,       // line 6156
        ...
        ...workspaceParams,        // workspaceParams.reimbursable is also true
    };
    

    The backend then applies the merchant rule and generates the system message ("Marked the expense as non-reimbursable") via a MODIFIED_EXPENSE action with policyRulesModifiedFields.reimbursable = false. However, the success data (line 2932-2938) only clears pendingAction and pendingFields — it does NOT update the transaction's reimbursable field. The optimistic reimbursable: true persists on the client.

    The fact that category and description are applied correctly suggests the backend does push those fields back, but the reimbursable field update from the backend either isn't included in the Onyx push or gets lost.

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

    Fix the early return in IOURequestStepConfirmation.tsx:392-393 — Remove or modify the early return so that setMoneyRequestReimbursable is still called with calculateDefaultReimbursable() even when isMovingTransactionFromTrackExpense is true. This ensures the target workspace's defaultReimbursable policy setting is applied to the draft transaction before submission.

    This is consistent with how defaultBillable is handled in the useEffect just above (lines 380-389), which also has an early return for isMovingTransactionFromTrackExpense — that early return should similarly be removed for consistency, but the reimbursable one is the critical fix.

    Additionally, the backend should be investigated to confirm that when a merchant rule applies reimbursable: false, the updated transaction value is included in the Onyx push response (since the system message proves the rule is matched and processed).

    What alternative solutions did you explore? (Optional)

    1. Only fix the backend: Since the backend generates the MODIFIED_EXPENSE action correctly, one could argue the backend should just include the updated reimbursable field in the transaction push. However, the frontend early return is still a bug — it means the optimistic UI always shows "Reimbursable" even momentarily, which is incorrect when the policy's default is non-reimbursable.

    2. Frontend rule matching: The frontend could try to match merchant rules optimistically and set reimbursable accordingly before sending to the backend. However, rule application is currently entirely backend-driven (no rule matching code exists in the IOU action module), and adding frontend rule matching would be over-engineering. The policy default is sufficient for the optimistic state.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.

  10. self-assigned this
    on Mar 5, 2026
  11. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Working on this one

  12. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    Demoting, but PR up

  13. added
    Daily
    and removed
    Hourly
    DeployBlocker
    on Mar 5, 2026
  14. luacmartins commented on Mar 5, 2026

    @luacmartins
    Contributor

    PR merged. Requested a CP

  15. added
    Reviewing
    on Mar 5, 2026
  16. luacmartins commented on Mar 6, 2026

    @luacmartins
    Contributor

    This is fixed

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

Metadata

Metadata

Labels

BugDailyEngineeringReviewing

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions