Skip to content

Workspace rule takes precedence over personal rule #82223

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.17-6
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: #81033
Email or phone of affected tester (no customers): kiatest.80+ck212263@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: iPhone 16/iOS 18.7.1
App Component: Money Requests

Action Performed:

  1. Launch Hybrid app
  2. As a admin of workspace, apply following rules:
  • Create workspace rule for "Amazon" → Category: "Office Supplies"
  • Create personal rule for "Amazon" → Category: "Software" (Account >> Expense Rules)
  • Create workspace rule for "Amazon" → Category: "Travel" (newer, should lose)
  1. Go to workspace chat
  2. Create an expense with merchant: "Amazon"
  3. Observe workspace rule get applied instead of personal rule

Expected Result:

Personal rule wins → Category: "Software". Personal rule should take precedence over workspace rule

Actual Result:

Workspace rule takes precedence over personal rule. Workspace rule with category "Office Supplies" get 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

Activity

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

    @melvin-bot

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

  3. melvin-bot commented on Feb 12, 2026

    @melvin-bot

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

  4. melvin-bot commented on Feb 12, 2026

    @melvin-bot

    Triggered auto assignment to @NicMendonca (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 12, 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 12, 2026

    @OSBotify
    Contributor

    🔍 Investigation Summary

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

    Recommendation: NEEDS INVESTIGATION

    This is a backend bug where the rule precedence logic is incorrect. PR #81033 simply removed the production environment check that was hiding merchant rules from production users, which exposed a pre-existing backend bug in the rule precedence logic.

    According to the official documentation, personal expense rules should take precedence over workspace merchant rules. However, the current implementation is applying workspace rules instead.

    Since this is a backend precedence logic issue, it requires investigation by the backend team to fix the rule application order on the server side.

    Labels: Removed DeployBlockerCash label since this is a backend bug. Keeping DeployBlocker label.

    📋 Detailed Analysis

    Evidence

    PR #81033 was a simple change that removed the isProduction environment check from src/pages/workspace/rules/MerchantRulesSection.tsx, enabling merchant rules for all users. This PR itself did not introduce rule precedence logic—it only made the feature visible to production users.

    The bug was reported as:

    • Expected: Personal rule with category "Software" should be applied
    • Actual: Workspace rule with category "Office Supplies" is applied instead
    • The test specifically created multiple rules to test precedence:
      1. Workspace rule for "Amazon" → Category: "Office Supplies"
      2. Personal rule for "Amazon" → Category: "Software"
      3. Workspace rule for "Amazon" → Category: "Travel" (newer, loses to older workspace rule)

    Verification

    The official documentation explicitly states:

    "What happens if a personal expense rule and a Workspace Merchant Rule both apply?
    Personal expense rules take precedence over Workspace Merchant Rules."

    This confirms the reported behavior is indeed a bug. The rule application logic exists on the backend (rules are applied when expenses are created via API calls), not in the frontend App code.

    Root Cause

    The rule precedence logic is implemented on the backend. When an expense is created with a merchant name that matches both personal and workspace rules, the backend should:

    1. First check for matching personal rules
    2. Only apply workspace rules if no personal rule matches

    Currently, it appears the backend is applying workspace rules without properly checking for personal rule precedence, or the precedence order is reversed.

    Since PR #81033 only removed a UI visibility check and did not modify any rule application logic, this is a backend bug that was always present but only became visible when merchant rules were enabled for production users.

  7. OSBotify commented on Feb 12, 2026

    @OSBotify
    Contributor

    Update

    I have removed the DeployBlockerCash label because this is a backend bug that requires a backend fix, not an App revert or fix.

    Why this is a backend bug:

    1. PR Enable merchant rules #81033 only changed frontend code to show the merchant rules UI in production (removed an isProduction check)
    2. The rule precedence logic that determines which rule to apply (personal vs workspace) is implemented on the backend
    3. No App code change caused the incorrect precedence behavior
    4. The fix needs to happen in the backend API that applies rules to expenses

    The bug blocks deploying because it affects core functionality (expense rule precedence), but there is no App PR to revert. The backend team needs to investigate and fix the rule application logic on the server side.

  8. luacmartins commented on Feb 12, 2026

    @luacmartins
    Contributor

    Discussing this. The logic currently fails because we first apply the workspace rule, which sets a category. And then we run into this logic that only applies a category if one is not set, effectively skipping the personal rule

  9. self-assigned this
    on Feb 13, 2026
  10. JS00001 commented on Feb 13, 2026

    @JS00001
    Contributor
  11. luacmartins commented on Feb 17, 2026

    @luacmartins
    Contributor

    PR is merged. Closing.

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.DailyKSv2EngineeringReviewingHas a PR in review

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions