fix: resolve current account switching issue for agy CLI and target environments#3186
Open
fedorovmv wants to merge 7 commits into
Open
fix: resolve current account switching issue for agy CLI and target environments#3186fedorovmv wants to merge 7 commits into
fedorovmv wants to merge 7 commits into
Conversation
…are account updates
…g automatically and preserve agy target on switch
…timize DashMap locking
# Conflicts: # src-tauri/src/modules/account.rs
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 addresses an issue where switching the active account for the
agyCLI (or custom IDE targets) is immediately reverted or lost in the Manager's UI due to background database synchronization (sync_account_from_db).Root Cause
AccountIndexstructure only storedcurrent_account_idglobally, without any concept of which target IDE or CLI environment was active.agyCLI, the Manager successfully updated the system Keyring and set the globalcurrent_account_idto the new account.agyCLI has no local SQLite database (state.vscdb), the classic VS Code SQLite database remained on the old account.sync_account_from_db) periodically polled the classic SQLite database. Seeing a mismatch between the Manager's global active account (newly switched foragy) and the classic database (old account), it erroneously concluded that the user switched accounts inside VS Code, and revertedcurrent_account_idback to the old account.Solution
To fix this, we introduced the concept of target IDE context into the Manager's state and enhanced the system keyring synchronization workflow:
current_target_idefield to theAccountIndexmodel (None/Some("classic"),Some("ide"), orSome("agy")).switch_accountcore logic now captures and persists the target environment (target_ide) of the user's last action incurrent_target_ide. If the switch target isNone(e.g., switched from the main dashboard), the Manager preserves the currently active CLI target (likeagy) instead of discarding it.Some("agy")(CLI), the background sync task is skipped becauseagyuses the system Keyring rather than a database file.Some("ide"), the sync process reads the Antigravity IDE database.synchronize_keyringhelper to coordinate system keyring writes/deletions. The keyring is automatically updated during:set_current_account_id_with_target).add_account).delete_account,delete_accounts).TokenManager::save_refreshed_tokenwhenever the refreshed token belongs to the active active account. This ensures CLI clients (likeagy) always have fresh, non-expired credentials.TokenManager::save_refreshed_tokento clone the account path and release the DashMap read-lock immediately before performing blocking disk IO and keyring command executions, resolving potential shard lock contention.on_account_switchto avoid double-writing during switches.test_set_current_account_id_with_target) that isolates file operations and verifies target-aware account and environment state changes.Why not sync the CLI by reading the Keyring?
Reading from the macOS Keychain (and some Linux Keyrings) inside a background loop is highly problematic:
agyCLI binary), attempting to read them programmatically via Tauri or CLI tools frequently triggers system-level security prompts (OS keychain dialogs asking the user for their password or to click "Allow").How is the IDE Database checked?
Some("ide"), the database path helper (db::get_db_path) is called with the target parameter, which maps to the Antigravity IDE data directory (e.g.,~/Library/Application Support/Antigravity IDE/...) instead of the default Antigravity directory.Why this approach?
Instead of completely redesigning the UI to show multiple current accounts per environment (which would require a massive overhaul of the frontend components and state), tracking the user's last-switched target context (
current_target_ide) is:accounts.jsonconfigs parse correctly.