fix: expose refreshAiGatewayVirtualKey for stale key recovery#270
Merged
dimavedenyapin merged 3 commits intomainfrom Apr 27, 2026
Merged
fix: expose refreshAiGatewayVirtualKey for stale key recovery#270dimavedenyapin merged 3 commits intomainfrom
dimavedenyapin merged 3 commits intomainfrom
Conversation
Add refreshAiGatewayVirtualKey() to EnterpriseAuth so callers (IPC handlers, adapter error recovery) can trigger a key refresh when LiteLLM returns "Invalid proxy server token" during a session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When an admin rotates the user's virtual key (via plan removal + re- assignment), the desktop's local SQLite cache still holds the old key. Now the agent-manager calls refreshAiGatewayVirtualKey() before each session start so the adapter always builds its provider config with the latest key from the backend. Best-effort — falls back to the cached key if the refresh fails (offline, server down). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ensureServerRunning() early-returns when the server is already running at the target URL, which skips the initial config push. This means rotated provider credentials (e.g. a new LiteLLM virtual key after plan re- assignment) never reach the running server. Now createSession() always calls pushMergedConfigToClient() after ensureServerRunning(), so the OpenCode provider config reflects the latest key fetched by refreshAiGatewayVirtualKey() in agent-manager. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Fixes "Invalid proxy server token" auth errors when an admin rotates a user's AI gateway virtual key (removes and re-assigns a plan). Three changes work together:
refreshAiGatewayVirtualKey()onEnterpriseAuthso callers can trigger a key refresh on demandAgentManager.startAdapterSession()calls the refresh so the local SQLite cache always has the latest key from the backendcreateSession()now callspushMergedConfigToClient()afterensureServerRunning(), becauseensureServerRunningearly-returns when the server is already up, skipping the config push that bakes provider credentialsRelated PR
fetchExistingDynamicKeyso stale keys are cleaned up and regenerated server-sideTest plan
🤖 Generated with Claude Code