Skip to content

[$250] Sign in - 'Couldn't retrieve account details' error message displayed when trying to sign in #86321

Closed

Description

@m-natarajan

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


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:

  1. Sign out if logged in
  2. 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:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

LoginIssue.mp4
Image Image

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mjasikowski
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022036811175278269293
  • Upwork Job ID: 2036811175278269293
  • Last Price Increase: 2026-03-25

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 25, 2026
  2. MelvinBot commented on Mar 25, 2026

    @MelvinBot
    Contributor

    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 (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:

    1. 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.
    2. Onyx.clear() resets PERSISTED_REQUESTS, which can trigger SequentialQueue.flush(). flush() recreates isReadyPromise as a new unresolved promise at SequentialQueue.ts:322.
    3. 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.
    4. User enters a new email on the sign-in page and triggers beginSignIn() → API.read(BEGIN_SIGNIN) → waitForWrites() — this waits on the unresolved isReadyPromise from step 2.
    5. 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:

    if (command === READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN || command === READ_COMMANDS.SIGN_IN_WITH_SUPPORT_AUTH_TOKEN || command === READ_COMMANDS.BEGIN_SIGNIN) {
        processRequest(request, CONST.API_REQUEST_TYPE.READ);
        return;
    }
    

    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)

    1. 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.

    2. 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.

    3. 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.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 25, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 25, 2026
  5. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @dmkt9 (External)

  6. 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
  7. melvin-bot commented on Mar 25, 2026

    @melvin-bot
  8. surafeal-dev commented on Mar 25, 2026

    @surafeal-dev

    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?

    • 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?

    1. 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.
    1. 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).
    1. (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.
  9. abelhailefen commented on Mar 25, 2026

    @abelhailefen

    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.

  10. added a commit that references this issue on Mar 25, 2026
    414f296
  11. wildan-m commented on Mar 25, 2026

    @wildan-m
    Contributor

    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 the SequentialQueue's in-memory state during sign-out. It already cleans up most network infrastructure — MainQueue, HttpUtils, PersistedRequests, and NetworkConnection — but omits SequentialQueue:

    function cleanupSession() {
    Pusher.disconnect();
    Timers.clearAll();
    Welcome.resetAllChecks();
    MainQueue.clear();
    HttpUtils.cancelPendingRequests();
    PersistedRequests.clear();
    NetworkConnection.clearReconnectionCallbacks();
    SessionUtils.resetDidUserLogInDuringSession();
    resetNavigationState();
    clearCache().then(() => {
    Log.info('Cleared all cache data', true, {}, true);
    });
    clearCachedAttachments();
    clearSoundAssetsCache();
    }

    When the queue is flushing write requests at sign-out time, flush() replaces isReadyPromise with a new unresolved promise:

    if (shouldResetPromise) {
    // Reset the isReadyPromise so that the queue will be flushed as soon as the request is finished
    isReadyPromise = new Promise((resolve) => {
    resolveIsReadyPromise = resolve;
    });
    }

    That promise is what waitForIdle() (and therefore waitForWrites()) returns:

    function waitForIdle(): Promise<unknown> {
    return isReadyPromise;
    }

    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:

    let isReadyPromise = new Promise((resolve) => {
    resolveIsReadyPromise = resolve;
    });
    // 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:

    function resetQueue(): void {
    isSequentialQueueRunning = false;
    currentRequestPromise = null;
    isQueuePaused = false;
    isReadyPromise = new Promise((resolve) => {
    resolveIsReadyPromise = resolve;
    });
    resolveIsReadyPromise?.();
    }

    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

  12. dmkt9 commented on Mar 26, 2026

    @dmkt9
    Contributor

    @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 BeginSignIn API hangs instead of returning failure data.

  13. 7 remaining items

  14. melvin-bot commented on Apr 6, 2026

    @melvin-bot

    @mjasikowski Eep! 4 days overdue now. Issues have feelings too...

  15. mjasikowski commented on Apr 7, 2026

    @mjasikowski
    Contributor

    Investigating

  16. m-natarajan commented on Apr 7, 2026

    @m-natarajan
    Author

    Unable to reproduce in Production

    Screen.Recording.2026-04-07.at.15.06.58.mp4
  17. mjasikowski commented on Apr 7, 2026

    @mjasikowski
    Contributor

    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.

  18. added
    ReviewingHas a PR in review
    and removed
    ReviewingHas a PR in review
    on Apr 7, 2026
  19. m-natarajan commented on Apr 10, 2026

    @m-natarajan
    Author

    @mjasikowski
    Able to reproduce this issue but its intermittent. Should I reopen this issue? Automation team also reported the same.

    Image
  20. mjasikowski commented on May 25, 2026

    @mjasikowski
    Contributor

    @MelvinBot create a new issue in Expensify/Expensify to investigate the problems, as they are recurring

  21. MelvinBot commented on May 25, 2026

    @MelvinBot
    Contributor

    Created https://github.com/Expensify/Expensify/issues/640645 to investigate the recurring BeginSignIn 403 responses on the backend/firewall side. Assigned to mjasikowski.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions