From f3caed71072da9105e762862e22819c996b77f29 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 22 Dec 2025 13:35:55 +0000 Subject: [PATCH] fix: use task stored API config as fallback for rate limit When provider state is unavailable (state is undefined/null), fall back to the task's stored apiConfiguration for rate limiting instead of defaulting to 0. This prevents rate limiting from being silently disabled in edge cases where getState() fails or provider reference is temporarily lost. Changes: - Line 3643 (attemptApiRequest): Use (apiConfiguration ?? this.apiConfiguration) - Line 3974 (backoffAndAnnounce): Use (state?.apiConfiguration ?? this.apiConfiguration) Both locations now follow the same pattern: 1. Prefer the most up-to-date config from provider state 2. Fall back to task's stored config if state unavailable 3. Only default to 0 if neither source has a config --- src/core/task/Task.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 92ea6aa957..5c8de3573e 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -3640,7 +3640,7 @@ export class Task extends EventEmitter implements TaskLike { if (Task.lastGlobalApiRequestTime) { const now = performance.now() const timeSinceLastRequest = now - Task.lastGlobalApiRequestTime - const rateLimit = apiConfiguration?.rateLimitSeconds || 0 + const rateLimit = (apiConfiguration ?? this.apiConfiguration)?.rateLimitSeconds || 0 rateLimitDelay = Math.ceil(Math.min(rateLimit, Math.max(0, rateLimit * 1000 - timeSinceLastRequest) / 1000)) } @@ -3971,7 +3971,7 @@ export class Task extends EventEmitter implements TaskLike { // Respect provider rate limit window let rateLimitDelay = 0 - const rateLimit = state?.apiConfiguration?.rateLimitSeconds || 0 + const rateLimit = (state?.apiConfiguration ?? this.apiConfiguration)?.rateLimitSeconds || 0 if (Task.lastGlobalApiRequestTime && rateLimit > 0) { const elapsed = performance.now() - Task.lastGlobalApiRequestTime rateLimitDelay = Math.ceil(Math.min(rateLimit, Math.max(0, rateLimit * 1000 - elapsed) / 1000))