Skip to content

fix(account-tree-controller): reset mappings and selected account in clearState - #9825

Merged
ccharly merged 6 commits into
mainfrom
cc/fix/account-tree-clear-state
Aug 13, 2026
Merged

fix(account-tree-controller): reset mappings and selected account in clearState#9825
ccharly merged 6 commits into
mainfrom
cc/fix/account-tree-clear-state

Conversation

@ccharly

@ccharly ccharly commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Explanation

We were not completely resetting the transient state of the AccountTreeController during clearState.

We now properly clear the mappings and fire an '' (empty) selected account group, since the tree will be empty.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches wallet-reset and account-selection event flow across controllers; behavior change is intentional but consumers must already handle empty selectedAccountGroupChange as documented.

Overview
AccountTreeController.clearState now fully tears down transient state on wallet reset: it clears in-memory reverse-lookup maps (#accountIdToContext, #groupIdToWalletId) and publishes AccountTreeController:selectedAccountGroupChange with an empty new group id (''), matching normal selection transitions.

AssetsController listens for that event’s groupId and skips getAssets when the id is empty (onboarding or reset), avoiding pointless fetches against a cleared tree. Tests cover map clearing, the empty-group event payload, and the assets no-op path.

Reviewed by Cursor Bugbot for commit 9b0921f. Bugbot is set up for automated code reviews on this repo. Configure here.

@ccharly
ccharly marked this pull request as ready for review August 11, 2026 18:30
@ccharly
ccharly requested review from a team as code owners August 11, 2026 18:30

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 659e648. Configure here.

Comment thread packages/assets-controller/src/AssetsController.ts Outdated
@salimtb

salimtb commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.6.1-preview-9b0921f9b
@metamask-previews/accounts-controller@39.1.0-preview-9b0921f9b
@metamask-previews/address-book-controller@7.1.2-preview-9b0921f9b
@metamask-previews/ai-controllers@0.8.0-preview-9b0921f9b
@metamask-previews/analytics-controller@2.0.0-preview-9b0921f9b
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-9b0921f9b
@metamask-previews/announcement-controller@8.1.0-preview-9b0921f9b
@metamask-previews/app-metadata-controller@2.0.1-preview-9b0921f9b
@metamask-previews/approval-controller@9.0.2-preview-9b0921f9b
@metamask-previews/assets-controller@13.1.2-preview-9b0921f9b
@metamask-previews/assets-controllers@111.1.0-preview-9b0921f9b
@metamask-previews/authenticated-user-storage@3.0.1-preview-9b0921f9b
@metamask-previews/base-controller@9.1.0-preview-9b0921f9b
@metamask-previews/base-data-service@0.1.3-preview-9b0921f9b
@metamask-previews/bitcoin-regtest-up@1.0.0-preview-9b0921f9b
@metamask-previews/bridge-controller@79.2.0-preview-9b0921f9b
@metamask-previews/bridge-status-controller@75.1.0-preview-9b0921f9b
@metamask-previews/build-utils@3.0.4-preview-9b0921f9b
@metamask-previews/chain-agnostic-permission@1.7.0-preview-9b0921f9b
@metamask-previews/chomp-api-service@4.0.0-preview-9b0921f9b
@metamask-previews/claims-controller@0.6.0-preview-9b0921f9b
@metamask-previews/client-controller@1.0.1-preview-9b0921f9b
@metamask-previews/client-utils@2.0.2-preview-9b0921f9b
@metamask-previews/compliance-controller@2.1.0-preview-9b0921f9b
@metamask-previews/composable-controller@12.0.1-preview-9b0921f9b
@metamask-previews/config-registry-controller@2.0.1-preview-9b0921f9b
@metamask-previews/connectivity-controller@0.3.0-preview-9b0921f9b
@metamask-previews/controller-utils@12.3.0-preview-9b0921f9b
@metamask-previews/core-backend@8.1.1-preview-9b0921f9b
@metamask-previews/delegation-controller@3.0.2-preview-9b0921f9b
@metamask-previews/earn-controller@12.2.4-preview-9b0921f9b
@metamask-previews/eip-5792-middleware@3.0.5-preview-9b0921f9b
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-9b0921f9b
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-9b0921f9b
@metamask-previews/ens-controller@19.1.6-preview-9b0921f9b
@metamask-previews/eth-block-tracker@15.0.1-preview-9b0921f9b
@metamask-previews/eth-json-rpc-middleware@24.0.0-preview-9b0921f9b
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-9b0921f9b
@metamask-previews/foundryup@1.0.1-preview-9b0921f9b
@metamask-previews/gas-fee-controller@26.3.1-preview-9b0921f9b
@metamask-previews/gator-permissions-controller@5.0.1-preview-9b0921f9b
@metamask-previews/geolocation-controller@1.0.0-preview-9b0921f9b
@metamask-previews/java-tron-up@1.0.0-preview-9b0921f9b
@metamask-previews/json-rpc-engine@10.5.0-preview-9b0921f9b
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-9b0921f9b
@metamask-previews/keyring-controller@27.1.1-preview-9b0921f9b
@metamask-previews/kyc-controller@0.0.0-preview-9b0921f9b
@metamask-previews/local-node-utils@1.0.0-preview-9b0921f9b
@metamask-previews/logging-controller@9.0.0-preview-9b0921f9b
@metamask-previews/message-manager@14.1.2-preview-9b0921f9b
@metamask-previews/messenger@2.0.0-preview-9b0921f9b
@metamask-previews/messenger-cli@0.2.0-preview-9b0921f9b
@metamask-previews/money-account-api-data-service@0.4.0-preview-9b0921f9b
@metamask-previews/money-account-balance-service@2.4.1-preview-9b0921f9b
@metamask-previews/money-account-controller@1.0.0-preview-9b0921f9b
@metamask-previews/money-account-upgrade-controller@3.0.1-preview-9b0921f9b
@metamask-previews/money-account-utils@1.1.0-preview-9b0921f9b
@metamask-previews/multichain-account-service@13.0.1-preview-9b0921f9b
@metamask-previews/multichain-api-middleware@4.0.2-preview-9b0921f9b
@metamask-previews/multichain-network-controller@3.2.3-preview-9b0921f9b
@metamask-previews/multichain-transactions-controller@7.1.2-preview-9b0921f9b
@metamask-previews/name-controller@9.1.2-preview-9b0921f9b
@metamask-previews/network-connection-banner-controller@0.1.2-preview-9b0921f9b
@metamask-previews/network-controller@35.0.1-preview-9b0921f9b
@metamask-previews/network-enablement-controller@6.0.3-preview-9b0921f9b
@metamask-previews/notification-services-controller@26.0.1-preview-9b0921f9b
@metamask-previews/passkey-controller@3.0.0-preview-9b0921f9b
@metamask-previews/permission-controller@13.1.1-preview-9b0921f9b
@metamask-previews/permission-log-controller@5.1.0-preview-9b0921f9b
@metamask-previews/perps-controller@11.0.0-preview-9b0921f9b
@metamask-previews/phishing-controller@17.3.1-preview-9b0921f9b
@metamask-previews/platform-api-docs@0.0.0-preview-9b0921f9b
@metamask-previews/polling-controller@16.0.9-preview-9b0921f9b
@metamask-previews/preferences-controller@23.1.0-preview-9b0921f9b
@metamask-previews/profile-metrics-controller@4.0.3-preview-9b0921f9b
@metamask-previews/profile-sync-controller@29.0.0-preview-9b0921f9b
@metamask-previews/ramps-controller@20.0.0-preview-9b0921f9b
@metamask-previews/rate-limit-controller@7.0.1-preview-9b0921f9b
@metamask-previews/react-data-query@0.2.2-preview-9b0921f9b
@metamask-previews/remote-feature-flag-controller@5.0.0-preview-9b0921f9b
@metamask-previews/sample-controllers@5.0.4-preview-9b0921f9b
@metamask-previews/seedless-onboarding-controller@10.1.1-preview-9b0921f9b
@metamask-previews/selected-network-controller@26.1.6-preview-9b0921f9b
@metamask-previews/sentinel-api-service@1.0.0-preview-9b0921f9b
@metamask-previews/shield-controller@6.0.0-preview-9b0921f9b
@metamask-previews/signature-controller@39.2.9-preview-9b0921f9b
@metamask-previews/smart-transactions-controller@25.1.0-preview-9b0921f9b
@metamask-previews/snap-account-service@2.1.2-preview-9b0921f9b
@metamask-previews/social-controllers@2.7.1-preview-9b0921f9b
@metamask-previews/solana-test-validator-up@1.0.0-preview-9b0921f9b
@metamask-previews/stellar-quickstart-up@0.0.0-preview-9b0921f9b
@metamask-previews/storage-service@1.0.2-preview-9b0921f9b
@metamask-previews/subscription-controller@7.0.0-preview-9b0921f9b
@metamask-previews/transaction-controller@69.5.2-preview-9b0921f9b
@metamask-previews/transaction-pay-controller@26.3.0-preview-9b0921f9b
@metamask-previews/user-operation-controller@41.2.8-preview-9b0921f9b
@metamask-previews/wallet@10.0.0-preview-9b0921f9b
@metamask-previews/wallet-cli@0.0.0-preview-9b0921f9b

@salimtb salimtb left a comment

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.

tested using a local build, LGTM

@ccharly
ccharly added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit 174c116 Aug 13, 2026
144 checks passed
@ccharly
ccharly deleted the cc/fix/account-tree-clear-state branch August 13, 2026 14:56
@maxime-oe maxime-oe mentioned this pull request Aug 13, 2026
4 tasks
pull Bot pushed a commit to dmrazzy/core that referenced this pull request Aug 13, 2026
## Explanation

## Assets Controller [13.1.3]

### Changed

- Bump `@metamask/transaction-controller` from `^69.5.1` to `^69.5.2`
([MetaMask#9823](MetaMask#9823))

### Fixed

- Fix Arc native USDC never appearing until the account receives its
first deposit, by default-tracking the native asset id
(`eip155:5042/slip44:5042`) instead of the `0x3600...` ERC20 identity so
`assetsInfo` metadata is seeded up front
([MetaMask#9869](MetaMask#9869))
- Properly filter empty (`''`) selected account group event
([MetaMask#9825](MetaMask#9825))

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> <sup>[Cursor Bugbot](https://cursor.com/bugbot) is generating a
summary for commit 444cbe4. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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