Skip to content

test: prevents race condition on app restarts#29721

Draft
christopherferreira9 wants to merge 2 commits into
mainfrom
cferreira/investigate-race-condition
Draft

test: prevents race condition on app restarts#29721
christopherferreira9 wants to merge 2 commits into
mainfrom
cferreira/investigate-race-condition

Conversation

@christopherferreira9
Copy link
Copy Markdown
Contributor

Description

Changelog

CHANGELOG entry:

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbotv2 metamaskbotv2 Bot added the team-qa QA team label May 5, 2026
@github-actions github-actions Bot added the size-S label May 5, 2026
@github-actions github-actions Bot added size-M and removed size-S labels May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeWalletPlatform, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, SmokeBrowser, SmokeSnaps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: high
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changed files are in app/util/generateSkipOnboardingState.ts and its test file. This utility is the core E2E test infrastructure mechanism that allows tests to skip the onboarding flow and start with a pre-initialized wallet state. It is imported and called by app/store/sagas/index.ts during EngineService startup.

The changes fix a critical race condition in the vault initialization logic:

  1. Debounce window bug: The vault initialization flag could be set immediately, but the KeyringController state is flushed to disk with a 200ms debounce. If the app restarts within that window, the flag exists but the vault is empty. The fix now checks Engine.context.KeyringController.state.keyrings to verify actual accounts exist.
  2. Redux state repair: The app could be terminated after controller state is persisted but before Redux flags finish writing, leaving existingUser=false on next launch. The fix now dispatches setExistingUser(true) and setCompletedOnboarding(true) on every launch (not just first initialization).
  3. Password repair: A new code path handles the case where accounts exist but the initialized flag is missing, repairing the password entry without resetting the vault.

Since this utility is the foundation that ALL E2E tests rely on to bypass onboarding and start with a valid wallet state, any regression in this code could cause widespread test failures across all test suites. The fix addresses real flakiness issues that affect test reliability. All test tags should be run to:

  1. Verify the fix resolves the race condition flakiness
  2. Ensure no regression was introduced in the initialization logic
  3. Validate that all test suites still correctly start with a properly initialized wallet

Performance Test Selection:
The changes are to the E2E test infrastructure utility (generateSkipOnboardingState.ts) that sets up pre-initialized wallet state for tests. While it touches Engine and KeyringController state, these changes are specifically about fixing a race condition in the test setup mechanism, not about UI rendering, data loading performance, or app startup performance in production. No performance test tags are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant