You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add merchant rule - Merchant rule not applied after member creating expense #82890
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+piyomn@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:
Prepare two accounts (Admin and Member that you have access to the email)
As Admin create a workspace with:
At least 3-4 categories enabled (e.g., "Meals & Entertainment", "Travel", "Software", "Advertising")
At least 2-3 tags enabled (e.g., "Client A", "Internal", "Project X")
Reimbursable and billable settings available
Enable rules in more feature
Steps:
(Admin) navigate to workspace -> rules -> add merchant rule
Create a comprehensive rule:
Merchant: "TestCorp"
Match type: Contains
Category: "Software"
Tag: "Project X"
Reimbursable: No
Billable: Yes
Description: "TestCorp subscription"
Rename merchant to: "TestCorp Inc."
Preview matches to verify expected expenses
(Member) create a new expense with merchant: "TestCorp Services"
(Admin) Navigate back to the rules page and refresh the page
Expected Result:
in step 3, As member, after creating the new expense, all field of merchant rule that already configured before should be applied correctly
in step 4, As admin, after refreshing the rules page, the configured merchant rules should be remains listed
Actual Result:
in step 3, as member, after creating the new expense, all field of merchant rule that already configured before is not applied
in step 4, as admin, after refreshing the rules page, the configured merchant rules disappear
👋 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:
Identify the pull request that introduced this issue and revert it.
PR #82438 should be reverted immediately. This PR simply removed the production gate for merchant rules, but the underlying feature has unresolved bugs that prevent it from working correctly.
Labels: Keeping DeployBlockerCash (this blocks the App deploy). The DeployBlocker label is not present on this issue.
Detailed Analysis
Evidence
This is a case of an existing bug being exposed by enabling a feature, rather than a new bug being introduced:
First Enable Attempt: PR Enable merchant rules #81033 enabled merchant rules on Feb 10, 2026 by removing the same production gate
Issues Discovered: Multiple bugs were found including:
Second Enable Attempt: PR Enable merchant rules v2 #82438 enables merchant rules again on Feb 18, 2026 with identical code change (just removing production gate)
Confirmed that PR #82438 only modifies src/pages/workspace/rules/MerchantRulesSection.tsx:
Removes useEnvironment hook import
Removes the if (isProduction) return null; gate
No other logic changes
The file shows merchant rules are stored in policy?.rules?.codingRules and managed through src/libs/actions/Policy/Rules.ts, but the underlying functionality for applying rules to new expenses and persisting them correctly was never fixed between the revert and re-enable.
Root Cause
The merchant rules feature has fundamental bugs in how rules are:
Applied to newly created expenses (particularly for workspace members)
Persisted and retrieved from the backend/Onyx store
PR #82438 only removed the visibility gate without addressing these core issues. The feature should not have been re-enabled without fixing the underlying problems that caused the first revert.
Please re-state the problem that we are trying to solve in this issue.
Two problems are reported after enabling merchant rules (PR #82438):
Rules not applied to new expenses: When a member creates an expense with a merchant matching a configured rule (e.g., "TestCorp Services" should match "TestCorp" with "Contains" match type), the rule's configured fields (category, tag, reimbursable, billable, description) are NOT applied to the expense.
Rules disappear on refresh: When the admin navigates back to the rules page and refreshes, the configured merchant rules vanish.
What is the root cause of that problem?
Both symptoms point to an incomplete backend implementation for the codingRules feature. Specifically:
Symptom 1 (Rules not applied): There is no client-side logic in the App that applies codingRules to new expenses. The expense creation flow (RequestMoney/TrackExpense in src/libs/actions/IOU/) has zero references to codingRules. The merchant name is sent to the server in the API params, and the server is expected to match it against the policy's coding rules and apply the configured fields to the transaction — but this server-side matching logic either doesn't exist yet or has a bug.
Evidence: Grep for codingRule across src/libs/actions/IOU/ returns no matches. IOURequestStepMerchant.tsx simply stores the merchant string via setMoneyRequestMerchant() with no rule-matching logic. The shouldUpdateMatchingTransactions flag (sent at rule-save time) is the only mechanism that triggers server-side rule application, and it only applies to existing transactions, not newly created ones.
Symptom 2 (Rules vanish on refresh): The openPolicyRulesPage function (src/libs/actions/Policy/Rules.ts:105-113) sends a READ_COMMANDS.OPEN_POLICY_RULES_PAGE request with no client-side onyxData — the backend entirely controls what data is returned. If the OpenPolicyRulesPage backend handler doesn't include codingRules in its response, they won't appear after refresh. Additionally, AccessOrNotFoundWrapper calls openWorkspace() when the policy is empty, and if that response uses Onyx.METHOD.SET (full replace) without codingRules, any previously stored rules would be wiped.
Evidence: The frontend write path (setPolicyCodingRule at src/libs/actions/Policy/Rules.ts:170-183) correctly stores rules at policy.rules.codingRules[ruleID] via Onyx.METHOD.MERGE, and the read path (MerchantRulesSection.tsx:85) reads from policy?.rules?.codingRules — the key structure is consistent. The successData pattern at Rules.ts:184-199 only clears pendingAction/errors, leaving the optimistic rule data intact. The frontend code is structurally sound and follows the same pattern used successfully by approvalRules and expenseRules.
What changes do you think we should make in order to solve the problem?
Since the root cause is server-side, the fix needs to be in the backend (Auth/Web-Expensify repos):
For rules disappearing on refresh: Ensure the OpenPolicyRulesPage backend handler returns codingRules as part of the policy.rules object in its onyxData response. Verify that SetPolicyCodingRule backend handler actually persists the rule to the database. Also verify that OpenWorkspace/OpenApp responses either use merge instead of set for the policy key, or include codingRules in the response.
For rules not applying to new expenses: Implement server-side logic in the RequestMoney/TrackExpense command handlers to match the expense merchant against the policy's codingRules (using the filter criteria: operator = eq for exact match or contains for partial match against the right field) and apply the rule's fields (category, tag, tax, comment, reimbursable, billable, merchant rename) to the transaction.
What alternative solutions did you explore? (Optional)
Client-side rule application: We could add logic to the App to match merchant names against codingRules and pre-fill expense fields client-side. However, this would be redundant with server-side application (which is needed anyway for the shouldUpdateMatchingTransactions feature that already exists), could lead to data inconsistencies, and wouldn't work for expenses submitted via API or other clients. Server-side is the correct approach, consistent with how the older personal expenseRules (NVP_EXPENSE_RULES) are handled.
I'm unable to reproduce this issue. The fact that the rule disappears means that it wasn't created and explains why it wasn't applied. That being said, I couldn't find logs for the account mentioned in the OP creating the rule.
@jponikarchuk can you please check if you can still reproduce the OP and if so, share the email of the account trying to create the rule?
Activity
melvin-bot commentedon Feb 19, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #82438
melvin-bot commentedon Feb 19, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Feb 19, 2026
Triggered auto assignment to @laurenreidexpensify (
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.github-actions commentedon Feb 19, 2026
👋 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:
OSBotify commentedon Feb 19, 2026
Investigation Summary
Classification: Frontend bug
Causing PR: #82438 - "Enable merchant rules v2" by @luacmartins (High confidence)
Related Issues: #82241, #82228, #82245, #82225 (from previous enable attempt)
Recommendation: REVERT
PR #82438 should be reverted immediately. This PR simply removed the production gate for merchant rules, but the underlying feature has unresolved bugs that prevent it from working correctly.
Labels: Keeping
DeployBlockerCash(this blocks the App deploy). TheDeployBlockerlabel is not present on this issue.Detailed Analysis
Evidence
This is a case of an existing bug being exposed by enabling a feature, rather than a new bug being introduced:
Verification
Confirmed that PR #82438 only modifies
src/pages/workspace/rules/MerchantRulesSection.tsx:useEnvironmenthook importif (isProduction) return null;gateThe file shows merchant rules are stored in
policy?.rules?.codingRulesand managed throughsrc/libs/actions/Policy/Rules.ts, but the underlying functionality for applying rules to new expenses and persisting them correctly was never fixed between the revert and re-enable.Root Cause
The merchant rules feature has fundamental bugs in how rules are:
PR #82438 only removed the visibility gate without addressing these core issues. The feature should not have been re-enabled without fixing the underlying problems that caused the first revert.
MelvinBot commentedon Feb 19, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
Two problems are reported after enabling merchant rules (PR #82438):
What is the root cause of that problem?
Both symptoms point to an incomplete backend implementation for the
codingRulesfeature. Specifically:Symptom 1 (Rules not applied): There is no client-side logic in the App that applies
codingRulesto new expenses. The expense creation flow (RequestMoney/TrackExpenseinsrc/libs/actions/IOU/) has zero references tocodingRules. The merchant name is sent to the server in the API params, and the server is expected to match it against the policy's coding rules and apply the configured fields to the transaction — but this server-side matching logic either doesn't exist yet or has a bug.codingRuleacrosssrc/libs/actions/IOU/returns no matches.IOURequestStepMerchant.tsxsimply stores the merchant string viasetMoneyRequestMerchant()with no rule-matching logic. TheshouldUpdateMatchingTransactionsflag (sent at rule-save time) is the only mechanism that triggers server-side rule application, and it only applies to existing transactions, not newly created ones.Symptom 2 (Rules vanish on refresh): The
openPolicyRulesPagefunction (src/libs/actions/Policy/Rules.ts:105-113) sends aREAD_COMMANDS.OPEN_POLICY_RULES_PAGErequest with no client-side onyxData — the backend entirely controls what data is returned. If theOpenPolicyRulesPagebackend handler doesn't includecodingRulesin its response, they won't appear after refresh. Additionally,AccessOrNotFoundWrappercallsopenWorkspace()when the policy is empty, and if that response usesOnyx.METHOD.SET(full replace) withoutcodingRules, any previously stored rules would be wiped.setPolicyCodingRuleatsrc/libs/actions/Policy/Rules.ts:170-183) correctly stores rules atpolicy.rules.codingRules[ruleID]viaOnyx.METHOD.MERGE, and the read path (MerchantRulesSection.tsx:85) reads frompolicy?.rules?.codingRules— the key structure is consistent. ThesuccessDatapattern atRules.ts:184-199only clearspendingAction/errors, leaving the optimistic rule data intact. The frontend code is structurally sound and follows the same pattern used successfully byapprovalRulesandexpenseRules.What changes do you think we should make in order to solve the problem?
Since the root cause is server-side, the fix needs to be in the backend (Auth/Web-Expensify repos):
For rules disappearing on refresh: Ensure the
OpenPolicyRulesPagebackend handler returnscodingRulesas part of thepolicy.rulesobject in itsonyxDataresponse. Verify thatSetPolicyCodingRulebackend handler actually persists the rule to the database. Also verify thatOpenWorkspace/OpenAppresponses either usemergeinstead ofsetfor the policy key, or includecodingRulesin the response.For rules not applying to new expenses: Implement server-side logic in the
RequestMoney/TrackExpensecommand handlers to match the expense merchant against the policy'scodingRules(using the filter criteria:operator=eqfor exact match orcontainsfor partial match against therightfield) and apply the rule's fields (category, tag, tax, comment, reimbursable, billable, merchant rename) to the transaction.What alternative solutions did you explore? (Optional)
shouldUpdateMatchingTransactionsfeature that already exists), could lead to data inconsistencies, and wouldn't work for expenses submitted via API or other clients. Server-side is the correct approach, consistent with how the older personalexpenseRules(NVP_EXPENSE_RULES) are handled.Detailed Investigation
Evidence Chain
Frontend write path (confirmed correct):
MerchantRulePageBase.tsx:208→ callssetPolicyCodingRule(policyID, form, policy, ruleID, shouldUpdateMatchingTransactions)Rules.ts:123-226→ buildsruleForOnyx(with nulls for cleared fields) andruleForAPI(without nulls), writes optimistic data topolicy.rules.codingRules[ruleID], callsAPI.write(WRITE_COMMANDS.SET_POLICY_CODING_RULE, {policyID, codingRuleID, codingRuleValue: JSON.stringify(ruleForAPI), shouldUpdateMatchingTransactions})types.ts:265→ command maps to'SetPolicyCodingRule'Frontend read path (confirmed correct):
PolicyRulesPage.tsx:26-32→ callsopenPolicyRulesPage(policyID)on mountRules.ts:105-113→ sendsAPI.read(READ_COMMANDS.OPEN_POLICY_RULES_PAGE, {policyID})with no client-side onyxDataMerchantRulesSection.tsx:85→ readspolicy?.rules?.codingRulesKey Onyx pattern:
Onyx.METHOD.MERGEwith rule data +pendingActionflag (Rules.ts:170-182)Onyx.METHOD.MERGEclearing onlypendingActionanderrors(Rules.ts:184-199)Onyx.METHOD.MERGEreverting rule + setting error (Rules.ts:200-216)approvalRules,expenseRules, and other policy settingsExpense creation flow (no codingRule references):
IOURequestStepMerchant.tsx:108-141→ stores merchant viasetMoneyRequestMerchant()(no rule lookup)IOU/index.ts:1438-1440→setMoneyRequestMerchantis a simpleOnyx.mergewith no rule logicRequestMoneyParams.ts→ contains merchant but no codingRuleID or coding rule fieldsRelevant Code
src/libs/actions/Policy/Rules.ts:105-226— Core CRUD logic for coding rulessrc/pages/workspace/rules/MerchantRulesSection.tsx:85-102— UI readspolicy?.rules?.codingRulessrc/pages/workspace/rules/PolicyRulesPage.tsx:26-32— CallsopenPolicyRulesPageon mountsrc/pages/workspace/AccessOrNotFoundWrapper.tsx:160-168— CallsopenWorkspacewhich may overwrite policysrc/types/onyx/Policy.ts:1958-1968— Type definition forrules.codingRulessrc/libs/actions/OnyxUpdates.ts:32-42— Backend response handler (method determined by server)Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.luacmartins commentedon Feb 19, 2026
I'm unable to reproduce this issue. The fact that the rule disappears means that it wasn't created and explains why it wasn't applied. That being said, I couldn't find logs for the account mentioned in the OP creating the rule.
@jponikarchuk can you please check if you can still reproduce the OP and if so, share the email of the account trying to create the rule?
jponikarchuk commentedon Feb 20, 2026
@luacmartins This issue is not reproduced using the latest staging build v9.3.23-3
luacmartins commentedon Feb 20, 2026
Thanks! We can close this