feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
Merged
feat(keyring-controller): add withController for atomic operations over multiple keyrings#8416
withController for atomic operations over multiple keyrings#8416Conversation
e1b0a6b to
001d092
Compare
withController for atomic operations over multiple keyrings
b74e2c3 to
02a9fac
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ 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 02a9fac. Configure here.
21276f6 to
0f03c1f
Compare
…er multiple keyrings
0f03c1f to
7fa0b28
Compare
hmalik88
reviewed
Apr 17, 2026
hmalik88
reviewed
Apr 17, 2026
hmalik88
reviewed
Apr 17, 2026
hmalik88
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Explanation
Today there's no way to make multiple operations in an "atomic" (read transactional) way.
A good example of this is if you want to use a keyring using
withKeyringthat's not existing yet (I'm omitting thecreateIfMissingvariants, as we wanted to move away from this pattern).To do this in a safe way, you usually have to use your own lock to make sure you can get-or-create the keyring and prevent concurrent keyring creations.
This new
withControlleris based on thewithKeyringbut with an access to a "restricted" state and methods of the controller. This way, you can interact with multiple keyring at once while being guarded (to prevent race-conditions) by the controller's global lock.The former problem can then be written that way now:
This will also be used to write the migration from the existing
SnapKeyring(1 for ALL Snaps) to multipleSnapKeyring(1 PER Snap) in a safe way like:References
N/A
Checklist
Note
Medium Risk
Adds a new transactional API that can create/remove keyrings and then persist/rollback state, which touches keyring lifecycle and vault persistence paths. Risk is moderate due to potential edge cases around staged mutations, keyring destruction, and primary keyring protection.
Overview
Adds
KeyringController.withController(and messenger actionKeyringController:withController) to run single-lock, atomic operations across multiple keyrings via aRestrictedControllerthat exposes a live read-only view plus stagedaddNewKeyring/removeKeyringmutations.On success it commits staged keyring list changes, persists via existing persist/rollback flow, and destroys removed keyrings; on error it rolls back and destroys any newly created keyrings. The PR also blocks removal of the primary HD keyring (
CannotRemovePrimaryKeyring), extendsKeyringEntry/callback typings, updates mocks to includedestroy, and adds comprehensive unit + messenger tests for the new behavior.Reviewed by Cursor Bugbot for commit 0ae24f6. Bugbot is set up for automated code reviews on this repo. Configure here.