Persist active account selection across app restarts - #110
Open
asherp wants to merge 1 commit into
Open
Conversation
The active account was only ever held in memory (AppState.current_private_key), so on restart the backend started with no active account. keychain_get_active_account returned None, and the frontend fell back to accounts[0] — an arbitrary entry from the keychain vault's HashMap, which has no stable order. The result: after a restart the app could load a different user than the one that was active before. Persist the active pubkey in the keychain vault (new Vault.active field, with serde(default) for backward compatibility) whenever an account is made active, and restore it into memory on cold start. keychain_get_active_account now returns the previously-active account after a restart instead of None. - keychain.rs: add Vault.active, set_active/get_active, and clear the pointer when the active key is deleted. Add serde round-trip / legacy-compat unit tests. - lib.rs: extract activate_account_in_memory helper; set_active_account persists the choice; get_active_account restores the persisted account on cold start. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016iwHXKaFc8y3GhMDLDJueS
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.
Summary
This PR adds persistence for the active account selection in the keychain manager. When a user switches to a different account, that choice is now saved and automatically restored when the app restarts, instead of losing the selection or picking an arbitrary account.
Key Changes
activefield to track the public key of the currently active account, with#[serde(default)]for backward compatibility with older vault filesset_active(): Persists the active account pointer (validates the key exists first)get_active(): Retrieves the persisted active account, returningNoneif the pointer is unset or staledelete_key()to clear the active pointer if the deleted key was activeactivate_account_in_memory()helper to load a key into in-memory state, used by both initial activation and cold-start restorationkeychain_get_active_account()now implements a two-tier lookup:Implementation Details
activefield is optional and defaults toNonefor backward compatibility—older vault files without this field will deserialize correctlyNoneset_active()are logged as warnings but don't block the session—the account remains active in memoryhttps://claude.ai/code/session_016iwHXKaFc8y3GhMDLDJueS