Skip to content

[$250] WS Setting - Added merchant rule disappeared after clear cache and restart #89717

Closed

Description

@mitarachim

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.67-3
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #87737
Email or phone of affected tester (no customers): applausetester+newccpiyo@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: iPhone 13 / iOS 26.5
App Component: Workspace Settings

Action Performed:

Preconditions

  • Logged in to expensifail account -> create a workspace -> enable rule -> add merchant rule

Steps:

  1. Create another workspace
  2. Tap more feature in newly workspace setting and enable rules
  3. Tap rules -> scroll down to merchant section
  4. Tap "Add merchant rule" and fill the adding rule process
  5. Tap save rule -> note that the added merchant rule displayed correctly
  6. Navigate to account -> Troubleshoot -> Tap "clear cache and restart" and confirm it
  7. Back to the just created workspace and navigate to rule in workspace setting
  8. Scroll down to Merchant section
  9. Tap "Add merchant rule" and fill the adding rule process then save the rule -> note that both merchant rules are now displayed

Expected Result:

in step 8, after clear cache and restart, the first added merchant rule shouldn't be disappeared

Actual Result:

in step 8, added merchant rule disappeared after clear cache and restart

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Bug7145608_1778044949855.merchant_rule.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022054386451270274100
  • Upwork Job ID: 2054386451270274100
  • Last Price Increase: 2026-05-13
Issue OwnerCurrent Issue Owner: @allgandalf

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    and removed on May 13, 2026
  2. MelvinBot commented on May 13, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Merchant rules (codingRules) are stored as a nested property on the Policy Onyx object at policy.rules.codingRules. They are properly persisted to the backend via API.write(SET_POLICY_CODING_RULE), but they are only fetched from the backend via the OpenPolicyRulesPage READ command, which is a lazy-load call that only fires when the user navigates to the Rules page.

    When "Clear cache and restart" is triggered, clearOnyxAndResetApp wipes all Onyx data and then calls OpenApp. The OpenApp command returns basic policy data but does not include codingRules. When the user then navigates to the Rules page, PolicyRulesPage calls openPolicyRulesPage on mount — but the backend's response for this READ command appears to not return codingRules, since the rules remain missing until the user adds a new rule (at which point the SET_POLICY_CODING_RULE API response brings back all coding rules, including the previously "missing" one).

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

    This is likely a backend issue: the OpenPolicyRulesPage API handler needs to include codingRules in its Onyx response data so that existing merchant rules are loaded when the user navigates to the Rules page after a cache clear.

    To confirm, verify whether the OpenPolicyRulesPage backend handler returns codingRules in its Onyx updates. If it doesn't, add codingRules to the response payload alongside other rule types (approvalRules, expenseRules).

    What alternative solutions did you explore? (Optional)

    An alternative client-side approach would be to eagerly fetch rules data during OpenApp/ReconnectApp for policies that have rules enabled, but this would add unnecessary overhead for most users. The proper fix is ensuring OpenPolicyRulesPage returns complete data.

    Investigation details

    Data flow (normal):

    1. User adds merchant rule → setPolicyCodingRule() optimistically updates Onyx AND calls API.write(SET_POLICY_CODING_RULE) to persist on the backend
    2. Rules appear correctly in MerchantRulesSection which reads policy?.rules?.codingRules

    Data flow (after cache clear):

    1. clearOnyxAndResetApp() wipes ALL Onyx data including policy.rules.codingRules
    2. OpenApp fires → returns policy data without codingRules
    3. User navigates to Rules page → openPolicyRulesPage() fires via useEffect → backend response does not populate codingRules
    4. MerchantRulesSection reads policy?.rules?.codingRules → undefined → no rules shown
    5. User adds a new rule → SET_POLICY_CODING_RULE write succeeds → server response includes all coding rules → both old and new rules appear

    Step 5 proves the rules are persisted on the backend. The gap is in step 3: OpenPolicyRulesPage isn't returning them.

    Key evidence: The issue's step 9 shows that after adding a new merchant rule post-cache-clear, both the old and new rules appear — confirming the backend has the data but OpenPolicyRulesPage isn't serving it.

    Possibly related: Expensify/App#83130 — offline-deleted rules reappearing after reconnecting until cache is cleared (inverse symptom, same data persistence area).


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 13, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 13, 2026
  5. melvin-bot commented on May 13, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @cretadn22 (External)

  6. changed the title [-]WS Setting - Added merchant rule disappeared after clear cache and restart[/-] [+][$250] WS Setting - Added merchant rule disappeared after clear cache and restart[/+] on May 13, 2026
  7. melvin-bot commented on May 13, 2026

    @melvin-bot
  8. neerajbachani commented on May 13, 2026

    @neerajbachani
    Contributor

    Proposal

    What is the root cause of that problem?

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

    What alternative solutions did you explore? (Optional)

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  9. 18 remaining items

  10. allgandalf commented on May 28, 2026

    @allgandalf
    Contributor

    Hello, Sorry for missing the last ping somehow.

    I'm about to go OoO till monday and i have some higher priority things to work on today before i log off, since this issue was reported by internal QA team and not customers, I hope it would be fine that i look into this after i'm back.

    Apologies for the delay here :) Please reassign if it priority is higher

    Scratch that, i took a glance and the issue seemed easier than i thought so i have a PR ready:

  11. allgandalf commented on May 28, 2026

    @allgandalf
    Contributor

    The merchant rules was not something which was available at the time i created the PR for OpenPolicyRulesPage command, so i'll also notify the authors who implemented it to point it out for their context

    Edit:

    Commented here https://github.com/Expensify/Expensify/issues/593005#issuecomment-4561392271

  12. mvtglobally commented on May 30, 2026

    @mvtglobally

    Issue not reproducible during KI retests. (First week)

  13. allgandalf commented on Jun 1, 2026

    @allgandalf
    Contributor

    @mvtglobally please test in a non default workspace , the bug is still reproducible

  14. allgandalf commented on Jun 1, 2026

    @allgandalf
    Contributor
  15. IuliiaHerets commented on Jun 1, 2026

    @IuliiaHerets

    Reproducible on iPhone 13/iOS 26.5 v9.3.89-5

    45a8e4fdcc28bd8103df77a2bd5b3108.mp4
  16. allgandalf commented on Jun 2, 2026

    @allgandalf
    Contributor

    Backend PR was merged, awaiting deploy

  17. added
    ReviewingHas a PR in review
    and removed on Jun 2, 2026
  18. allgandalf commented on Jun 4, 2026

    @allgandalf
    Contributor
  19. allgandalf commented on Jun 4, 2026

    @allgandalf
    Contributor
  20. IuliiaHerets commented on Jun 4, 2026

    @IuliiaHerets

    Not repro on iPhone 12/iOS 26.5/Build v9.3.98-1

    90d4fe85-6d4f-4538-a2b6-1a6b37045f96.mp4
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.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions