Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit f3caed7

Browse files
committed
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
1 parent 2bb3755 commit f3caed7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/core/task/Task.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
36403640
if (Task.lastGlobalApiRequestTime) {
36413641
const now = performance.now()
36423642
const timeSinceLastRequest = now - Task.lastGlobalApiRequestTime
3643-
const rateLimit = apiConfiguration?.rateLimitSeconds || 0
3643+
const rateLimit = (apiConfiguration ?? this.apiConfiguration)?.rateLimitSeconds || 0
36443644
rateLimitDelay = Math.ceil(Math.min(rateLimit, Math.max(0, rateLimit * 1000 - timeSinceLastRequest) / 1000))
36453645
}
36463646

@@ -3971,7 +3971,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
39713971

39723972
// Respect provider rate limit window
39733973
let rateLimitDelay = 0
3974-
const rateLimit = state?.apiConfiguration?.rateLimitSeconds || 0
3974+
const rateLimit = (state?.apiConfiguration ?? this.apiConfiguration)?.rateLimitSeconds || 0
39753975
if (Task.lastGlobalApiRequestTime && rateLimit > 0) {
39763976
const elapsed = performance.now() - Task.lastGlobalApiRequestTime
39773977
rateLimitDelay = Math.ceil(Math.min(rateLimit, Math.max(0, rateLimit * 1000 - elapsed) / 1000))

0 commit comments

Comments
 (0)