feat(keyring-controller): persist vault when keyring state changes during unlock#8415
Merged
feat(keyring-controller): persist vault when keyring state changes during unlock#8415
Conversation
…ring unlock Introduces `hasStateChanged` helper and uses it to detect when a keyring's serialized state differs from what was stored in the vault. If any keyring changed during deserialization (e.g. ran a migration, or was missing metadata), the vault is re-persisted via the existing upgrade path in `submitPassword`/`submitEncryptionKey`. Also removes the now-redundant `isEqual` import from lodash.
…low serialize() Eagerly stringify session state before the operation so that subsequent mutations to keyring-internal arrays (e.g. MockShallowKeyring) cannot retroactively change the snapshot used for comparison. Also removes the now-unnecessary `hasStateChanged` helper.
…alization state change
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 010a2d8. Configure here.
ccharly
reviewed
Apr 10, 2026
ccharly
reviewed
Apr 10, 2026
…n-place mutations
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
Currently, if a keyring runs a migration inside
deserialize()during unlock, the updated in-memory state is never written back to the vault. On the next unlock the migration silently re-runs against the same stale data.This PR fixes that by comparing each keyring's re-serialized state against the original data after
#restoreKeyring. If any keyring's state differs — whether due to a migration or missing metadata —hasChangedis propagated up through#restoreSerializedKeyringsand#unlockKeyrings, and the existing vault upgrade path insubmitPassword/submitEncryptionKeyre-persists the vault.As part of this change, a
hasStateChangedhelper function is introduced and reused in#persistOrRollback, removing the dependency on lodashisEqualfor that comparison.References
Checklist
Note
Medium Risk
Touches the unlock/vault-update path to trigger re-encryption/persistence based on detected keyring state changes, which could affect login performance and vault write frequency if the change detection is wrong.
Overview
During
submitPassword/submitEncryptionKey, the controller now tracks whether any keyring’s serialized data changes during restore (including missing metadata) and, if so, re-runs the existing vault update flow to persist the upgraded state.Change detection is implemented in
#restoreKeyringby comparing pre- and post-deserialization serialized payloads and is propagated via#restoreSerializedKeyrings/#unlockKeyringsashasChanged;#persistOrRollbackalso switches from lodashisEqualto a JSON-string comparison for session-state diffs. Adds a regression test for an in-place migrating keyring and updates the changelog.Reviewed by Cursor Bugbot for commit 6e75026. Bugbot is set up for automated code reviews on this repo. Configure here.