App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-10-14] [$175] Workspace - Rules are not enabled when copying Merchant rule to the Collect workspace

Open applause-bot[bot] opened this issue 2 months ago โ€ข 38 comments

If you havenโ€™t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.4.93-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: https://github.com/Expensify/App/pull/101710 Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 26.5.1 Safari, iPhone 13 iOS 26.6 App Component: Workspace Settings

Action Performed:

Preconditions: User has a Control workspace (Workspace A) with Rules enabled and created merchant rule

  1. Go to https://staging.new.expensify.com
  2. Create a Collect workspace
  3. Navigate to the Workspaces list
  4. Click the โ‹ฎ menu on Workspace A (Control) and select Copy settings
  5. On Select workspaces, select Workspace B (Collect) and click Next.
  6. On Select settings, tick Merchant Rule and click Next.
  7. Click Upgrade.
  8. Click Continue
  9. Click Copy settings
  10. Navigate to the Workspace B

Expected Result:

Rules should be enabled when copying Merchant rule to the Collect workspace

Actual Result:

Rules are not enabled when copying Merchant rule to the Collect workspace

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/39371541-2d83-4f9c-93bc-9f56759776e8

View all open jobs on GitHub

Applause Internal Information Exported by: Julia Ponikarchuk Bug ID: 7268359

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

applause-bot[bot] avatar Sep 24 '26 16:09 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/a2bf935adbdd998b5fbb807e85f16ebc3f22b5dd01639c509f0baabb603b4256

applause-bot[bot] avatar Sep 24 '26 16:09 applause-bot[bot]

You have been assigned to this deploy blocker because you recently merged this PR: https://github.com/Expensify/App/pull/101710

melvin-bot[bot] avatar Sep 24 '26 16:09 melvin-bot[bot]

:wave: 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.

github-actions[bot] avatar Sep 24 '26 16:09 github-actions[bot]

@marcochavezf @JmillsExpensify @daledah you have been assigned to this deploy blocker because you reviewed the offending PR: https://github.com/Expensify/App/pull/101710

melvin-bot[bot] avatar Sep 24 '26 16:09 melvin-bot[bot]

๐Ÿ’ฌ A slack conversation has been started in #expensify-open-source

melvin-bot[bot] avatar Sep 24 '26 16:09 melvin-bot[bot]

๐Ÿ” Investigation Summary

Classification: Frontend bug Causing PR: Fix copy settings from Control to Collect workspace - "Show the Upgrade step when copying rules to a Collect workspace" by @MelvinBot (Medium-High confidence) Related Issues: Auto - Workspace - Unable to "Copy settings" from Control to Collect workspace (the issue #101710 fixed)

Recommendation: ROLL FORWARD

The copy part for Merchant rules (codingRules) copies the merchant rules themselves but never copies/sets areRulesEnabled, so the target lands with the rules data but the Rules feature toggled off. Reverting #101710 would just restore the older, worse "Copy failed" bug (#101456) without fixing the missing flag, so a small roll-forward is the right call.

Assigned: @marcochavezf, @JmillsExpensify, @daledah (approving reviewers of #101710) โ€” already auto-assigned; the PR author is a bot so there is no human author to add. Labels: No changes. DeployBlockerCash is kept (App-side fix). DeployBlocker was not present, so nothing was removed.

๐Ÿ“‹ Detailed Analysis

Evidence

  • The bug is staging-only because #101710 is the only change in Deploy Checklist: New Expensify 2026-09-24 that touches this flow. Before it, selecting Merchant rules with a Collect target skipped the Upgrade step entirely and the copy failed outright โ€” the user never reached a completed copy, so the "Rules stayed off" end state was unreachable. The PR added CONTROL_ONLY_COPY_PARTS = new Set<Part>(['rules', 'codingRules']) and short-circuits getControlOnlySelectedParts, which now routes this case through Upgrade โ†’ Confirm โ†’ a copy that actually succeeds: CopyPolicySettingsUtils.ts#L309-L341.
  • The PR's own test plan only asserted that the Upgrade step is displayed for Merchant rules ("2. Merchant rules behaves the same") โ€” it never verified the post-copy state of Workspace B, which is exactly where this fails.
  • The underlying omission is older than this release (identical on production), but it was unreachable in this flow until #101710 unblocked it, which is why it surfaced now as a staging-only regression.

Verification

Affected files (confirmed against staging code):

Root Cause

Three places each assume someone else turns Rules on, and nobody does:

  1. The codingRules part copies no feature flag. PARTS_TO_POLICY_FIELDS.rules starts with 'areRulesEnabled', but codingRules maps to ['rules'] only โ€” and that single field is explicitly skipped in buildPolicyFieldPatch because the merchant rules are applied through a dedicated patch instead. Net effect: copying Merchant rules writes zero policy-level fields. See CopyPolicySettings.ts#L48-L67 and the skip at L315-L317.
  2. The merchant-rules patch only writes rules.codingRules, leaving areRulesEnabled untouched on the target: CopyPolicySettings.ts#L430-L437.
  3. The Upgrade step doesn't enable the feature either. bulkUpgradeToCorporate flips type to CORPORATE and sets glCodes/eReceipts/receipt thresholds, but never areRulesEnabled: Policy.ts#L6159-L6206 and getCorporateUpgradeOnyxFields.

So Workspace B ends up Control, with the merchant rules stored under policy.rules.codingRules, but areRulesEnabled still false โ€” the Rules feature reads as off and the copied merchant rules are invisible. Copying Rules (rather than Merchant rules) works precisely because that part carries areRulesEnabled across.

Suggested fix (one line, plus coverage): include the feature flag in the codingRules part so it is copied from the source the same way the rules part does it:

codingRules: ['rules', 'areRulesEnabled'],

'rules' stays skipped in buildPolicyFieldPatch, so this only adds areRulesEnabled: sourcePolicy.areRulesEnabled (true for any source that has merchant rules) to the target patch, and it automatically gets the right pending-field handling.

Two things to check alongside the fix:

  • The server-side copy has to persist the same thing for the merchant-rules part, otherwise the server push will flip the toggle back off after the optimistic update.
  • The same gap exists in the duplicate workspace flow, where areRulesEnabled is derived from the rules selection only and ignores the merchant-rules selection: Policy.ts#L3535 vs L3557. Worth fixing in the same PR.

There is also no test coverage for the codingRules part in tests/actions/CopyPolicySettingsTest.ts, which is how this slipped through โ€” the fix should add one asserting the target ends up with areRulesEnabled: true.

MelvinBot avatar Sep 24 '26 16:09 MelvinBot

checking now

daledah avatar Sep 25 '26 04:09 daledah

commented on Slack channel

daledah avatar Sep 25 '26 05:09 daledah

It needs a BE fix, https://expensify.slack.com/archives/C01GTK53T8Q/p1790317995109609?thread_ts=1790267834.535419&cid=C01GTK53T8Q

The Merchant rules part of CopyPolicySettings only writes rules.codingRules (plus approvalRules and expenseRules) and never sets areRulesEnabled.

lakchote avatar Sep 25 '26 06:09 lakchote

@marcochavezf, please let me know once the BE fix is done, as we still need an FE fix for the offline case.

daledah avatar Sep 28 '26 04:09 daledah

The BE PR has been merged, but hasn't been deployed yet

marcochavezf avatar Sep 28 '26 14:09 marcochavezf

@marcochavezf, has the BE PR been deployed?

daledah avatar Oct 02 '26 05:10 daledah

Hi @daledah, yup it's now deployed

marcochavezf avatar Oct 02 '26 14:10 marcochavezf

@MelvinBot the BE fix is deployed. Could you open a PR to fix the offline case?

daledah avatar Oct 05 '26 10:10 daledah

๐Ÿค– Draft PR created: Enable Rules optimistically when copying merchant rules Please mark it as "Ready for review" when it is ready for review.

When you copy Merchant rules, the optimistic update now sets areRulesEnabled: true on each target workspace, so Rules shows as on while offline. See CopyPolicySettings.ts:407-411. If the request fails, the original toggle comes back.

The 2 new unit tests pass, along with typecheck, lint, and spell check. I didn't run a manual offline test in the browser, so the Tests and QA sections are still for you to fill in.

MelvinBot avatar Oct 05 '26 10:10 MelvinBot

@marcochavezf This PR is ready for review. Since I don't have permission to mark it as ready (and MelvinBot wasn't able to do it either). Could you mark it as ready and take a look? TIA!

daledah avatar Oct 06 '26 08:10 daledah

Job added to Upwork: https://www.upwork.com/jobs/~022107388253441828896

melvin-bot[bot] avatar Oct 06 '26 08:10 melvin-bot[bot]

What is the root cause of that problem?

Copy settings builds the target workspace's optimistic data in buildCopyPolicySettingsData() in src/libs/actions/Policy/CopyPolicySettings.ts. For each part you select, it looks up the workspace fields that part owns in PARTS_TO_POLICY_FIELDS. It then copies those fields from the source workspace and marks them as pending.

Merchant rules are stored in a separate Onyx collection, not on the workspace. So in that map the Merchant rule part (codingRules) owns no workspace fields:

https://github.com/Expensify/App/blob/main/src/libs/actions/Policy/CopyPolicySettings.ts#L68-L70

When only Merchant rule is selected:

  • The rules themselves are copied to the target workspace.
  • Nothing on the target workspace changes, so its Rules toggle (areRulesEnabled) keeps its old value, which is off for a new Collect workspace.

Merchant rules are only shown when Rules is on, so the copied rules end up hidden. The backend had the same gap and has been fixed. The frontend optimistic data still has it, so the bug still shows offline and until the server update arrives.

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

All changes go in buildCopyPolicySettingsData(), using the existing check for whether Merchant rule is selected. They follow the pattern already used for the other separately handled parts (Time tracking and Receipt partners).

  1. Turn Rules on in the optimistic update. When Merchant rule is selected, set areRulesEnabled to true on each target workspace. Always use true instead of copying the source workspace's value, because merchant rules are only visible while Rules is on. This matches what the backend now does.
  2. Apply it after the normal field copy. If the user selects both "Rules" and "Merchant rule" and the source workspace has Rules off, the "Rules" part would copy "off" to the target. Applying the Merchant rule change last keeps Rules on.
  3. Mark the toggle as pending. Add areRulesEnabled to the target workspace's pending fields, so the Rules toggle shows the pending (greyed out) state while offline.
  4. Clear the pending state on success. Add areRulesEnabled to the pending fields that the success update clears.
  5. Failure needs no change. The existing failure update already puts back the original target workspace, so Rules returns to its old value. The copied rules are already removed on failure.
  6. Unit tests in tests/actions/CopyPolicySettingsTest.ts:
    • Copying only Merchant rule to a workspace with Rules off turns Rules on and marks it pending. Success clears the pending state and failure turns Rules back off.
    • Copying Rules and Merchant rule together from a source workspace with Rules off still leaves Rules on for the target.
    • Copying other parts (for example, Categories) doesn't change the Rules toggle.

voxturrlabs avatar Oct 06 '26 12:10 voxturrlabs

๐Ÿ“ฃ @voxturrlabs! ๐Ÿ“ฃ Hey, it seems we donโ€™t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Oct 06 '26 12:10 melvin-bot[bot]

Proposal for #102210

Problem: When copying a Merchant rule to the Collect workspace, the enabled state is not preserved, so rules appear disabled in the destination workspace.

Root Cause: In the rule copy/duplication flow (src/pages/workspace/rules/ and MerchantRule actions), the payload copies merchant, field, category etc but does not copy isEnabled / pendingAction for rules. When createPolicyRule is called for the target workspace, it defaults to disabled.

Solution:

  1. In the copy function (likely copyRules / importMerchantRules), include enabled: true if source rule is enabled, or copy rule.isEnabled flag
  2. Ensure POLICY.RULES Onyx merge preserves enabled
  3. Update MerchantRule model to keep enabled state during copyToWorkspace

Test plan:

  • Create 2 workspaces, create Merchant rule in workspace A, enable it
  • Use Copy rule to Collect workspace
  • Verify rule in Collect workspace is enabled
  • Test on Web, mWeb, Android, iOS

Regression: No impact on other rule types. Only changes copy flow.

Contributor checklist: I have access, can test on all platforms, will follow CONTRIBUTING.md

quantumchain-core avatar Oct 06 '26 15:10 quantumchain-core