MetaMask / MetaMask/metamask-extension

Investigate atomic persistence for multi-controller keyring workflows

Open
#45,818 1 comment 0 reactions 0 assignees View on GitHub
INVALID-ISSUE-TEMPLATE ta-triaged
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

## Context

Multi-step keyring workflows can update `KeyringController` before related work in other controllers has succeeded.

For example, `LegacyBackgroundApiService.importAccountWithStrategy` currently:

1. imports the account through `KeyringController`;
2. creates or updates the social backup;
3. removes the account as compensation if backup creation fails;
4. selects the imported account.

This consistency gap predates #44009. Debounced persistence could already make an intermediate keyring state durable. Flushing keyring persistence in #44009 narrows the shutdown-loss window, but also makes that existing intermediate state more likely to reach storage before the overall workflow completes.

## Desired outcome

Define and implement a durability boundary for workflows that span keyring, social-backup, account, and selection state.

Possible approaches include:

- deferring the keyring flush until the owning workflow reports success;
- adding an explicit persistence transaction or batching boundary;
- making compensation durable and restart-safe;
- adding startup reconciliation for incomplete workflows.

## Acceptance criteria

- Document the intended consistency and durability semantics for multi-controller keyring workflows.
- Cover social-backup failure after a keyring import.
- Cover termination or runtime reload between keyring import and completion of related controller updates.
- Verify restart state is internally consistent: either the operation completed, or it was fully compensated.
- Confirm ordinary keyring mutations still receive the shutdown-loss protection introduced by #44009.

Related: #44009

Contributor guide

Open the contributing guide

Research direction

Start with LegacyBackgroundApiService.importAccountWithStrategy and read the context from #44009 to understand current keyring persistence and shutdown behavior. Trace the related KeyringController, social-backup, account, and selection updates. Done means documented consistency semantics, coverage for backup failure and termination or reload, restart-consistent state, and preserved shutdown-loss protection for ordinary keyring mutations.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.