Skip to content

Rules - "Apply to existing unsubmitted expense" gets disabled when rule is reopened. #82888

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: 9.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): ibellicotest+2250@gmail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Motorola MotoG60 / Android 12 (Hybrid app) - Windows 11 / Chrome
App Component: Workspace Settings

Action Performed:

Prerequisite: User is an admin of a workspace.
Prerequisite 2: Rules enabled.

  1. Open the staging.new.expensify.com website.
  2. Navigate to "Workspaces" > "Rules" > "Add Merchant Rule"
  3. In "For expenses with" add any merchant.
  4. In "Apply these updates", add any category, description, tag and "Billable" field "On".
  5. Enable "Apply to existing unsubmitted expenses"
  6. Save the rule.
  7. Open the just created rule.
  8. Note that "Apply to existing unsubmitted expenses" toggle is disabled.

Expected Result:

"Apply to existing unsubmitted expenses" feature should remain enabled when user saves the rule and reopens it.

Actual Result:

"Apply to existing unsubmitted expenses" feature gets disabled after saving merchant rule and reopening the just created rule.

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 @dylanexpensify (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. twilight2294 commented on Feb 19, 2026

    @twilight2294
    Contributor

    Proposal

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

    When a user creates a merchant rule with the "Apply to existing unsubmitted expenses" toggle enabled, saves it, and then reopens the rule for editing, the toggle is always shown as disabled (off). This creates a confusing UX where the user's previously-set preference appears to be lost.

    What is the root cause of that problem?

    The toggle state is stored exclusively in local React component state in src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx at line 104:

    const [shouldUpdateMatchingTransactions, setShouldUpdateMatchingTransactions] = useState(false);

    Because it is hardcoded to false, every time the component remounts (i.e., when the user reopens the rule page), the toggle resets to off — regardless of what the user had previously set.

    The useEffect block that pre-populates form fields when editing an existing rule (lines 110–130) initializes all other fields from existingRule data but never calls setShouldUpdateMatchingTransactions(...). This means there is no path by which the toggle can be restored to a non-default state on remount.

    Additionally, the CodingRule type in src/types/onyx/Policy.ts has no field for shouldUpdateMatchingTransactions, and the setPolicyCodingRule action in src/libs/actions/Policy/Rules.ts never persists this value. As a result, there is no source of truth to restore the toggle state from on reopen.

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

    Since shouldUpdateMatchingTransactions is semantically a "do this retroactively right now" one-shot action flag (not a persistent rule attribute), the most pragmatic fix that matches user expectations is to default the toggle to true when editing an existing rule, rather than always defaulting to false. This matches the intuition that when a user reopens a rule to edit it, they likely want their changes applied retroactively.

    In src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx, line 104, change:

    // Before:
    const [shouldUpdateMatchingTransactions, setShouldUpdateMatchingTransactions] = useState(false);
    
    // After:
    const [shouldUpdateMatchingTransactions, setShouldUpdateMatchingTransactions] = useState(isEditing);

    This single change means new rule creation keeps the opt-in behavior (toggle starts off), while editing an existing rule pre-enables the toggle — consistent with the expectation that editing a rule should apply those edits retroactively by default.

    What alternative solutions did you explore?

    A more complete fix would involve: (1) adding a shouldUpdateMatchingTransactions?: boolean field to the CodingRule type in src/types/onyx/Policy.ts, (2) persisting the value in setPolicyCodingRule() in src/libs/actions/Policy/Rules.ts, and (3) reading it back in the useEffect initialization in MerchantRulePageBase.tsx. However, this approach conflicts with the semantic meaning of the toggle as a one-shot action rather than a persistent rule attribute, adding unnecessary complexity for limited benefit.

  7. OSBotify commented on Feb 19, 2026

    @OSBotify
    Contributor

    Investigation Summary

    Classification: Frontend bug
    Causing PR: #80545 - "Create merchant rule" by @luacmartins (High confidence)
    Related Issues: None

    Recommendation: ROLL FORWARD

    The issue is in the original implementation. The "Apply to existing unsubmitted expenses" toggle is stored in local component state and is not persisted as part of the rule data. When editing an existing rule, the toggle always defaults to false because there is no persisted value to restore.

    PR #82438 only enabled merchant rules for all users (removed the production check) but did not introduce this bug. The bug existed from the beginning when merchant rules were first implemented.

    Rolling forward with a fix is recommended because:

    1. Reverting Enable merchant rules v2 #82438 would disable the entire merchant rules feature
    2. The fix is straightforward - either persist the toggle value or clarify it as a one-time action in the UI

    Labels: No label changes made (keeping DeployBlockerCash since this blocks App deployment)

    Detailed Analysis

    Evidence

    In src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx:

    • Line 104: const [shouldUpdateMatchingTransactions, setShouldUpdateMatchingTransactions] = useState(false);
    • Lines 110-130: When editing a rule, the code initializes form fields from existingRule, but does NOT initialize shouldUpdateMatchingTransactions
    • Lines 397-404: The toggle UI is rendered with the local state value

    In src/libs/actions/Policy/Rules.ts:

    • Line 123: shouldUpdateMatchingTransactions is a parameter passed to the API
    • Line 223: It is sent as a one-time parameter, not persisted in the rule object
    • The CodingRule type in src/types/onyx/Policy.ts has no field for storing this value

    Verification

    The affected files:

    • /home/runner/_work/App/App/src/pages/workspace/rules/MerchantRules/MerchantRulePageBase.tsx - Contains the toggle UI and state
    • /home/runner/_work/App/App/src/libs/actions/Policy/Rules.ts - Contains the API call
    • /home/runner/_work/App/App/src/types/onyx/Policy.ts - Defines the CodingRule type (no field for toggle)

    PR #80545 created these files and introduced the toggle functionality on 2026-01-27.
    PR #82438 only removed the production check to enable the feature on 2026-02-18.

    Root Cause

    The toggle value is implemented as ephemeral local state rather than a persisted field. This appears to be a design/implementation oversight where:

    1. The toggle should either be persisted as part of the rule (requires backend changes)
    2. OR clarified in the UI that it only applies when creating/saving the rule
  8. MelvinBot commented on Feb 19, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When a user creates or edits a merchant rule and enables the "Apply to existing unsubmitted expenses" toggle, saves the rule, and then reopens it, the toggle is always shown as disabled/off — the user's selection is not persisted.

    What is the root cause of that problem?

    The "Apply to existing unsubmitted expenses" toggle is backed by local React state initialized to false on every mount:

    MerchantRulePageBase.tsx:104 — const [shouldUpdateMatchingTransactions, setShouldUpdateMatchingTransactions] = useState(false);

    This value is sent to the backend as the shouldUpdateMatchingTransactions parameter in the SetPolicyCodingRule API call (Rules.ts:223), but it is never persisted as part of the CodingRule data model. The CodingRule type (Policy.ts:1720-1756) has no field for it, and the edit-mode initialization useEffect (MerchantRulePageBase.tsx:110-130) only restores persisted fields (merchant, category, tag, etc.) — it never sets shouldUpdateMatchingTransactions because there's nothing to read.

    So every time the rule page mounts, the toggle defaults to false.

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

    Important consideration: The label "Apply to existing unsubmitted expenses" reads like a one-time action ("apply this rule retroactively now"), not a persistent rule property. If this is the intended design, the toggle resetting to off on each open is correct behavior — and the fix should be a UX clarification (e.g., wording change, or showing it only on create, not edit).

    However, if the intent is for this to be a persistent per-rule setting, then:

    1. Add a shouldUpdateMatchingTransactions (or similar) field to the CodingRule type in src/types/onyx/Policy.ts
    2. Include it in the optimistic Onyx data in setPolicyCodingRule in src/libs/actions/Policy/Rules.ts (the ruleForOnyx object around line 141)
    3. Read it back in the edit-mode useEffect in MerchantRulePageBase.tsx:110-130 to initialize setShouldUpdateMatchingTransactions(existingRule.shouldUpdateMatchingTransactions ?? false)
    4. Ensure the backend persists this field as part of the coding rule and returns it in policy data

    The product team should clarify which behavior is intended before implementing a fix.

    What alternative solutions did you explore? (Optional)

    If this toggle is intended as a one-time action:

    • Only show the toggle when creating a new rule (not when editing)
    • Or change the wording to make it clearer it's a one-time action (e.g., "Also apply to existing unsubmitted expenses now")

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

  9. m-natarajan commented on Feb 19, 2026

    @m-natarajan

    Reproduce, Chrome / v9.3.22-4

    Screen.Recording.2026-02-19.at.18.42.35.mp4
  10. added and removed
    DeployBlockerCashThis issue or pull request should block deployment
    on Feb 19, 2026
  11. luacmartins commented on Feb 19, 2026

    @luacmartins
    Contributor

    This is expected. Apply to existing expenses is a toggle that should be manually turned on/off each time you edit a rule since it's a one off event, i.e. we only apply to previously existing expenses when you either create or edit the rule.

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