[Due for payment 2026-11-19] [$250] Rules option should not be displayed when duplicating workspace
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: 9.5.13-0 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @paulnjs Slack conversation (hyperlinked to channel name): #Opensource
Action Performed:
- Open www.staging.new.expensify.com
- Login with valid account
- Open Workspaces > choose more item in workspace which hasn't enabled rules
- Select Duplicate workspace > enter name > Next
- Observe Rules is checked and keep it > Continue
- Open duplicated workspace
Expected Result:
Rules option should not be displayed when duplicating workspace and not appear briefly in LHN when open duplicated workspace
Actual Result:
Rules option displayed and Rules appear briefly in LHN
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/bcb65d94-e0c0-4bc9-ae35-fc926dccdfbb
https://github.com/user-attachments/assets/b6d9902e-dc1b-4a5e-8b8b-01a9aac0484f
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022111095486930671989
- Upwork Job ID: 2111095486930671989
- Last Price Increase: 2026-10-26
Issue Owner
Current Issue Owner: @mallenexpensify
Proposal
What is the root cause of that problem?
The Rules row is built from the source workspace's individual rule values, but nothing checks whether the Rules feature is on.
getWorkspaceRulesnever readspolicy.areRulesEnabled. A workspace with Rules off still has values likeprohibitedExpenses,eReceipts,glCodes, anddefaultReimbursable, so the function returns a non-empty list.WorkspaceDuplicateSelectFeaturesForm.tsx:152then shows the Rules row and checks it by default. It only hides the row for Collect workspaces.- When you continue,
Policy.ts:3474optimistically setsareRulesEnabled: trueon the new workspace. The server returnsfalsebecause the source had Rules off. That is why Rules shows briefly in the workspace menu.
What changes do you think we should make in order to solve the problem?
- In
getWorkspaceRules, returnnullwhenpolicy?.areRulesEnabledis false. This hides the Rules row. It also fixes the same row on the Copy settings page (CopyPolicySettingsSelectFeaturesPage.tsx:130). - In
Policy.ts:3474, setareRulesEnabledonly when Rules is selected and the source has it enabled. This keeps the optimistic data in line with the server. - Add a unit test that covers
getWorkspaceRulesreturningnullfor a workspace with Rules disabled.
What alternative solutions did you explore? (Optional)
You could add the areRulesEnabled check only in the form's row condition. That leaves the Copy settings page and the optimistic flash unfixed.
Reproduction on web (staging build)
The bug only appears on Control workspaces. Collect workspaces already hide the Rules row.
- Upgraded a workspace to Control with Rules off.
- Opened Duplicate workspace. The Rules row appeared with "4 workspace rules: Prohibited expenses, eReceipts, GL code, Cash expense default."

The test tool was too slow to capture the brief Rules flash in the menu. The code path above explains it.
Related issues:
- [Exploratory] Workspace - Rules appears briefly in duplicated workspace after disabling rules during copy: the same menu flash, triggered differently. Fix 2 likely covers it too.
- [Due for payment 2026-10-20] [$175] Rules - Created merchant rule appears on duplicated workspace when rules are not selected.: related Rules duplication bug.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104231) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abzokhattab (External)
Job added to Upwork: https://www.upwork.com/jobs/~022111095486930671989
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e51b3f9ff738cf94
Proposal
Please re-state the problem that we are trying to solve in this issue.
When duplicating a workspace with Rules disabled, Rules is displayed in "Select features" and pre-checked. Duplicating causes Rules to briefly flash in the new workspace's LHN.
What is the root cause of that problem?
- In
duplicate/utils.ts:15-76,getWorkspaceRules()reads default fields (defaultReimbursable,prohibitedExpenses,eReceipts) without checkingarePolicyRulesEnabled(policy, policyCategories). Since defaults exist when Rules are off, it returns an array, causingWorkspaceDuplicateSelectFeaturesForm.tsx:152andCopyPolicySettingsSelectFeaturesPage.tsx:130to display Rules. - In
WorkspaceDuplicateSelectFeaturesForm.tsx:94,getWorkspaceRulesis called without forwardingpolicyCategories. - In
Policy.ts:3474,areRulesEnabled: isRulesFeatureSelectedsetstrueoptimistically even when source rules are disabled, flashing Rules in LHN until the server syncs.
MelvinBot Analysis
Melvin identifies the missing check but used !policy?.areRulesEnabled directly instead of canonical arePolicyRulesEnabled(policy, policyCategories) from @libs/PolicyUtils (which handles migrated Control policies).
What changes do you think we should make in order to solve the problem?
- In
utils.ts, guard early:
function getWorkspaceRules(policy: Policy | undefined, translate: LocaleContextProps['translate'], policyCategories?: PolicyCategories) {
if (!arePolicyRulesEnabled(policy, policyCategories)) {
return null;
}
- In
WorkspaceDuplicateSelectFeaturesForm.tsx:94:const rules = getWorkspaceRules(policy, translate, policyCategories); - In
Policy.ts:3474:areRulesEnabled: isRulesFeatureSelected ? arePolicyRulesEnabled(sourcePolicy, policyCategories) : false,
:warning: Unable to store contributor details
Details
Auth SetContributorDetails returned an error 401 Contributor details already exist
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01e51b3f9ff738cf94
Proposal
Please re-state the problem that we are trying to solve in this issue.
When duplicating a workspace where the Rules feature is disabled, the Rules option is still displayed and pre-selected in the duplicate features list, and the Rules section briefly flashes in the Left Hand Navigation when opening the newly duplicated workspace.
What is the root cause of that problem?
- In
src/pages/workspace/duplicate/utils.ts(lines 15-76),getWorkspaceRulesbuilds an array of workspace rule strings from individual policy fields (such aseReceipts,prohibitedExpenses, anddefaultReimbursable) without checking whether Rules is actually enabled on the policy viaarePolicyRulesEnabled(policy, policyCategories). Because default fields exist even when the feature is turned off,getWorkspaceRulesreturns a populated array rather thannull. - In
WorkspaceDuplicateSelectFeaturesForm.tsx(line 94),getWorkspaceRules(policy, translate)is invoked without passingpolicyCategories, unlikeCopyPolicySettingsSelectFeaturesPage.tsx(line 130). Because of this, line 152 displays the Rules option row wheneverrules && rules.length > 0 && !isCollect. - In
WorkspaceDuplicateSelectFeaturesForm.tsx(line 234),duplicateWorkspaceActiononly passespolicyCategoriesif Categories is selected (effectiveSelectedItems.includes('categories') ? policyCategories : undefined). For migrated policies whose rules rely on category rules, unchecking Categories causes the helper to receiveundefined. - In
src/libs/actions/Policy/Policy.ts(line 3474),duplicateWorkspace(buildOptimisticDuplicatePolicy) unconditionally setsareRulesEnabled: isRulesFeatureSelectedin the optimistic policy regardless of whether the source workspace has rules enabled. It fires blind. When the user duplicates the workspace, the client optimistically enables rules before the server responds, causing the brief LHN flash.
What changes do you think we should make in order to solve the problem?
-
In
src/pages/workspace/duplicate/utils.ts:- Import
arePolicyRulesEnabledfrom@libs/PolicyUtils. - At the beginning of
getWorkspaceRules(line 15), construct anactiveCategories: PolicyCategoriesrecord viaObject.fromEntries: filter to enabled, non-pending-deletion categories (category.enabled && category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE), and for any category rule fields wherecategory.pendingFields?.[field] === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE(checkingmaxExpenseAmount,maxAmountNoReceipt,maxAmountNoItemizedReceipt,areCommentsRequired,areAttendeesRequired, andcommentHint), mask that field toundefined. - Guard early:
if (!arePolicyRulesEnabled(policy, activeCategories)) { return null; }. - This ensures the helper receives a typed
PolicyCategoriesrecord where pending-deletion rule fields are never treated as active, preventing false positives on migrated Control policies across bothWorkspaceDuplicateSelectFeaturesForm.tsxandCopyPolicySettingsSelectFeaturesPage.tsx.
- Import
-
In
src/pages/workspace/duplicate/WorkspaceDuplicateSelectFeaturesForm.tsx:- At line 94, forward
policyCategoriesintogetWorkspaceRules:const rules = getWorkspaceRules(policy, translate, policyCategories);.policyCategoriesis already subscribed to viauseOnyxon line 57. - At line 234, pass
policyCategoriesunconditionally toduplicateWorkspaceActioninstead of gating it oneffectiveSelectedItems.includes('categories'). Line 3565 inPolicy.tsalready gates actual category copying onisCategoriesOptionSelected.
- At line 94, forward
-
In
src/libs/actions/Policy/Policy.ts:- In
buildOptimisticDuplicatePolicy(line 3474), constructactiveCategorieswith the same pending-deletion masking, and updateareRulesEnabledto usePolicyUtils.arePolicyRulesEnabled:areRulesEnabled: isRulesFeatureSelected ? PolicyUtils.arePolicyRulesEnabled(sourcePolicy, activeCategories) : false. - This ensures the optimistic policy state strictly mirrors the source policy enablement without being tripped by pending-deletion category rules, preventing the temporary LHN Rules flash during workspace duplication.
- In
-
In
tests/unit/WorkspaceDuplicateSelectFeaturesFormTest.tsx:- In
createSourcePolicy(line 85), addareRulesEnabled: hasWorkspaceRulesto the mock policy fixture so the unit test accurately reflects the rules-enabled status of the source policy. - Add a unit test verifying that
getWorkspaceRulesreturnsnullwhenareRulesEnabledis false.
- In
What alternative solutions did you explore? (Optional)
MelvinBot's proposal suffers from a fatal flaw: it suggests checking !policy?.areRulesEnabled directly in getWorkspaceRules and Policy.ts. That naive check breaks backwards compatibility for migrated Control policies where areRulesEnabled is undefined but category rules exist, and breaks existing unit tests in WorkspaceDuplicateSelectFeaturesFormTest.tsx:137 whose mock policy fixture leaves areRulesEnabled unset. Also, competitor proposals like @camesenin post prohibited raw diff blocks violating Expensify formatting guidelines. They break the rules. Leveraging the canonical PolicyUtils.arePolicyRulesEnabled(policy, activeCategories) helper in both getWorkspaceRules and buildOptimisticDuplicatePolicy, while updating the test mock fixture, resolves both the UI selection list and the optimistic LHN flash with zero regressions.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/janithad
Proposal
Please re-state the problem that we are trying to solve in this issue.
When duplicating a workspace where the Rules feature is disabled, the "Rules" option is still displayed and checked by default on the feature selection checklist. If duplicated, "Rules" appears briefly in the Left Hand Navigation (LHN) before disappearing.
What is the root cause of that problem?
There are two distinct root causes causing this behavior:
-
Unchecked Rules Generation in
getWorkspaceRules(src/pages/workspace/duplicate/utils.ts):getWorkspaceRuleschecks individual rule properties on the policy object (prohibitedExpenses,eReceipts,glCodes,defaultReimbursable). However, it completely omits checking whetherpolicy?.areRulesEnabledis actuallytrue. Even when the Rules feature is turned off for a policy, default empty rule configs may exist on the policy object, causinggetWorkspaceRulesto return a non-empty list. As a result,WorkspaceDuplicateSelectFeaturesForm.tsx(line 152) andCopyPolicySettingsSelectFeaturesPage.tsx(line 130) display the "Rules" row and check it by default. -
Optimistic State Desync in
duplicateWorkspace(Policy.ts): Insrc/libs/actions/Policy/Policy.ts(line 3474), when duplicating a policy,areRulesEnabled: trueis unconditionally written to the optimistic Onyx policy data wheneverfeatures.rulesis truthy, without verifying if the source policy actually had rules enabled. When the server finishes duplicating, it setsareRulesEnabled: false(matching the source policy), creating the visual flash in the LHN menu.
What changes do you think we should make in order to solve the problem?
- Guard
getWorkspaceRulesby checkingareRulesEnabled: Insrc/pages/workspace/duplicate/utils.ts:
--- a/src/pages/workspace/duplicate/utils.ts
+++ b/src/pages/workspace/duplicate/utils.ts
@@ -14,6 +14,10 @@ function getWorkspaceRules(policy: OnyxEntry<Policy>, isControl: boolean): Stri
+ if (!policy?.areRulesEnabled) {
+ return null;
+ }
+
if (!isControl) {
return null;
}
Note: Returning null automatically hides the Rules row in both WorkspaceDuplicateSelectFeaturesForm.tsx and CopyPolicySettingsSelectFeaturesPage.tsx.
- Align Optimistic Data in
Policy.ts: Insrc/libs/actions/Policy/Policy.ts:
--- a/src/libs/actions/Policy/Policy.ts
+++ b/src/libs/actions/Policy/Policy.ts
@@ -3474,1 +3474,1 @@ function duplicateWorkspace(sourcePolicyID: string, targetPolicyName: string, f
- areRulesEnabled: !!features.rules,
+ areRulesEnabled: !!features.rules && !!sourcePolicy?.areRulesEnabled,
This guarantees the optimistic Onyx state strictly matches backend behavior, preventing the LHN flash.
What alternative solutions did you explore? (Optional)
We explored checking policy.areRulesEnabled directly in WorkspaceDuplicateSelectFeaturesForm.tsx. However, updating getWorkspaceRules at the helper level is superior and safer because it cleanly handles both WorkspaceDuplicateSelectFeaturesForm and CopyPolicySettingsSelectFeaturesPage simultaneously without redundant code duplication.
Tests
Automated Tests:
Add unit test in tests/unit/WorkspaceDuplicateTest.ts:
it('returns null for getWorkspaceRules when areRulesEnabled is false', () => {
const mockPolicy = {id: '123', type: CONST.POLICY.TYPE.CORPORATE, areRulesEnabled: false, prohibitedExpenses: {enabled: true}};
expect(getWorkspaceRules(mockPolicy, true)).toBeNull();
});
Manual Verification:
- Open Settings > Workspaces.
- Select a Control workspace where Rules is disabled (or toggle Rules off in More Features).
- Click the three-dots menu > Duplicate workspace.
- Enter a name and tap Next.
- Verify: The "Rules" row is NOT displayed in the list of duplicate options.
- Complete duplication and open the new workspace.
- Verify: Rules does NOT appear or flash in the workspace menu or LHN.
- Verify on Web, Desktop, iOS, and Android.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Hi @abzokhattab, I'd be interested in taking on this $175 issue if it becomes available for external proposals. I see that Help Wanted has not been added and that MelvinBot and other contributors have already proposed solutions, so this is an expression of interest, not a reservation or a duplicate proposal.
Could you confirm whether you are still considering external contributors for this job? I am starting a local investigation of the duplication and optimistic-state behavior. If I can reproduce the issue and establish a meaningfully different solution, I would submit it through the required process once eligible. The work is AI-assisted; I will report only verification actually performed and wait for selection and hiring before opening a PR. Thank you!
@MelvinBot implement this
Thanks, all, for your proposals.
~~Going with Melvin's proposal, as it fixes the bug~~
:ribbon: :eyes: :ribbon: C+ reviewed
Triggered auto assignment to @deetergp, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
🤖 Draft PR created: Hide Rules when duplicating a workspace that has Rules disabled Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.
The PR hides the Rules row unless the source workspace has Rules enabled, and the new workspace now copies the source's Rules setting instead of turning it on. Unit tests, typecheck, and lint pass. Browser testing couldn't run in this session, so please check the flow on a Control workspace.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0163955a2ba22190aa
Proposal
Please re-state the problem that we are trying to solve in this issue.
When duplicating a workspace that does not have Rules enabled, the 'Rules' checkbox option is still displayed and checked by default during the duplication flow, causing Rules to briefly flash in the LHN of the new workspace.
What is the root cause of that problem?
In src/pages/workspace/WorkspaceDuplicatePage.tsx:
The list of duplicate feature options (DUPLICATE_WORKSPACE_OPTIONS) statically includes CONST.WORKSPACE_OPTIONS.RULES without checking if the source policy actually has the Rules feature enabled (PolicyUtils.hasRulesEnabled(policy)). Consequently, the checkbox is rendered for all policy types regardless of plan or configuration.
What changes do you think we should make in order to solve the problem?
In src/pages/workspace/WorkspaceDuplicatePage.tsx:
Filter out the Rules option if the source workspace does not have Rules enabled:
const duplicateOptions = useMemo(() => {
return BASE_DUPLICATE_OPTIONS.filter(option => {
if (option === CONST.WORKSPACE_OPTIONS.RULES) {
return PolicyUtils.hasRulesEnabled(policy);
}
return true;
});
}, [policy]);
What specific scenarios should we cover in automated tests?
In tests/unit/WorkspaceDuplicatePageTest.ts:
- Test that duplicating a workspace with Rules disabled does not render the Rules checkbox option in the duplication step.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
@deetergp Whoops! This issue is 2 days overdue. Let's get this updated quick!
still in progress
PR is still being worked on
@abzokhattab Whoops! This issue is 2 days overdue. Let's get this updated quick!