Skip to content

Rules - Rules behavior unchanged after merchant match type is changed to 'Exactly matches" #82899

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+aqwa@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:

  1. Prepare two accounts (Admin and Member)
  2. As Admin create a workspace and invite the member to the workspace
  3. Enable rules in more feature

Steps:

  1. (Admin) navigate to rules in workspace setting, scroll down and add merchant rule:
  • Match type: Contains
  • Merchant: "Coffee"
  • Category: "Meals & Entertainment"
  1. (Admin) Save the rule
  2. (Member) create expenses with merchants "Starbucks Coffee" → Verify rule applies
  3. (Admin) Edit the "Coffee" rule created above
  4. (Admin) Change Match type from "Contains" to "Exactly matches" and save the rule
  5. (Member) create an expense with merchant: "Starbucks Coffee"

Expected Result:

After member created the second expense when the rule already changed, the rule should not be applied (no longer contains match). Also there should be system message displayed on the expense details.

Actual Result:

Rules remain active after the admin updates the merchant match type to “exactly matches". Also, there's no system message displayed to show whether the category is automatically set by concierge or by the workspace rules.

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

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 @stephanieelliott (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: Backend bug
    Causing PR: #82438 - "Enable merchant rules v2" by @luacmartins (High confidence)
    Related Issues: None found

    Recommendation: REVERT

    PR #82438 enabled merchant rules in production by removing the production environment check. However, this exposed a backend bug where the rule matching logic does not properly respect updated match types (operator changes from "Contains" to "Exactly matches").

    The App correctly sends the updated rule to the backend via the SET_POLICY_CODING_RULE API command. The bug occurs on the backend when applying rules to new transactions - the backend is not correctly evaluating the updated operator when matching merchant names.

    Since this is a new feature that does not exist in production and the bug is in backend rule application logic (not in the App code), we should revert PR #82438 to restore the production check until the backend rule matching logic is fixed.

    Labels: Removing DeployBlockerCash and keeping Bug label. This is a backend bug that blocks deployment but does not require App changes.

    📋 Detailed Analysis

    Evidence

    PR #82438 removed the isProduction check from MerchantRulesSection.tsx, enabling merchant rules for all users. The PR only contains frontend changes - it removes 6 lines that prevented the merchant rules UI from being displayed in production.

    The bug report shows that after editing a rule to change the match type from "Contains" to "Exactly matches", the rule continues to match using the old "Contains" behavior. This indicates the backend rule evaluation engine is not properly updating its matching logic when the operator changes.

    Verification

    Files affected by the bug:

    • Backend rule application logic (not in App repository)
    • The symptom appears when members create expenses, which triggers backend rule evaluation

    PR #82438 changes:

    • Only modified src/pages/workspace/rules/MerchantRulesSection.tsx
    • Removed the production environment check that hid the merchant rules feature
    • No changes to rule creation, editing, or application logic

    Root Cause

    When an admin edits a merchant rule and changes the match type (operator), the App correctly:

    1. Updates the form with the new matchType value (line 116 in MerchantRulePageBase.tsx)
    2. Calls setPolicyCodingRule() with the updated form data (line 208)
    3. Sends the updated rule to the API with the new operator (line 137-146 in Rules.ts)

    However, the backend does not properly apply the updated operator when evaluating rules against new transactions. The backend continues to use the old matching behavior, suggesting either:

    • The backend is caching the old rule configuration
    • The backend rule evaluation logic has a bug in how it processes operator updates
    • The backend is not receiving or storing the updated operator correctly

    This is purely a backend issue because:

    • Rule application happens server-side when expenses are created
    • The App only manages the rule UI and sends configurations to the API
    • No client-side rule matching occurs in the App codebase
  7. MelvinBot commented on Feb 19, 2026

    @MelvinBot
    Contributor

    Proposal

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

    Two issues with workspace merchant rules (CodingRules):

    1. After an admin changes a merchant rule's match type from "Contains" to "Exactly matches" and saves, the old "Contains" behavior persists when a member creates a new expense. For example, a rule for "Coffee" that was changed to "Exactly matches" still matches "Starbucks Coffee" (contains behavior).
    2. No system message is displayed on the expense to indicate that the category was auto-set by workspace rules.

    What is the root cause of that problem?

    Both issues are server-side bugs. Merchant rule matching is done entirely on the backend — the App frontend has zero rule-evaluation logic.

    Evidence from code investigation:

    1. Rule save is correct on the frontend: When saving a rule, setPolicyCodingRule() at App/src/libs/actions/Policy/Rules.ts:137-163 correctly reads the match type and includes it in the filters object:

      const operator = form.matchType ?? CONST.SEARCH.SYNTAX_OPERATORS.CONTAINS;
      filters: { left: 'merchant', operator, right: form.merchantToMatch }
      

      This operator ('eq' for "Exactly matches", 'contains' for "Contains") is sent to the backend as part of the JSON-stringified codingRuleValue parameter via the SetPolicyCodingRule API.

    2. No client-side rule matching: Expense creation via RequestMoney at App/src/libs/actions/IOU/index.ts sends raw transaction data to the backend with no reference to coding rules. All IOU action files have zero references to codingRule, expenseRule, or rule-matching logic.

    3. System message mechanism exists but is backend-generated: The MODIFIEDEXPENSE report action type has a policyRulesModifiedFields property (App/src/types/onyx/OriginalMessage.ts:837-856) and the frontend renders it via getPolicyRulesModifiedMessage() at App/src/libs/ModifiedExpenseMessage.ts:205-241. But this message is generated by the backend — if it's missing, the backend isn't creating it.

    Root cause hypotheses (backend — not inspectable from App repo):

    • Issue 1 (stale match type): The backend RequestMoney handler likely ignores or defaults the operator field when evaluating coding rules, always using "contains" semantics regardless of the stored operator. Alternatively, there may be a caching layer for policy rules that serves stale data after an update.
    • Issue 2 (missing system message): The backend may not be generating the MODIFIEDEXPENSE report action with policyRulesModifiedFields when coding rules are applied to new expenses (it may only generate them for retroactive updates via shouldUpdateMatchingTransactions).

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

    Since this is a backend issue, the fix needs to be in the Auth/Web-Expensify server code:

    1. For the match type bug: The backend handler for RequestMoney (or its post-processing that applies coding rules) needs to be updated to respect the operator field from CodingRuleFilter. When operator is 'eq', it should require an exact match (case-insensitive) between the transaction merchant and filters.right. When operator is 'contains', it should check if the merchant string contains filters.right as a substring.

    2. For the missing system message: The backend should generate a MODIFIEDEXPENSE report action with policyRulesModifiedFields whenever a coding rule is applied to a new expense, not only during retroactive updates. The frontend already has the rendering logic in place at ModifiedExpenseMessage.ts:205-241.

    What alternative solutions did you explore? (Optional)

    Investigated whether the matching could be done client-side as a workaround, but this would be architecturally wrong — the backend is the source of truth for rule evaluation, and the system message generation must also happen server-side. Moving matching client-side would create inconsistencies between platforms and bypass server-side validation.

    Detailed Investigation

    Architecture Overview

    Workspace merchant rules are stored as CodingRule objects in policy.rules.codingRules (type defined at App/src/types/onyx/Policy.ts:1720-1756). Each rule has:

    • filters: { left: 'merchant', operator: 'contains' | 'eq', right: '<pattern>' }
    • Action fields: merchant, category, tag, comment, tax, reimbursable, billable

    Data Flow

    1. Rule creation/edit: Admin selects match type in AddMatchTypePage.tsx → stored in form as matchType → setPolicyCodingRule() builds filters.operator and sends SetPolicyCodingRule API
    2. Expense creation: Member calls requestMoney() → sends RequestMoney API with raw expense data → backend evaluates rules → applies matching fields → generates MODIFIEDEXPENSE report action
    3. System message: Backend generates policyRulesModifiedFields on MODIFIEDEXPENSE → frontend renders via getPolicyRulesModifiedMessage()

    Key Files

    • App/src/libs/actions/Policy/Rules.ts:123-226 - Rule CRUD (correctly sends operator)
    • App/src/types/onyx/Policy.ts:1691-1756 - CodingRule type (includes operator in filters)
    • App/src/pages/workspace/rules/MerchantRules/AddMatchTypePage.tsx:41-58 - Match type selection UI
    • App/src/libs/ModifiedExpenseMessage.ts:205-241 - System message rendering
    • App/src/types/onyx/OriginalMessage.ts:837-856 - policyRulesModifiedFields type

    Evidence Chain

    Frontend save → SetPolicyCodingRule API with operator: 'eq' → Backend stores rule → Member creates expense → RequestMoney API → Backend should match using 'eq' semantics but appears to use 'contains' → Backend should generate system message but doesn't


    Next Steps for Contributor+ team: This is a backend bug. The fix needs to be in the server-side code that handles RequestMoney and evaluates coding rules. The App frontend correctly sends and displays all the necessary data. Reply with @MelvinBot implement this to create a draft PR (if the fix is in the App repo), or @MelvinBot <your feedback> to refine this analysis.

  8. luacmartins commented on Feb 19, 2026

    @luacmartins
    Contributor

    This is not an issue. The rule is updated correctly, but we also have AgentZero auto-categorizing expenses. So when the user changed the rule to exactly matches the rule no longer applies, but AZ still auto-categorizes the expense as Meals & Entertainment which makes it seem like the rule is being applied.

    Closing as expected.

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.DailyKSv2Engineering

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions