-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(settings): add rate limit control for Profile configuration #1785
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
Closed
olweraltuve
wants to merge
7
commits into
RooCodeInc:main
from
olweraltuve:rate-limit-profile-specificv3
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9efc90d
feat(settings): add rate limit control for API configuration
olweraltuve 474c177
fix
olweraltuve 68f50fa
fix
olweraltuve 95bd374
Merge branch 'main' into rate-limit-profile-specificv3
olweraltuve 2f4873a
Merge branch 'main' into rate-limit-profile-specificv3
olweraltuve 1356f0d
feat(config): implement rate limit migration for API configurations
olweraltuve 733f2de
fix(tests): enhance ConfigManager tests with global state mocking
olweraltuve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ export interface ApiConfigData { | |
| [key: string]: ApiConfiguration | ||
| } | ||
| modeApiConfigs?: Partial<Record<Mode, string>> | ||
| migrations?: { | ||
| rateLimitMigrated?: boolean // Flag to track if rate limit migration has been applied | ||
| } | ||
| } | ||
|
|
||
| export class ConfigManager { | ||
|
|
@@ -17,8 +20,12 @@ export class ConfigManager { | |
| apiConfigs: { | ||
| default: { | ||
| id: this.generateId(), | ||
| rateLimitSeconds: 0, // Set default rate limit for new installations | ||
| }, | ||
| }, | ||
| migrations: { | ||
| rateLimitMigrated: true, // Mark as migrated for fresh installs | ||
| }, | ||
| } | ||
|
|
||
| private readonly SCOPE_PREFIX = "roo_cline_config_" | ||
|
|
@@ -52,15 +59,28 @@ export class ConfigManager { | |
| return | ||
| } | ||
|
|
||
| // Migrate: ensure all configs have IDs | ||
| // Initialize migrations tracking object if it doesn't exist | ||
| if (!config.migrations) { | ||
| config.migrations = {} | ||
| } | ||
|
|
||
| let needsMigration = false | ||
|
|
||
| // Migrate: ensure all configs have IDs | ||
| for (const [name, apiConfig] of Object.entries(config.apiConfigs)) { | ||
| if (!apiConfig.id) { | ||
| apiConfig.id = this.generateId() | ||
| needsMigration = true | ||
| } | ||
| } | ||
|
|
||
| // Apply rate limit migration if needed | ||
| if (!config.migrations.rateLimitMigrated) { | ||
| await this.migrateRateLimit(config) | ||
| config.migrations.rateLimitMigrated = true | ||
| needsMigration = true | ||
| } | ||
|
|
||
| if (needsMigration) { | ||
| await this.writeConfig(config) | ||
| } | ||
|
|
@@ -70,6 +90,43 @@ export class ConfigManager { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Migrate rate limit settings from global state to per-profile configuration | ||
| */ | ||
| private async migrateRateLimit(config: ApiConfigData): Promise<void> { | ||
| try { | ||
| // Get the global rate limit value from extension state | ||
| let rateLimitSeconds: number | undefined | ||
|
|
||
| try { | ||
| // Try to get global state rate limit | ||
| rateLimitSeconds = await this.context.globalState.get<number>("rateLimitSeconds") | ||
| console.log(`[RateLimitMigration] Found global rate limit value: ${rateLimitSeconds}`) | ||
| } catch (error) { | ||
| console.error("[RateLimitMigration] Error getting global rate limit:", error) | ||
| } | ||
|
|
||
| // If no global rate limit, use default value of 5 seconds | ||
| if (rateLimitSeconds === undefined) { | ||
| rateLimitSeconds = 5 // Default value | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default should be 0 |
||
| console.log(`[RateLimitMigration] Using default rate limit value: ${rateLimitSeconds}`) | ||
| } | ||
|
|
||
| // Apply the rate limit to all API configurations | ||
| for (const [name, apiConfig] of Object.entries(config.apiConfigs)) { | ||
| // Only set if not already configured | ||
| if (apiConfig.rateLimitSeconds === undefined) { | ||
| console.log(`[RateLimitMigration] Applying rate limit ${rateLimitSeconds}s to profile: ${name}`) | ||
| apiConfig.rateLimitSeconds = rateLimitSeconds | ||
| } | ||
| } | ||
|
|
||
| console.log(`[RateLimitMigration] Migration complete`) | ||
| } catch (error) { | ||
| console.error(`[RateLimitMigration] Failed to migrate rate limit settings:`, error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * List all available configs with metadata | ||
| */ | ||
|
|
@@ -96,6 +153,48 @@ export class ConfigManager { | |
| return await this.lock(async () => { | ||
| const currentConfig = await this.readConfig() | ||
| const existingConfig = currentConfig.apiConfigs[name] | ||
|
|
||
| // If this is a new config or doesn't have rate limit, try to apply the global rate limit | ||
| if (!existingConfig || config.rateLimitSeconds === undefined) { | ||
| // Apply rate limit if not specified explicitly in the config being saved | ||
| if (config.rateLimitSeconds === undefined) { | ||
| let globalRateLimit: number | undefined | ||
|
|
||
| // First check if we have an existing migrated config to copy from | ||
| const anyExistingConfig = Object.values(currentConfig.apiConfigs)[0] | ||
| if (anyExistingConfig?.rateLimitSeconds !== undefined) { | ||
| globalRateLimit = anyExistingConfig.rateLimitSeconds | ||
| console.log( | ||
| `[RateLimitMigration] Using existing profile's rate limit value: ${globalRateLimit}s`, | ||
| ) | ||
| } else { | ||
| // Otherwise check global state | ||
| try { | ||
| globalRateLimit = await this.context.globalState.get<number>("rateLimitSeconds") | ||
| console.log( | ||
| `[RateLimitMigration] Using global rate limit for new profile: ${globalRateLimit}s`, | ||
| ) | ||
| } catch (error) { | ||
| console.error( | ||
| "[RateLimitMigration] Error getting global rate limit for new profile:", | ||
| error, | ||
| ) | ||
| } | ||
|
|
||
| // Use default if not found | ||
| if (globalRateLimit === undefined) { | ||
| globalRateLimit = 5 // Default value | ||
| console.log( | ||
| `[RateLimitMigration] Using default rate limit value for new profile: ${globalRateLimit}s`, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Apply the rate limit to the new config | ||
| config.rateLimitSeconds = globalRateLimit | ||
| } | ||
| } | ||
|
Comment on lines
+157
to
+196
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need this code. After we do the migration, we should just remove the idea of a global rate limit. |
||
|
|
||
| currentConfig.apiConfigs[name] = { | ||
| ...config, | ||
| id: existingConfig?.id || this.generateId(), | ||
|
|
||
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
Oops, something went wrong.
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.
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 should clear out the global state rate limit too right?