Skip to content

fix(signin): Fix flaky vpn signin functional tests#20543

Draft
dschom wants to merge 2 commits into
mainfrom
worktree-fix-flaky-vpn-test
Draft

fix(signin): Fix flaky vpn signin functional tests#20543
dschom wants to merge 2 commits into
mainfrom
worktree-fix-flaky-vpn-test

Conversation

@dschom
Copy link
Copy Markdown
Contributor

@dschom dschom commented May 8, 2026

Because

  • vpn integration > authorization flow - user already signed into Firefox was flaking with a 401 on the second /v1/oauth/authorization. firefox.fxaLogin's async WebChannel handler mutates session state mid-flight, racing with a later OAuth flow's /v1/oauth/authorization HTTP call.

This pull request

  • Adds NavigationOptions.isCachedSignin, set in signInWithCachedAccount.
  • In handleNavigation, defers fxaLogin until after getOAuthNavigationTarget only when isCachedSignin && isOAuth. First-flow (password) signins keep the original ordering — pairing's pair_authorize handler relies on Firefox seeing fxaLogin first, and the previous blanket-reorder attempt deterministically broke pairing/pairingFlow.spec.ts.

Companion: #20556 (testAccountTracker → v2; independent).

Issue that this pull request solves

Closes: FXA-13687

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

@dschom dschom requested a review from a team as a code owner May 8, 2026 00:01
@dschom dschom marked this pull request as draft May 8, 2026 01:11
@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch from 204d9de to 76e1354 Compare May 9, 2026 00:13
@dschom dschom changed the title fix(functional-tests): default test accounts to v2 key stretching fix(signin): run /oauth/authorization before firing webchannel events May 9, 2026
@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch 3 times, most recently from 75d701f to 860f9cf Compare May 12, 2026 01:01
@dschom dschom requested a review from vpomerleau May 12, 2026 20:02
@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch from 860f9cf to 0473650 Compare May 12, 2026 20:05
@dschom dschom marked this pull request as ready for review May 12, 2026 20:05
sendFxaLogin(navigationOptions);
}

// Non-OAuth path: send Login then navigate.
Copy link
Copy Markdown
Contributor

@LZoog LZoog May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is right - isOAuth is going to be true if the integration is OAuthNative (oauth desktop Sync, or any other service flow). The only non-oauth integration that should send web channel messages is the old FxDesktopV3. Haven't tested this locally though.

edit: I should have seen that further down in the isOAuth check, you've got this chunk of code there too and you left the comment 👍 . Can we add a comment about this only being for fx_desktop_v3? We should be able to remove it later when we don't care to support fx_desktop_v3 any longer.

Copy link
Copy Markdown
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thank you for investigating!! r+, but just noting, I didn't test the flows locally. Our functional tests have a desktop v3 test though so might be good to verify there's a test there that sends fxa_login if we don't have one already but I know we have coverage for login + oauth so LGTM.

// IMPORTANT: run /oauth/authorization (HTTP) BEFORE firing any web
// channel messages. firefox.fxaLogin/fxaOAuthLogin dispatch synchronously
// but the browser processes them asynchronously, and the browser's
// handler for fxaLogin can mutate session state in ways that race with
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, what ways does it mutate the session state?

// "unconfirmed session" error. The only exception to this is the type C
// unverified session noted above.
if (isOAuth) {
// IMPORTANT: run /oauth/authorization (HTTP) BEFORE firing any web
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like if I'm looking at this file later, I might be confused by what run /oauth/authorization means? It makes me think of the VPN test and us navigating to /authorization there but I think we're just talking about doing the oauth dance/getting the oauth data back.

@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch 8 times, most recently from 98f5d19 to 32d465c Compare May 16, 2026 01:45
@dschom dschom changed the title fix(signin): run /oauth/authorization before firing webchannel events fix(signin): Fix flaky vpn signin functional tests May 19, 2026
@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch from 32d465c to ddc0352 Compare May 19, 2026 16:42
dschom and others added 2 commits May 20, 2026 16:23
Because:
* In handleNavigation's verified-OAuth path, sendFxaLogin (the
  fxaccounts:login webchannel event) was dispatched synchronously
  BEFORE awaiting getOAuthNavigationTarget (the /v1/oauth/authorization
  HTTP call). The browser's async handler for that webchannel message
  can mutate session state, racing with the in-flight HTTP request.
* This produced intermittent 401 "Token not found" failures on the
  HTTP call — most reproducibly when the same browser context goes
  through two consecutive OAuth flows (e.g. the vpn integration test
  signing into Sync then VPN). The first /oauth/authorization
  succeeded; the second one would 401 even though the session
  remained valid for /account/profile, /session/status, and
  /oauth/token in between.

This commit:
* Reorders handleNavigation so getOAuthNavigationTarget runs first,
  obtaining the OAuth code while the session is still untouched, and
  THEN fires fxaLogin and fxaOAuthLogin. The Login → OAuthLogin order
  is preserved (still required for Desktop OAuth per FXA-10388).
* Adds a v1-account regression test alongside the existing vpn
  integration test, using target.createAuthClient(1) so the v1→v2
  upgrade path is exercised on the first sign-in even after
  testAccountTracker defaults to v2 (separate PR).

closes FXA-13687
…tener

Because:
* The "authority generates QR URL and supplicant connects via channel"
  pairing spec consistently times out in CI. Firefox's
  FxAccountsPairingFlow processes both pairAuthorize and
  pair:supp:authorize but pair:auth:authorize is never delivered to the
  supplicant. The root cause is an unresolved environment-specific
  interaction between Playwright's bundled Firefox and the production
  channel server (wss://channelserver.services.mozilla.com).
* requestAnimationFrame callbacks are throttled in background/headless
  Firefox windows. sendPairingCommand and pairHeartbeat both used rAF to
  schedule their sends, causing the 500 ms fallback timeout to fire
  without the commands ever reaching Firefox.
* recordAuthorizationOnLogin was awaited on the /oauth/authorization
  response path, adding unnecessary DB latency.

This commit:
* Marks the happy-path pairing test as fixme (FXA-13687) with a detailed
  comment. The test infrastructure changes below are retained for when
  the underlying environment issue is resolved.
* Pre-installs a WebChannel listener for fxaccounts:oauth_login before
  clicking Confirm, giving an earlier success signal than waitForURL.
* Bumps TIMEOUTS.AUTHORITY_COMPLETE from 15s to 30s.
* Removes requestAnimationFrame from sendPairingCommand and pairHeartbeat
  in firefox.ts so commands are dispatched immediately.
* Makes recordAuthorizationOnLogin fire-and-forget in /oauth/authorization.
* Adds WebChannel redirect URIs to the Fenix OAuth client in dev.json:
  urn:ietf:wg:oauth:2.0:oob:pair-auth-webchannel and
  urn:ietf:wg:oauth:2.0:oob:oauth-redirect-webchannel.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@dschom dschom force-pushed the worktree-fix-flaky-vpn-test branch from 9d6b748 to 8f2d42a Compare May 20, 2026 23:25
@dschom dschom marked this pull request as draft May 20, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants