Skip to content

Rules - Existing expenses not updated after applying merchant rule and no system message #82914

Closed

Description

@jponikarchuk

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: v9.3.22-1
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: #82438
Email or phone of affected tester (no customers): applausetester+piyomn@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: iPhone 13 / iOS 18.7.1, Samsung Galaxy A52 / Android 14, Windows 11 / Chrome
App Component: Workspace Settings

Action Performed:

Preconditions: account has at least one workspace with rules in more feature enabled

Steps:

  1. Create several unsubmitted expenses with merchant "Starbucks" (I created 3 expenses)
  2. Navigate to workspace setting -> Rules -> Add merchant rule
  3. Create the merchant rule with "Starbucks" as the merchant, configure description and any categories except "Meals and Entertainment" (I choose "materials" for categories)
  4. Toggle on the "apply to existing unsubmitted expenses"
  5. Click the "Preview matches" button to make sure there's unsubmitted expenses there and and save it
  6. Navigate to the workspace chat
  7. Click on the newly created report with several expenses
  8. Click on any individual expense

Expected Result:

  • in step 6, merchant should updated to "Materials", like the description that auto updated to "Jajan" after "Apply to existing unsubmitted expenses" is toggled on in Step 4
  • in step 7, there should be a system message appeared on the update expenses since the description is updated.

Actual Result:

  • in step 6, merchant doesn't updated to "Materials" like the description that auto updated to "Jajan" after "Apply to existing unsubmitted expenses" is toggled on in Step 4
  • in step 7, the system message doesn't appeared on the update expense. there's only concierge system message from the original auto selected category before the merchant rule applied.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

1.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @luacmartins

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    on Feb 19, 2026
  2. melvin-bot commented on Feb 19, 2026

    @melvin-bot

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

  3. melvin-bot commented on Feb 19, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 19, 2026

    @melvin-bot

    Triggered auto assignment to @brianlee-expensify (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.

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

    @OSBotify
    Contributor

    🔍 Investigation Summary

    Classification: Frontend bug
    Causing PR: #82438 - "Enable merchant rules v2" by @luacmartins (High confidence)
    Related Issues: #82225 (similar issue from previous merchant rules enable attempt)

    Recommendation: REVERT

    PR #82438 enabled the merchant rules feature by removing the production gate. While the bug exists in the backend API logic (which partially applies rules - updating description but not merchant field), reverting the App PR is the correct action to prevent shipping broken functionality to users. The feature should remain hidden until the backend correctly implements the full merchant rule application including merchant field updates and system messages.

    Labels: Keeping DeployBlockerCash (App deploy blocked until revert)

    📋 Detailed Analysis

    Evidence

    PR #82438 removed only the isProduction check from MerchantRulesSection.tsx, making the merchant rules feature visible to all users. The feature was previously gated and this PR enabled it for the first time in this deploy cycle.

    The issue describes that when applying a merchant rule with "apply to existing unsubmitted expenses" toggled:

    • Description field updates correctly ✓
    • Merchant field does NOT update ✗
    • No system message appears ✗

    This matches the behavior described in issue #82225 from the previous merchant rules enable attempt (PR #81033), which was also reverted due to similar issues.

    Verification

    • PR Enable merchant rules v2 #82438 modified src/pages/workspace/rules/MerchantRulesSection.tsx
    • The change removed the production gate: if (isProduction) { return null; }
    • This directly enabled the merchant rules feature that exhibits the reported bug
    • The issue is reproducible on staging (where PR Enable merchant rules v2 #82438 is deployed) but N/A on production (where the feature doesn't exist)

    Root Cause

    The frontend correctly passes shouldUpdateMatchingTransactions: true to the backend API (SET_POLICY_CODING_RULE). The backend API is responsible for updating matching transactions but only partially applies the rule - it updates the description field but fails to update the merchant field and generate system messages.

    While the root cause is a backend bug, the correct action per deploy blocker protocol is to revert the App PR that exposed the broken feature to users, then address the backend bug before re-enabling the feature.

  7. MelvinBot commented on Feb 19, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When creating a merchant rule with "Apply to existing unsubmitted expenses" toggled ON, the category field is not applied to matching existing expenses, even though the description field IS applied correctly. Additionally, no system message appears for the category update on the affected expenses.

    What is the root cause of that problem?

    The root cause is in the backend SetPolicyCodingRule command handler, not in the frontend App code. Here's why:

    The frontend correctly sends all rule fields (category, description/comment, tag, tax, merchant, reimbursable, billable) to the backend via the SetPolicyCodingRule API command. Specifically:

    1. mapFormFieldsToRuleForAPI() in src/libs/actions/Policy/Rules.ts:71-99 builds the complete rule object — both category and comment (description) are included identically using the same truthy-check pattern.
    2. The rule is JSON-stringified into the codingRuleValue parameter alongside shouldUpdateMatchingTransactions: true (src/libs/actions/Policy/Rules.ts:219-224).
    3. The frontend creates zero optimistic transaction updates or report actions — it only optimistically updates the policy's codingRules record (src/libs/actions/Policy/Rules.ts:170-217). The entire "apply to existing" logic is delegated to the backend.

    The backend handler for SetPolicyCodingRule is responsible for: (a) finding matching transactions, (b) updating their fields, and (c) creating MODIFIEDEXPENSE report actions with policyRulesModifiedFields in the original message. The backend appears to handle comment (description) correctly but skips category when applying the rule to existing transactions.

    The frontend rendering code for policy-rules-modified system messages is fully implemented and ready — getPolicyRulesModifiedMessage() in src/libs/ModifiedExpenseMessage.ts:205-242 explicitly handles the category key and would render the message correctly if the backend created the report action.

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

    The fix needs to be made in the backend SetPolicyCodingRule command handler (likely in Web-Expensify or Auth). When shouldUpdateMatchingTransactions is true, the handler must:

    1. Apply all rule fields to matching transactions — not just comment (description), but also category, tag, tax, merchant, reimbursable, and billable.
    2. Create MODIFIEDEXPENSE report actions for each modified transaction with policyRulesModifiedFields containing all changed fields (including category) and the policyID, so the frontend can render the system messages.

    No changes are needed in the App (frontend) repo — the form submission, API parameter construction, and system message rendering are all correctly implemented.

    What alternative solutions did you explore? (Optional)

    Considered whether this could be a frontend issue where the category field is omitted from the API payload, but traced the complete data flow and confirmed both category and comment are sent identically via mapFormFieldsToRuleForAPI(). Also considered whether optimistic data might need to update transactions client-side, but this would be impractical since the frontend doesn't know which transactions match — the backend must handle matching and updating.


    Next Steps for Contributor+ team: This is a backend-only bug. The SetPolicyCodingRule handler needs to be investigated to confirm which fields it applies to matching transactions when shouldUpdateMatchingTransactions=true. Reply with @MelvinBot <your feedback> to refine this analysis.

  8. luacmartins commented on Feb 19, 2026

    @luacmartins
    Contributor

    We reverted the offending PR. NAB. PR to fix this is in review.

  9. luacmartins commented on Mar 3, 2026

    @luacmartins
    Contributor

    This is done

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

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2EngineeringReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions