[$175] [Exploratory] w44-Secondary email-Both emails become workspace members when changing default one
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: v9.5.26-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/81501458/folder/52723565/49419429/1929776044 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Desktop / Windows 11 App Component: User Settings
Action Performed:
Preconditions:
- User A has two contact methods (emails) in the account profile settings.
- User B is any existing user.
- Open the Expensify Web App and log in as User A from the Precondition
- Create a workspace
- Go to Workspace / Members and invite User B to the workspace
- Go to Account / Profile / Contact methods and set the secondary contact method as the default one
- Go to Workspace / Members again and observe the members list
Expected Result:
Nothing should change. The workspace should have two people (Owner and Member).
Actual Result:
The previous default email appears in the members list as the Owner. The new default email (previously secondary) appears in the members list as the Workspace Admin. User B still appears as the Member.
The workspace now has three people.
Workaround:
Unknown
Platforms:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [ ] MacOS: Chrome Safari
Screenshots/Videos
https://github.com/user-attachments/assets/56ced547-4209-4b08-b7af-352e14731c8c
Applause Internal Information Exported by: Chandana Kiran Bug ID: 7300888
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022117413290377373797
- Upwork Job ID: 2117413290377373797
- Last Price Increase: 2026-11-03
While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/e916debb910a8ee4f5de5862c1b45d48ca1e0b28a8ae8ad36a64a7460557dac9
https://platform.applause.com/services/links/v1/external/14c97a8f3791b6f977319f573c260da956e8c2b014dd6ae833635248b65acef0
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105ac9050d5ca10e5
Proposal
What is the root cause of that problem?
In src/libs/actions/User.ts:1120-1175 (setContactMethodAsDefault), setting a secondary contact method as default was refactored to Pattern C (deferring local state mutations to successData). However, successData only updates ACCOUNT.primaryLogin, SESSION.email, LOGINS, and PERSONAL_DETAILS_LIST:
https://github.com/Expensify/App/blob/main/src/libs/actions/User.ts#L1126-L1160
It omits the workspace policy migration that was originally added in PR #45234 (fixing #44705). Specifically:
policy.employeeList[oldDefaultContactMethod]is never removed or set tonullin Onyx.policy.owneris never updated tonewDefaultContactMethod.
When the user subsequently navigates to Workspace / Members, openWorkspaceMembersPage fetches the member list and merges the new default email into policy.employeeList. Because Onyx merges the dictionary keys without removing the old key:
policy.employeeListretains botholdDefaultContactMethodandnewDefaultContactMethod.- In
src/pages/workspace/WorkspaceMembersPage.tsx:431,const role = policy?.owner === details.login ? ownerDisplayRole : employeeRole. Becausepolicy.ownerstill holds the old email, the old email is rendered with the Owner badge (with fallback personal details generated byuseWorkspaceMembers). - The new default email matches the user's active personal details and renders with role
admin(Workspace Admin). - This results in two separate member rows for the same user.
What changes do you think we should make in order to solve the problem?
-
In
src/libs/actions/User.ts:- Connect or pass
allPolicies(Onyx.connect({key: ONYXKEYS.COLLECTION.POLICY, ...})or retrieve policies from Onyx). - When building
successDatainsetContactMethodAsDefault: Iterate over policies where the user is a member or owner, and append policy updates tosuccessData:- In
employeeList, set[oldDefaultContactMethod]: nulland[newDefaultContactMethod]: currentEmployee(preserving the member's current role and permissions). - If
policy.ownerAccountID === currentUserPersonalDetails.accountID(orpolicy.owner === oldDefaultContactMethod), updateowner: newDefaultContactMethod.
- In
- Also append the inverse to
failureDataif the call fails to ensure rollback consistency.
- Connect or pass
-
In
tests/unit/UserTest.ts:- Add a unit test verifying that when
setContactMethodAsDefaultsucceeds,policy.employeeListremoves the old default contact method (null), adds the new contact method, and updatespolicy.ownerto the new email.
- Add a unit test verifying that when
What alternative solutions did you explore? (Optional)
- Deduplicating members strictly in the UI layer inside
useWorkspaceMembers.tsby grouping onaccountID: rejected because the underlying Onyx store remains out-of-sync with stale member keys, which would cause errors in downstream member management actions (e.g. removing members, role changes, or approvals). Fixing it insuccessDatakeeps Onyx consistent across the entire application.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
What is the root cause of that problem?
setContactMethodAsDefault no longer renames the user's entry in each workspace's employeeList. It also no longer updates policy.owner. After a successful call, it only updates account, session, logins, and personal details (User.ts:1124-1156).
This is a regression of [HOLD for payment 2024-07-24] [$250] Workspace member - Hidden admin appears in the members list after changing contact method. Fix hidden member appears in the WS members after changing default contact method fixed it by moving each policy from employeeList[old] to employeeList[new] and setting owner to the new email. Add magic code verification when setting default contact method moved the function to "Pattern C", where data changes wait for the server to confirm success. It deleted the policy loop instead of moving it into successData.
The members page then shows two rows for the same person:
- Old email: the key is still in
employeeList, but no personal details match it anymore.useWorkspaceMembers.ts:31-57builds a fallback row for it.policy.ownerstill holds the old email, soWorkspaceMembersPage.tsx:432labels this row Owner. - New email: the server returns this key. It matches the real personal details but not
policy.owner, so the row shows the user's actual role, Workspace Admin.
Before Show workspace members with missing personal details instead of dropping them, the page silently dropped the stale row. Since that PR, the row is visible.
What changes do you think we should make in order to solve the problem?
- In
setContactMethodAsDefault, accept apoliciesparameter. Include onlyid,ownerAccountID, andemployeeList. - For each policy, add a
MERGEtosuccessData:- If
employeeList[oldLogin]exists, setemployeeList: {[oldLogin]: null, [newLogin]: <old entry>}. - If
ownerAccountIDequals the current user's accountID, setowner: newLogin.
- If
- In
SetDefaultContactMethodConfirmValidateCodePage.tsx, read the policies withuseOnyxand a narrow selector. Pass them to the action at line 77. - Add a
UserTestcase that checks the old key is removed, the new key is added, andowneris updated after success.
Because of Pattern C, failureData needs no policy rollback.
What alternative solutions did you explore? (Optional)
- Compare owner by accountID: at
WorkspaceMembersPage.tsx:432, checkaccountID === policy.ownerAccountIDinstead of comparing emails. This is useful extra hardening. On its own it won't fix the bug, because the staleemployeeListkey would still render a second row. - Remove duplicates in the UI by accountID: rejected, because Onyx would still hold a stale member key that other member actions read.
Investigation notes
- Add magic code verification when setting default contact method (merged 2026-04-30) removed the
policies: OnyxCollection<Policy>parameter and thefor (const policy of Object.values(policies))loop that updatedemployeeListandowner. Nothing replaced it insuccessData. openWorkspaceMembersPage(Member.ts:1346-1358) has no client-side Onyx data, so the server response decides what happens toemployeeList. The page buildsclientMemberEmailswithgetMemberAccountIDsForWorkspace(members.ts:147-175), which skips emails with no personal details. So the client never reports the stale email to the server, and the server never clears it.- Not verified: whether the backend ever sends
employeeList[old]: nullor a newownerafterSetContactMethodAsDefault. The front-end fix above makes the client correct either way. - The earlier contributor proposal from
edotwedoreaches the same root cause and fix.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105532) 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 - @ZhenjaHorbach (External)
Job added to Upwork: https://www.upwork.com/jobs/~022117413290377373797
@MelvinBot Create a PR with your proposal
🤖 Web test steps verification results: ❌ fail
Blocked on dev NewDot web: the handed-over session rendered a blank page. The fix could not be verified; no reload, reauthentication, or magic-code bypass was attempted.
| Step | Status |
|---|---|
Open Expensify signed inInitial and follow-up snapshots returned no nodes; waiting for Inbox timed out.![]() |
❌ |
Create a workspaceNot reached because the application remained blank. |
⚠️ |
Invite an existing user and confirm Owner + MemberNot reached because the application remained blank. |
⚠️ |
Make the secondary contact email defaultNot reached; the two-email prerequisite could not be confirmed. |
⚠️ |
Verify exactly two workspace members, new email as Owner, and old email absentNot reached because the application remained blank. |
⚠️ |
Created draft PR: Prevent duplicate workspace members after changing the default email, assigned to ZhenjaHorbach, with PullerBear review requested.
Implemented the approved proposal and added regression coverage. All 37,138 Jest tests passed, alongside lint, typechecking and Storybook smoke testing. Remaining check limitations are documented in the PR.
Please complete human testing before marking it ready for review, or ask me to mark it ready once testing is complete.
view run · no recording available
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user who owns or belongs to a workspace adds a secondary email, sets that secondary email as their default contact method, and then checks the workspace Members page, both the old default email and the new default email appear as separate members in the workspace members list.
What is the root cause of that problem?
In src/libs/actions/User.ts (lines 1120–1160, setContactMethodAsDefault), when refactoring setContactMethodAsDefault to defer state updates to successData, the workspace policy.employeeList and policy.owner migration logic originally added in PR #45234 (for issue #44705) was dropped. Specifically, setContactMethodAsDefault currently updates ONYXKEYS.ACCOUNT, ONYXKEYS.SESSION, ONYXKEYS.LOGIN_LIST, and ONYXKEYS.PERSONAL_DETAILS_LIST, but never removes policy.employeeList[oldDefaultContactMethod] or moves that employee entry to policy.employeeList[newDefaultContactMethod] in ONYXKEYS.COLLECTION.POLICY. When the backend adds the new primary login to the policy's employeeList, Onyx merges the new key while retaining the stale oldDefaultContactMethod key in policy.employeeList, causing both emails to render in WorkspaceMembersPage.
What changes do you think we should make in order to solve the problem?
- In
src/libs/actions/User.ts(setContactMethodAsDefault, lines 1120–1175), iterate throughallPolicies(ONYXKEYS.COLLECTION.POLICY) wherepolicy?.employeeList?.[oldDefaultContactMethod]exists orpolicy?.owner === oldDefaultContactMethod. - For each matching policy, add an
Onyx.Method.MERGEentry insuccessData(matching Pattern C used bysetContactMethodAsDefault) that:- Updates
owner: policy.owner === oldDefaultContactMethod ? newDefaultContactMethod : policy.owner, and - Updates
employeeListby setting[newDefaultContactMethod]: {...policy.employeeList[oldDefaultContactMethod], email: newDefaultContactMethod}and[oldDefaultContactMethod]: nullso the stale entry under the old email is deleted from Onyx.
- Updates
- Add a unit test in
tests/actions/UserTest.tsverifying thatsetContactMethodAsDefaultmigratespolicy.employeeListandpolicy.ownerfrom the old default login to the new default login without leaving duplicate member entries.
What alternative solutions did you explore? (Optional)
We considered deduplicating employeeList entries by accountID in WorkspaceMembersPage.tsx, but policy.employeeList is keyed by email across the entire codebase, so cleaning up [oldDefaultContactMethod]: null in setContactMethodAsDefault keeps Onyx state consistent everywhere.
📣 @jeffrey-graham! 📣 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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Not overdue Will check the PR today or tomorrow
@ZhenjaHorbach this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
@ZhenjaHorbach 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
@ZhenjaHorbach Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!