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
[$250] Copilot - User will force sign out after issue new card using full delegate access #83539
Version Number: v9.3.26-4 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:#81817 Email or phone of affected tester (no customers): N/A Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: Windows 11 / Chrome, Android 13 / Xiaomi Poco F5, iOS 15.8.3 / iPhone 7 Plus App Component: Workspace Settings
Action Performed:
Precondition:
User A, login using Expensifial account, create a workspace, and enable the Expensify Card feature
User A, add user B as a Copilot account with full delegate access (can use a Gmail account)
Login to user B
Navigate to Account and switch as user A
Go to Workspace > Expensify Card
Click the Issue card and follow the issue card flow
In the RHP magic code, enter the magic code that was sent to user A's email
Expected Result:
User does not auto sign out after issue new card using full delegate access
Actual Result:
User will force sign out after issue new card using full delegate access
Note:
Sometimes the user will force sign out after navigating to another section
The new card is successfully added after the user relogin to user B's account
👋 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.
Classification: Frontend bug Causing PR: #81817 - "Allow full Copilot users to access Expensify Card pages" by @MelvinBot (High confidence) Related Issues: #79095
Recommendation: REVERT
The frontend PR was merged without the corresponding backend changes being deployed first. The PR description explicitly states: "The backend change (allowing ROLE_ALL auth token type for CreateAdminIssuedVirtualCard command) is out of scope for this frontend PR and needs to be handled separately."
This means the frontend allows full Copilot users to proceed through the card issuance flow, but when they submit the magic code, the backend rejects the request (likely with a 407 NOT_AUTHENTICATED or similar error), which triggers a sign-out.
Labels: Keeping DeployBlockerCash (blocks App deploy). The DeployBlocker label was not present on this issue.
📋 Detailed Analysis
Evidence
PR #81817 changed the delegate access checks from isActingAsDelegate to isDelegateAccessRestricted for Expensify Card pages. This allows full Copilot users (ROLE_ALL delegates) to access the card issuance flow, but the backend API command CreateAdminIssuedVirtualCard has not been updated to accept ROLE_ALL auth token types.
The PR modified these files:
IssueNewCardPage.tsx - Changed access check from isActingAsDelegate to isDelegateAccessRestricted
WorkspaceExpensifyCardListPage.tsx - Same change
WorkspaceExpensifyCardPageEmptyState.tsx - Same change
WorkspaceExpensifyCardBankAccounts.tsx - Changed DENIED_ACCESS_VARIANTS.DELEGATE to DENIED_ACCESS_VARIANTS.SUBMITTER
The bug is reproducible on staging but not validated on production, which aligns with PR #81817 being in the current staging deploy (v9.3.26-4) at position #87 in the chronologically ordered list.
The issue affects the card issuance flow specifically when:
A full Copilot delegate accesses the Expensify Card section
They complete the issue card flow
They submit the magic code
The backend rejects the request due to auth token restrictions
The rejection response causes the frontend to sign out the user
Root Cause
Frontend-Backend Mismatch: The frontend was deployed to allow full Copilot users to access card issuance pages, but the backend API was not updated to accept ROLE_ALL delegate auth tokens for the CreateAdminIssuedVirtualCard command. When the magic code is submitted, the backend likely returns an authentication error (jsonCode 407 or similar), which triggers the reauthentication middleware or forces a sign-out.
Please re-state the problem that we are trying to solve in this issue.
When a Copilot user (User B) with full delegate access acts on behalf of User A and issues a new Expensify Card through the magic code flow, User B is force-signed out after entering the magic code. The card is successfully created, but the user's session is disrupted.
What is the root cause of that problem?
PR #81817 changed the frontend delegate access guards on the card issuance pages from blocking all delegates to only blocking submitter-only delegates, allowing full Copilot users (role=all) to reach the card issuance flow. However, the delegate's restricted auth token can expire during the magic code flow (while waiting for User A to share the code), or the backend may not fully accept the restricted token for the CreateAdminIssuedVirtualCard/CreateExpensifyCard commands.
When any API call returns a 407 NOT_AUTHENTICATED while connected as a delegate, the Reauthentication middleware triggers re-authentication using the stashed credentials — which belong to User B's original account, not User A's. The code at Authentication.ts:197-203 detects the delegate session and calls restoreDelegateSession(), which clears Onyx and restores User B's original session at Delegate.ts:698-709. From the user's perspective, this looks like a force sign-out.
The card is still created because the backend processes the creation request before the token issue manifests on a subsequent API call (explaining the "sometimes the user will force sign out after navigating to another section" symptom).
The PR body itself explicitly states: "The backend change (allowing ROLE_ALL auth token type for CreateAdminIssuedVirtualCard command) is out of scope for this frontend PR and needs to be handled separately."
What changes do you think we should make in order to solve the problem?
The fix requires a backend change to ensure the CreateAdminIssuedVirtualCard and CreateExpensifyCard commands accept the ROLE_ALL restricted auth token type used by delegate sessions. This was explicitly called out as out of scope in the original PR #81817.
Additionally, to improve resilience for the magic code flow specifically, the frontend could extend the IssueNewCardConfirmMagicCodePage to handle the delegate token expiration more gracefully — for example, by detecting the delegate session state and warning the user or refreshing the delegate token before submitting the card creation request, rather than allowing the silent sign-out.
What alternative solutions did you explore? (Optional)
Add a delegate token refresh before the CreateExpensifyCard/CreateAdminIssuedVirtualCard API call to ensure the token is still valid after the user enters the magic code.
Delegate sessions use restricted tokens — When a delegate connects via Delegate.connect(), they receive a restrictedToken (not a full authToken). The delegate's original credentials are stashed in STASHED_CREDENTIALS and STASHED_SESSION.
Magic code is sent to the delegator (User A) — The ResendValidateCode command takes no parameters and uses the current session identity (User A's in delegate mode). The magic code page displays User A's email at IssueNewCardConfirmMagicCodePage.tsx:28.
Card creation uses API.write() — issueExpensifyCard() sends CreateAdminIssuedVirtualCard or CreateExpensifyCard through the sequential queue. Client-side Onyx updates only touch ISSUE_NEW_EXPENSIFY_CARD — no session data.
Activity
melvin-bot commentedon Feb 26, 2026
You have been assigned to this deploy blocker because you recently merged this PR: #81817
melvin-bot commentedon Feb 26, 2026
💬 A slack conversation has been started in #expensify-open-source
melvin-bot commentedon Feb 26, 2026
Triggered auto assignment to @trjExpensify (
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 26, 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 26, 2026
🔍 Investigation Summary
Classification: Frontend bug
Causing PR: #81817 - "Allow full Copilot users to access Expensify Card pages" by @MelvinBot (High confidence)
Related Issues: #79095
Recommendation: REVERT
The frontend PR was merged without the corresponding backend changes being deployed first. The PR description explicitly states: "The backend change (allowing
ROLE_ALLauth token type forCreateAdminIssuedVirtualCardcommand) is out of scope for this frontend PR and needs to be handled separately."This means the frontend allows full Copilot users to proceed through the card issuance flow, but when they submit the magic code, the backend rejects the request (likely with a 407 NOT_AUTHENTICATED or similar error), which triggers a sign-out.
Labels: Keeping
DeployBlockerCash(blocks App deploy). TheDeployBlockerlabel was not present on this issue.📋 Detailed Analysis
Evidence
PR #81817 changed the delegate access checks from
isActingAsDelegatetoisDelegateAccessRestrictedfor Expensify Card pages. This allows full Copilot users (ROLE_ALL delegates) to access the card issuance flow, but the backend API commandCreateAdminIssuedVirtualCardhas not been updated to accept ROLE_ALL auth token types.The PR modified these files:
IssueNewCardPage.tsx- Changed access check fromisActingAsDelegatetoisDelegateAccessRestrictedWorkspaceExpensifyCardListPage.tsx- Same changeWorkspaceExpensifyCardPageEmptyState.tsx- Same changeWorkspaceExpensifyCardBankAccounts.tsx- ChangedDENIED_ACCESS_VARIANTS.DELEGATEtoDENIED_ACCESS_VARIANTS.SUBMITTERIssueNewCardConfirmMagicCodePage.tsx- Added session email fallbackVerification
The bug is reproducible on staging but not validated on production, which aligns with PR #81817 being in the current staging deploy (v9.3.26-4) at position #87 in the chronologically ordered list.
The issue affects the card issuance flow specifically when:
Root Cause
Frontend-Backend Mismatch: The frontend was deployed to allow full Copilot users to access card issuance pages, but the backend API was not updated to accept ROLE_ALL delegate auth tokens for the
CreateAdminIssuedVirtualCardcommand. When the magic code is submitted, the backend likely returns an authentication error (jsonCode 407 or similar), which triggers the reauthentication middleware or forces a sign-out.The fix requires EITHER:
MelvinBot commentedon Feb 26, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a Copilot user (User B) with full delegate access acts on behalf of User A and issues a new Expensify Card through the magic code flow, User B is force-signed out after entering the magic code. The card is successfully created, but the user's session is disrupted.
What is the root cause of that problem?
PR #81817 changed the frontend delegate access guards on the card issuance pages from blocking all delegates to only blocking submitter-only delegates, allowing full Copilot users (role=
all) to reach the card issuance flow. However, the delegate's restricted auth token can expire during the magic code flow (while waiting for User A to share the code), or the backend may not fully accept the restricted token for theCreateAdminIssuedVirtualCard/CreateExpensifyCardcommands.When any API call returns a
407 NOT_AUTHENTICATEDwhile connected as a delegate, theReauthenticationmiddleware triggers re-authentication using the stashed credentials — which belong to User B's original account, not User A's. The code atAuthentication.ts:197-203detects the delegate session and callsrestoreDelegateSession(), which clears Onyx and restores User B's original session atDelegate.ts:698-709. From the user's perspective, this looks like a force sign-out.The card is still created because the backend processes the creation request before the token issue manifests on a subsequent API call (explaining the "sometimes the user will force sign out after navigating to another section" symptom).
The PR body itself explicitly states: "The backend change (allowing ROLE_ALL auth token type for CreateAdminIssuedVirtualCard command) is out of scope for this frontend PR and needs to be handled separately."
What changes do you think we should make in order to solve the problem?
The fix requires a backend change to ensure the
CreateAdminIssuedVirtualCardandCreateExpensifyCardcommands accept theROLE_ALLrestricted auth token type used by delegate sessions. This was explicitly called out as out of scope in the original PR #81817.Additionally, to improve resilience for the magic code flow specifically, the frontend could extend the
IssueNewCardConfirmMagicCodePageto handle the delegate token expiration more gracefully — for example, by detecting the delegate session state and warning the user or refreshing the delegate token before submitting the card creation request, rather than allowing the silent sign-out.What alternative solutions did you explore? (Optional)
CreateExpensifyCard/CreateAdminIssuedVirtualCardAPI call to ensure the token is still valid after the user enters the magic code.Detailed Investigation
Evidence Chain
PR Allow full Copilot users to access Expensify Card pages #81817 changed the access guard —
IssueNewCardPage.tsx:53,135usesisDelegateAccessRestricted(fromDelegateNoAccessModalProvider/index.tsx:28), which only blocks submitter-only delegates viaAccountUtils.isDelegateOnlySubmitter. Full copilots (role=all) pass through.Delegate sessions use restricted tokens — When a delegate connects via
Delegate.connect(), they receive arestrictedToken(not a fullauthToken). The delegate's original credentials are stashed inSTASHED_CREDENTIALSandSTASHED_SESSION.Magic code is sent to the delegator (User A) — The
ResendValidateCodecommand takes no parameters and uses the current session identity (User A's in delegate mode). The magic code page displays User A's email atIssueNewCardConfirmMagicCodePage.tsx:28.Card creation uses
API.write()—issueExpensifyCard()sendsCreateAdminIssuedVirtualCardorCreateExpensifyCardthrough the sequential queue. Client-side Onyx updates only touchISSUE_NEW_EXPENSIFY_CARD— no session data.407 triggers delegate session restoration — The
Reauthentication middlewarecatchesNOT_AUTHENTICATEDresponses. Thereauthenticate()function detects delegate mode and callsrestoreDelegateSession(), which clears Onyx and restores User B's own session.Open Questions
ROLE_ALLauth token type on card creation commands been deployed yet?CreateExpensifyCard(physical card) affected the same way asCreateAdminIssuedVirtualCard(virtual card)?Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.18 remaining items
inimaga commentedon Feb 26, 2026
Demoting this for now. See here for reasoning.
rushatgabhane commentedon Mar 1, 2026
Looks all good now
Screen.Recording.2026-03-01.at.23.08.35.mov
rushatgabhane commentedon Mar 1, 2026
can close after @jponikarchuk retests
trjExpensify commentedon Mar 2, 2026
What did the retest say?
jponikarchuk commentedon Mar 2, 2026
@rushatgabhane @trjExpensify Issue is not reproducible for me now
bandicam.2026-03-02.21-06-22-547.mp4
trjExpensify commentedon Mar 2, 2026
Perfect, closing!