Skip to content

Rules - "Similar merchant rule already exists" is shown when editing the original rule #84210

Closed

Description

@lanitochka17

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): sodijsojosjsdoj@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.2 / Chrome
App Component: Money Requests

Action Performed:

Precondition:

  • Rules are enabled.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Rules.
  3. Click Add merchant rule.
  4. Create a rule where category changes to Car when merchant is Apple.
  5. Create a second rule where category changes to Fees when merchant is Apple.
  6. Open the first rule from Step 4.
  7. Click Category, change it to Labor and click Save.
  8. Click Save rule.
    → "Your existing rule for "Apple" will take priority over this one" is shown when this is the original/first rule.
  9. Click Save anyway.
  10. Go to workspace chat.
  11. Create an expense with Apple merchant without category.
  12. Open the expense.
    → Category is changed to Labor, which means the first rule is prioritised. "Your existing rule for "Apple" will take priority over this one" in Step 8 is confusing as it indicates that the second rule will take priority over "this one".

Expected Result:

In Step 8, when editing the original/first rule, Your existing rule for "Apple" will take priority over this one" will not appear.

Actual Result:

In Step 8, when editing the original/first rule, Your existing rule for "Apple" will take priority over this one" is shown.
In Step 12, when merchant rule is applied, the first rule is prioritised.
"Your existing rule for "Apple" will take priority over this one" in Step 8 is confusing as it indicates that the second rule will take priority over "this one" when the original rule is edited.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7094008_1772653807950.15.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 Mar 4, 2026
  2. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  3. melvin-bot commented on Mar 4, 2026

    @melvin-bot

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

  4. github-actions commented on Mar 4, 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.
  5. melvin-bot commented on Mar 4, 2026

    @melvin-bot

    Triggered auto assignment to @heyjennahay (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. OSBotify commented on Mar 4, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #80545 - "Create merchant rule" by @luacmartins (High confidence)
    Related Issues: #82239 (tried to fix with PR #82440, but that PR is not yet in this staging deploy)

    Recommendation: ROLL FORWARD

    The issue is in the merchant rule duplicate detection logic in MerchantRulePageBase.tsx. When editing an existing rule to match another rules merchant, the duplicate warning always shows "Your existing rule for [merchant] will take priority over this one" - but this message is confusing when editing the FIRST/original rule because "this one" (the rule being edited) is actually the one that takes priority, not the "existing" duplicate that was created later.

    A fix should be relatively straightforward - the checkForDuplicateRule function needs to either:

    1. Not show the warning when the rule being edited has higher priority than the duplicate, OR
    2. Adjust the warning message to correctly reflect which rule actually takes priority

    Rolling forward with a fix is recommended over reverting because:

    • This is a UX/messaging issue, not a functional break
    • The merchant rules feature is working correctly (the right rule does take priority)
    • Only the warning message is confusing in this specific edit scenario
    • Reverting would remove the entire merchant rules feature which is more disruptive
    • PR Update duplicate rule copy #82440 attempted to address this but only changed wording, not the underlying logic

    Labels: No label changes needed - keeping DeployBlockerCash as this is a frontend (App) issue

    Detailed Analysis

    Evidence

    The bug report shows that when editing Rule 1 (created first, category=Car) to change it to category=Labor, after Rule 2 (category=Fees) was created with the same merchant, the warning message appears saying "Your existing rule for Apple will take priority over this one." This is confusing because "this one" refers to Rule 1 being edited, which is actually the original rule that takes priority.

    Verification

    I verified the checkForDuplicateRule function in src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx (lines 191-215). The function:

    • Skips the rule being edited (line 202-203)
    • Checks if ANY other rule has the same merchant and match type
    • Shows the generic warning if a match is found
    • Does NOT consider which rule was created first or has higher priority

    The actual behavior (Rule 1 takes priority over Rule 2) is correct - this is just a confusing message.

    Root Cause

    The checkForDuplicateRule function was introduced in PR #80545 when merchant rules were first created. It always assumes the rule being saved is the "new" one that will have lower priority, but when editing an older existing rule, this assumption is incorrect. The warning should either not appear in this case, or should dynamically determine which rule has priority and adjust the message accordingly.

  7. MelvinBot commented on Mar 4, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user has two merchant rules for the same merchant (e.g., "Apple") and edits the original/first rule, a confusing confirmation modal appears saying: "Your existing rule for 'Apple' will take priority over this one. Save anyway?" This message implies the other (second) rule will take priority, but in reality the first rule is the priority rule — it was created earlier and takes precedence. The warning should not appear when editing the rule that already has priority.

    What is the root cause of that problem?

    The checkForDuplicateRule function in src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx correctly skips the rule being edited but finds any other rule with the same merchant name and match type, returning a simple boolean. It does not consider which rule has priority based on creation order.

    When handleSubmit detects a duplicate, it always shows the same static prompt via the duplicateRulePrompt translation (src/languages/en.ts):

    "Your existing rule for '{merchantName}' will take priority over this one. Save anyway?"

    This message assumes "this one" (the rule being edited) is always the lower-priority rule. But when the user is editing the original/oldest rule, that assumption is wrong — the rule being edited IS the higher-priority rule, and the "existing" duplicate is actually the newer, lower-priority one.

    The created timestamp (which determines priority) is preserved on edits (src/libs/actions/Policy/Rules.ts: const created = existingRule?.created ?? new Date().toISOString()), so editing the first rule does not change its priority position.

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

    Modify checkForDuplicateRule in MerchantRulePageBase.tsx to be priority-aware. Instead of returning a simple boolean, it should compare the created timestamps of the rule being edited against the duplicate rule found:

    • If the rule being edited was created before the duplicate (i.e., the edited rule has priority) → return false (no warning needed, since this rule already takes precedence)
    • If the rule being edited was created after the duplicate (i.e., the duplicate has priority) → return true (show the existing warning as-is)

    Specifically, inside the .some() callback, after finding a matching rule, add a comparison of existingRule?.created against the found rule.created. If the rule being edited is older, skip the match.

    What alternative solutions did you explore? (Optional)

    An alternative would be to keep showing the warning in both directions but change the message text depending on which rule has priority (e.g., "This rule will take priority over your other rule for 'Apple'"). However, this adds UI complexity and the issue's expected behavior states the warning should simply not appear when editing the original rule.


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

  8. luacmartins commented on Mar 5, 2026

    @luacmartins
    Contributor

    @MelvinBot implement this

  9. luacmartins commented on Mar 5, 2026

    @luacmartins
    Contributor

    I don't think we need to block on this

  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Mar 5, 2026
  11. MelvinBot commented on Mar 5, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: #84224
    Please mark it as "Ready for review" when it is ready for review.

  12. added
    ReviewingHas a PR in review
    and removed on Mar 5, 2026
  13. self-assigned this
    on Mar 5, 2026
  14. JS00001 commented on Mar 5, 2026

    @JS00001
    Contributor

    This is merged

  15. luacmartins commented on Mar 6, 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

Labels

BugSomething is broken. Auto assigns a BugZero manager.EngineeringReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions