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] Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in #86321
Version Number: 9.3.43-3 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: Applause Internal Team Slack conversation (hyperlinked to channel name): #Quality
Action Performed:
Sign out if logged in
Trying to sign in again with different email
Expected Result:
User should be signed in without error message
Actual Result:
'Couldn't retrieve account details, please try to sign in again.' error message displayed. Refreshing the page and signin with the same email works at times.
Workaround:
Refresh the page and signin
Platforms:
Select the officially supported platforms where the issue was reproduced:
Please re-state the problem that we are trying to solve in this issue.
After signing out and attempting to sign in with a different email, users see the error "Couldn't retrieve account details, please try to sign in again." Refreshing the page and retrying works. This is reproducible on web (Chrome/Safari) in both staging and production.
What is the root cause of that problem?
The root cause is that BeginSignIn (a READ command) is blocked by waitForWrites() in API.read(), which waits for the SequentialQueue's isReadyPromise to resolve before processing the request. After sign-out, this promise can be left in an unresolved state due to a race condition in the cleanup sequence.
Here's the sequence:
User signs out. signOutAndRedirectToSignIn() calls signOut() (LOG_OUT API), then calls redirectToSignIn() which triggers Onyx.clear() — but this is fire-and-forget (not awaited) at Session/index.ts:446.
Onyx.clear() resets PERSISTED_REQUESTS, which can trigger SequentialQueue.flush(). flush() recreates isReadyPromise as a new unresolved promise at SequentialQueue.ts:322.
cleanupSession() runs when AuthScreensInitHandler unmounts (AuthScreensInitHandler.tsx:146), calling HttpUtils.cancelPendingRequests() which aborts in-flight requests and NetworkConnection.clearReconnectionCallbacks() which removes the reconnection handler that would normally trigger queue recovery.
User enters a new email on the sign-in page and triggers beginSignIn() → API.read(BEGIN_SIGNIN) → waitForWrites() — this waits on the unresolvedisReadyPromise from step 2.
The BeginSignIn request either never fires (hangs on the unresolved promise) or gets aborted by lingering cleanup, triggering the failureData which sets the cannotGetAccountDetails error at Session/index.ts:545.
A contributing factor: the credential-empty guard in Authentication.ts:134-140 is commented out (referencing #fireroom-2026-01-28-user-signout), meaning if reauthentication is triggered with stale/empty credentials, it falls through silently instead of cleanly aborting.
Refreshing the page works because all in-memory state (including isReadyPromise, which is resolved immediately on module load at SequentialQueue.ts:51) is reinitialized.
What changes do you think we should make in order to solve the problem?
Exempt BeginSignIn from waitForWrites in API.read() at API/index.ts:247. BeginSignIn does not require an auth token (it's already exempt in enhanceParameters.ts:49-51) and is used on the sign-in page before any session exists. There is no reason for it to wait for write requests from a previous session to complete.
Add READ_COMMANDS.BEGIN_SIGNIN to the existing exemption check:
Similarly, BEGIN_APPLE_SIGN_IN and BEGIN_GOOGLE_SIGN_IN should also be exempted as they use the same signInAttemptState() and have the same pre-session semantics.
What alternative solutions did you explore? (Optional)
Awaiting Onyx.clear() in signOutAndRedirectToSignIn — This would ensure cleanup completes before the sign-in page becomes interactive. However, this is a larger change with potential side effects on the sign-out flow timing and would not address the fundamental design issue of sign-in commands waiting on write queues from a previous session.
Resetting isReadyPromise in cleanupSession() — Adding a SequentialQueue.resetReadyPromise() call that creates and immediately resolves a new promise. This would unblock pending reads but could have unintended effects on other read commands that legitimately need to wait.
Re-enabling the credential-empty guard in Authentication.ts — Un-commenting the code at lines 134-140 would prevent broken reauthentication attempts, but wouldn't fix the primary issue of BeginSignIn being blocked by waitForWrites.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
changed the title [-]Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in[/-][+][$250] Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in[/+]on Mar 25, 2026
Please re-state the problem that we are trying to solve in this issue.
On iOS HybridApp launch a console error appears: Uncaught (in promise, id: 0): "Error: The operation couldn't be completed. (BGTaskSchedulerErrorDomain error 1.)" (BGTaskScheduler.Error.unavailable). It surfaces as an unhandled promise rejection during app startup.
What is the root cause of that problem?
The NewDot app unconditionally imports and registers background tasks (App/src/setup/backgroundTask/index.native.ts) on startup. That code calls TaskManager.defineTask() which invokes native code that expects BGTaskScheduler configuration (BGTaskSchedulerPermittedIdentifiers and UIBackgroundModes) to be present in the host app Info.plist.
In HybridApp mode the JS runs inside the OldDot native host (Mobile-Expensify). The OldDot host bundle does not include the NewDot Info.plist keys, so the native call to schedule/submit background tasks fails with BGTaskSchedulerErrorDomain error 1 and rejects the promise.
The JS caller does not attach a .catch() to the promise, so the rejection becomes an unhandled promise error in the console.
What changes do you think we should make in order to solve the problem?
Guard background task registration in HybridApp:
Update App/src/setup/backgroundTask/index.native.ts to detect HybridApp mode (using CONFIG.IS_HYBRID_APP or equivalent runtime flag) and skip TaskManager.defineTask() when running inside HybridApp. The host app likely doesn't intend NewDot to schedule background tasks.
Add robust promise handling as a defensive measure:
Ensure TaskManager.defineTask() calls are followed by .catch() that logs a non-fatal warning instead of surfacing an unhandled rejection. This prevents console noise even in edge cases (simulator, misconfigured bundle, or temporary scheduler unavailability).
(Optional / follow-up) Verify host bundle configuration if background tasks are required in HybridApp:
If product decides HybridApp should support background tasks, coordinate with Mobile-Expensify owners to add BGTaskSchedulerPermittedIdentifiers and UIBackgroundModes to the OldDot Info.plist and wire up any native setup. This is out-of-repo and requires cross-repo/ops coordination.
Crucial implementation details
File changes:
App/src/setup/backgroundTask/index.native.ts: wrap defineTask call with if (!CONFIG.IS_HYBRID_APP) { ... } and attach .catch() to the returned promise.
Add a safe logger call (e.g., Log.warn('backgroundTask', '...')) on failure so errors are recorded but non-fatal.
Acceptance criteria
The console no longer shows an unhandled promise rejection for BGTaskSchedulerErrorDomain error 1 on HybridApp iOS launches.
Background tasks remain registered on standalone NewDot builds where IS_HYBRID_APP is false and Info.plist keys are present.
The app logs a clear, non-fatal warning if defineTask() fails for any reason (simulator, missing keys, scheduler unavailable).
Alternative solutions considered
Add required background keys to the OldDot host Info.plist (Mobile-Expensify): feasible but cross-repo and may enable background behavior not desired by the host app.
Always swallow the promise rejection without a guard: reduces console noise but would register background tasks in a host that may not be configured for them — risky.
Testing notes
Manual: Launch HybridApp on device and simulator; confirm no unhandled promise rejection appears. Launch standalone NewDot and confirm background task registration still occurs (or at least no regression).
Unit: add a test that index.native.ts skips defineTask when CONFIG.IS_HYBRID_APP === true and that the call attaches a .catch() handler.
E2E: optionally verify background task behavior on a real device with correct Info.plist keys.
Please re-state the problem that we are trying to solve in this issue.
When a user signs out of the app and immediately tries to sign in with a different email address, they are blocked by an error message stating "Couldn't retrieve account details. Please try to sign in again." The user is forced to manually refresh the page to successfully sign in.
What is the root cause of that problem?
The issue is caused by a race condition between the asynchronous sign-out process and the new sign-in attempt, combined with how the login screen handles stale error states.
When a user signs out, the app sends a logout network request and begins clearing local session data. If the user immediately submits a new sign-in request, it can fail because it either gets queued behind the pending logout request or goes out with a newly invalidated authentication token. When this failure occurs, the app saves an error message to the local account state.
The login screen currently only clears account errors exactly once when the component initially loads (mounts). Because the login screen is often already mounted in the background during the sign-out transition, it does not re-run this clearing logic when the user lands back on it. As a result, the stale error from the interrupted background request persists on the screen, blocking the user.
What changes do you think we should make in order to solve the problem?
We need to update the login form so that it clears stale account errors every time it becomes active, not just on its initial load.
To do this, we will update the component lifecycle logic inside the base login form. Currently, the logic that clears errors and the logic that auto-focuses the text input are bundled together and set to run only once. We will separate these into two distinct processes.
We will create a dedicated process that listens specifically to the screen's focus and visibility states. Whenever the login screen becomes both focused and visible—such as when a user is redirected back to it immediately after signing out—it will actively clear any lingering account error messages. This ensures that even if a background race condition causes a temporary failure, the UI remains clean and the user can proceed with their new sign-in attempt without needing to refresh.
What alternative solutions did you explore? (Optional)
We considered updating the core network API layer to support canceling in-flight sign-in requests (using an abort controller or a request counter) if they conflict with a sign-out event. However, modifying the foundational API request logic for this specific timing edge case adds unnecessary complexity and risk. Handling the stale error state directly at the UI level is a much simpler, safer, and more robust solution.
Please re-state the problem that we are trying to solve in this issue.
After signing out and attempting to sign in with a different email, users see "Couldn't retrieve account details, please try to sign in again." Refreshing the page resolves it.
What is the root cause of that problem?
cleanupSession() does not reset the SequentialQueue's in-memory state during sign-out. It already cleans up most network infrastructure — MainQueue, HttpUtils, PersistedRequests, and NetworkConnection — but omits SequentialQueue:
Because cleanupSession() cancels in-flight requests and removes the reconnection callback that would normally trigger queue recovery, nothing resolves the stale promise. When the user then enters an email on the sign-in page, beginSignIn() → API.read(BEGIN_SIGNIN) → waitForWrites() waits on that unresolved promise, and the request either hangs or fails — resulting in the failureData error.
Refreshing the page works because all module-level state is reinitialized, including isReadyPromise which is immediately resolved on load:
// Resolve the isReadyPromise immediately so that the queue starts working as soon as the page loads
resolveIsReadyPromise?.();
What changes do you think we should make in order to solve the problem?
Add SequentialQueue.resetQueue() to cleanupSession(), right after the existing NetworkConnection.clearReconnectionCallbacks() call. resetQueue() already exists (used by tests) and does exactly what's needed — it resets isSequentialQueueRunning, currentRequestPromise, isQueuePaused, and creates a new immediately-resolved isReadyPromise:
This ensures the queue is in a clean initial state for the new session, exactly as if the page had been refreshed. All subsequent waitForWrites() calls resolve immediately instead of blocking on stale state from the previous session.
The network requests were stopped at the firewall level, so I'm going to close this as a network problem. It can't be reproduced either. If it re-occurs, we'll investigate further.
Activity
MelvinBot commentedon Mar 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After signing out and attempting to sign in with a different email, users see the error "Couldn't retrieve account details, please try to sign in again." Refreshing the page and retrying works. This is reproducible on web (Chrome/Safari) in both staging and production.
What is the root cause of that problem?
The root cause is that
BeginSignIn(aREADcommand) is blocked bywaitForWrites()inAPI.read(), which waits for theSequentialQueue'sisReadyPromiseto resolve before processing the request. After sign-out, this promise can be left in an unresolved state due to a race condition in the cleanup sequence.Here's the sequence:
signOutAndRedirectToSignIn()callssignOut()(LOG_OUT API), then callsredirectToSignIn()which triggersOnyx.clear()— but this is fire-and-forget (not awaited) atSession/index.ts:446.Onyx.clear()resetsPERSISTED_REQUESTS, which can triggerSequentialQueue.flush().flush()recreatesisReadyPromiseas a new unresolved promise atSequentialQueue.ts:322.cleanupSession()runs whenAuthScreensInitHandlerunmounts (AuthScreensInitHandler.tsx:146), callingHttpUtils.cancelPendingRequests()which aborts in-flight requests andNetworkConnection.clearReconnectionCallbacks()which removes the reconnection handler that would normally trigger queue recovery.beginSignIn()→API.read(BEGIN_SIGNIN)→waitForWrites()— this waits on the unresolvedisReadyPromisefrom step 2.BeginSignInrequest either never fires (hangs on the unresolved promise) or gets aborted by lingering cleanup, triggering thefailureDatawhich sets thecannotGetAccountDetailserror atSession/index.ts:545.A contributing factor: the credential-empty guard in
Authentication.ts:134-140is commented out (referencing#fireroom-2026-01-28-user-signout), meaning if reauthentication is triggered with stale/empty credentials, it falls through silently instead of cleanly aborting.Refreshing the page works because all in-memory state (including
isReadyPromise, which is resolved immediately on module load atSequentialQueue.ts:51) is reinitialized.What changes do you think we should make in order to solve the problem?
Exempt
BeginSignInfromwaitForWritesinAPI.read()atAPI/index.ts:247.BeginSignIndoes not require an auth token (it's already exempt inenhanceParameters.ts:49-51) and is used on the sign-in page before any session exists. There is no reason for it to wait for write requests from a previous session to complete.Add
READ_COMMANDS.BEGIN_SIGNINto the existing exemption check:Similarly,
BEGIN_APPLE_SIGN_INandBEGIN_GOOGLE_SIGN_INshould also be exempted as they use the samesignInAttemptState()and have the same pre-session semantics.What alternative solutions did you explore? (Optional)
Awaiting
Onyx.clear()insignOutAndRedirectToSignIn— This would ensure cleanup completes before the sign-in page becomes interactive. However, this is a larger change with potential side effects on the sign-out flow timing and would not address the fundamental design issue of sign-in commands waiting on write queues from a previous session.Resetting
isReadyPromiseincleanupSession()— Adding aSequentialQueue.resetReadyPromise()call that creates and immediately resolves a new promise. This would unblock pending reads but could have unintended effects on other read commands that legitimately need to wait.Re-enabling the credential-empty guard in
Authentication.ts— Un-commenting the code at lines 134-140 would prevent broken reauthentication attempts, but wouldn't fix the primary issue ofBeginSignInbeing blocked bywaitForWrites.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.melvin-bot commentedon Mar 25, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @dmkt9 (
External)[-]Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in[/-][+][$250] Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in[/+]melvin-bot commentedon Mar 25, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022036811175278269293
surafeal-dev commentedon Mar 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On iOS HybridApp launch a console error appears: Uncaught (in promise, id: 0): "Error: The operation couldn't be completed. (BGTaskSchedulerErrorDomain error 1.)" (BGTaskScheduler.Error.unavailable). It surfaces as an unhandled promise rejection during app startup.
What is the root cause of that problem?
App/src/setup/backgroundTask/index.native.ts) on startup. That code callsTaskManager.defineTask()which invokes native code that expects BGTaskScheduler configuration (BGTaskSchedulerPermittedIdentifiersand UIBackgroundModes) to be present in the host app Info.plist..catch()to the promise, so the rejection becomes an unhandled promise error in the console.What changes do you think we should make in order to solve the problem?
App/src/setup/backgroundTask/index.native.tsto detect HybridApp mode (usingCONFIG.IS_HYBRID_APPor equivalent runtime flag) and skipTaskManager.defineTask()when running inside HybridApp. The host app likely doesn't intend NewDot to schedule background tasks.TaskManager.defineTask()calls are followed by.catch()that logs a non-fatal warning instead of surfacing an unhandled rejection. This prevents console noise even in edge cases (simulator, misconfigured bundle, or temporary scheduler unavailability).BGTaskSchedulerPermittedIdentifiersandUIBackgroundModesto the OldDot Info.plist and wire up any native setup. This is out-of-repo and requires cross-repo/ops coordination.Crucial implementation details
App/src/setup/backgroundTask/index.native.ts: wrapdefineTaskcall withif (!CONFIG.IS_HYBRID_APP) { ... }and attach.catch()to the returned promise.Log.warn('backgroundTask', '...')) on failure so errors are recorded but non-fatal.Acceptance criteria
IS_HYBRID_APPis false and Info.plist keys are present.defineTask()fails for any reason (simulator, missing keys, scheduler unavailable).Alternative solutions considered
Testing notes
index.native.tsskips defineTask whenCONFIG.IS_HYBRID_APP === trueand that the call attaches a.catch()handler.abelhailefen commentedon Mar 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a user signs out of the app and immediately tries to sign in with a different email address, they are blocked by an error message stating "Couldn't retrieve account details. Please try to sign in again." The user is forced to manually refresh the page to successfully sign in.
What is the root cause of that problem?
The issue is caused by a race condition between the asynchronous sign-out process and the new sign-in attempt, combined with how the login screen handles stale error states.
When a user signs out, the app sends a logout network request and begins clearing local session data. If the user immediately submits a new sign-in request, it can fail because it either gets queued behind the pending logout request or goes out with a newly invalidated authentication token. When this failure occurs, the app saves an error message to the local account state.
The login screen currently only clears account errors exactly once when the component initially loads (mounts). Because the login screen is often already mounted in the background during the sign-out transition, it does not re-run this clearing logic when the user lands back on it. As a result, the stale error from the interrupted background request persists on the screen, blocking the user.
What changes do you think we should make in order to solve the problem?
We need to update the login form so that it clears stale account errors every time it becomes active, not just on its initial load.
To do this, we will update the component lifecycle logic inside the base login form. Currently, the logic that clears errors and the logic that auto-focuses the text input are bundled together and set to run only once. We will separate these into two distinct processes.
We will create a dedicated process that listens specifically to the screen's focus and visibility states. Whenever the login screen becomes both focused and visible—such as when a user is redirected back to it immediately after signing out—it will actively clear any lingering account error messages. This ensures that even if a background race condition causes a temporary failure, the UI remains clean and the user can proceed with their new sign-in attempt without needing to refresh.
What alternative solutions did you explore? (Optional)
We considered updating the core network API layer to support canceling in-flight sign-in requests (using an abort controller or a request counter) if they conflict with a sign-out event. However, modifying the foundational API request logic for this specific timing edge case adds unnecessary complexity and risk. Handling the stale error state directly at the UI level is a much simpler, safer, and more robust solution.
Reset SequentialQueue state during session cleanup to unblock sign-in
wildan-m commentedon Mar 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
After signing out and attempting to sign in with a different email, users see "Couldn't retrieve account details, please try to sign in again." Refreshing the page resolves it.
What is the root cause of that problem?
cleanupSession()does not reset theSequentialQueue's in-memory state during sign-out. It already cleans up most network infrastructure —MainQueue,HttpUtils,PersistedRequests, andNetworkConnection— but omitsSequentialQueue:App/src/libs/actions/Session/index.ts
Lines 1007 to 1022 in f82128f
When the queue is flushing write requests at sign-out time,
flush()replacesisReadyPromisewith a new unresolved promise:App/src/libs/Network/SequentialQueue.ts
Lines 320 to 325 in f82128f
That promise is what
waitForIdle()(and thereforewaitForWrites()) returns:App/src/libs/Network/SequentialQueue.ts
Lines 561 to 563 in f82128f
Because
cleanupSession()cancels in-flight requests and removes the reconnection callback that would normally trigger queue recovery, nothing resolves the stale promise. When the user then enters an email on the sign-in page,beginSignIn()→API.read(BEGIN_SIGNIN)→waitForWrites()waits on that unresolved promise, and the request either hangs or fails — resulting in thefailureDataerror.Refreshing the page works because all module-level state is reinitialized, including
isReadyPromisewhich is immediately resolved on load:App/src/libs/Network/SequentialQueue.ts
Lines 46 to 51 in f82128f
What changes do you think we should make in order to solve the problem?
Add
SequentialQueue.resetQueue()tocleanupSession(), right after the existingNetworkConnection.clearReconnectionCallbacks()call.resetQueue()already exists (used by tests) and does exactly what's needed — it resetsisSequentialQueueRunning,currentRequestPromise,isQueuePaused, and creates a new immediately-resolvedisReadyPromise:App/src/libs/Network/SequentialQueue.ts
Lines 569 to 577 in f82128f
This ensures the queue is in a clean initial state for the new session, exactly as if the page had been refreshed. All subsequent
waitForWrites()calls resolve immediately instead of blocking on stale state from the previous session.https://github.com/Expensify/App/compare/main...wildan-m:App:wildan/86321-fix-signin-after-signout?expand=1
dmkt9 commentedon Mar 26, 2026
@wildan-m, @surafeal-dev, @abelhailefen, can you reproduce this issue on your end?
@MelvinBot, your RCA seems incorrect. If the promise can’t be resolved, the
BeginSignInAPI hangs instead of returning failure data.7 remaining items
melvin-bot commentedon Apr 6, 2026
@mjasikowski Eep! 4 days overdue now. Issues have feelings too...
mjasikowski commentedon Apr 7, 2026
Investigating
m-natarajan commentedon Apr 7, 2026
Unable to reproduce in Production
Screen.Recording.2026-04-07.at.15.06.58.mp4
mjasikowski commentedon Apr 7, 2026
The network requests were stopped at the firewall level, so I'm going to close this as a network problem. It can't be reproduced either. If it re-occurs, we'll investigate further.
m-natarajan commentedon Apr 10, 2026
@mjasikowski
Able to reproduce this issue but its intermittent. Should I reopen this issue? Automation team also reported the same.
mjasikowski commentedon May 25, 2026
@MelvinBot create a new issue in Expensify/Expensify to investigate the problems, as they are recurring
MelvinBot commentedon May 25, 2026
Created https://github.com/Expensify/Expensify/issues/640645 to investigate the recurring
BeginSignIn403 responses on the backend/firewall side. Assigned tomjasikowski.