-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: update task API configuration when Gemini API key changes #7091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Update task.apiConfiguration alongside task.api when provider settings change - Ensures Gemini API key is properly refreshed when changed mid-task - Add comprehensive test coverage for API key update scenarios Fixes #7090
…ange - Add updateApiConfiguration method to Task class to safely update config - Convert apiConfiguration to getter/setter pattern for controlled access - Update ClineProvider to use new method when updating provider settings - Ensure both API handler and configuration are updated together This ensures the Gemini API key (and other provider settings) are properly refreshed in active tasks when changed through the UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code because apparently I trust no one, not even myself.
* This is used when the provider settings change (e.g., API key update) | ||
*/ | ||
public updateApiConfiguration(newConfiguration: ProviderSettings): void { | ||
this._apiConfiguration = newConfiguration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactoring from readonly to getter/setter pattern is clean and maintains proper encapsulation. Good architectural choice.
|
||
// Verify that the task's API handler was updated | ||
expect(mockTask.api).toBeDefined() | ||
expect(mockTask.updateApiConfiguration).toHaveBeenCalledWith(newProviderSettings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent test coverage! These tests comprehensively verify the API configuration update behavior across all scenarios.
* Updates the API configuration and ensures consistency | ||
* This is used when the provider settings change (e.g., API key update) | ||
*/ | ||
public updateApiConfiguration(newConfiguration: ProviderSettings): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure this approach is actually sound: will updating the API key possibly lose the current context?
(Can I ping the bot to ask it to check this?)
@Ten0 Great question! The current implementation preserves the context because:
The key insight is that the API handler is stateless - it is just a mechanism to send requests. The actual conversation context and history are maintained by the Task class itself, so switching API handlers (even to a different key) will not lose any context. This is actually the same behavior that happens when users switch between different API providers mid-conversation - the context is preserved. |
I suspect this is not a problem with the settings not saving and rather a rate limit applied on the IP of the user, closing for now until more information is gathered |
That is not correct because the error specifies the rate limit that was hit and that corresponds to a free project's rate limit while the new api key is for a paid account. The issue is indeed that the credentials are saved on the task, so only a new task will have it use the new credentials. |
Summary
This PR fixes issue #7090 where the Gemini API key was not being properly refreshed in active tasks when changed through the UI.
Problem
When a user changed their Gemini API key after exceeding quota, the system continued using the old cached key, resulting in persistent quota exceeded errors even after updating to a new key.
Root Cause
The Task class was caching the API handler with the initial configuration but wasn't updating the configuration when provider settings changed. While the API handler was being updated in ClineProvider, the task's apiConfiguration property remained unchanged.
Solution
task.api = buildApiHandler()
andtask.updateApiConfiguration()
when provider settings changeTesting
Changes
Task
class to support configuration updatesClineProvider.upsertProviderProfile
andactivateProviderProfile
methodsClineProvider.gemini.spec.ts
Fixes #7090
Important
Fixes issue #7090 by updating
Task
API configuration when Gemini API key changes, with comprehensive tests added.Task
class:apiConfiguration
changed from readonly to getter/setter with private backing field.Task
class: AddedupdateApiConfiguration()
to update API configuration.ClineProvider
: Callstask.updateApiConfiguration()
when provider settings change.ClineProvider.gemini.spec.ts
to verify API key updates.This description was created by
for e507d13. You can customize this summary. It will automatically update as commits are pushed.