@@ -140,9 +140,17 @@ export class Task extends EventEmitter<ClineEvents> {
140140 // API
141141 readonly apiConfiguration : ProviderSettings
142142 api : ApiHandler
143- private lastApiRequestTime ?: number
143+ private static lastGlobalApiRequestTime ?: number
144144 private consecutiveAutoApprovedRequestsCount : number = 0
145145
146+ /**
147+ * Reset the global API request timestamp. This should only be used for testing.
148+ * @internal
149+ */
150+ static resetGlobalApiRequestTime ( ) : void {
151+ Task . lastGlobalApiRequestTime = undefined
152+ }
153+
146154 toolRepetitionDetector : ToolRepetitionDetector
147155 rooIgnoreController ?: RooIgnoreController
148156 rooProtectedController ?: RooProtectedController
@@ -1657,10 +1665,11 @@ export class Task extends EventEmitter<ClineEvents> {
16571665
16581666 let rateLimitDelay = 0
16591667
1660- // Only apply rate limiting if this isn't the first request
1661- if ( this . lastApiRequestTime ) {
1668+ // Use the shared timestamp so that subtasks respect the same rate-limit
1669+ // window as their parent tasks.
1670+ if ( Task . lastGlobalApiRequestTime ) {
16621671 const now = Date . now ( )
1663- const timeSinceLastRequest = now - this . lastApiRequestTime
1672+ const timeSinceLastRequest = now - Task . lastGlobalApiRequestTime
16641673 const rateLimit = apiConfiguration ?. rateLimitSeconds || 0
16651674 rateLimitDelay = Math . ceil ( Math . max ( 0 , rateLimit * 1000 - timeSinceLastRequest ) / 1000 )
16661675 }
@@ -1675,8 +1684,9 @@ export class Task extends EventEmitter<ClineEvents> {
16751684 }
16761685 }
16771686
1678- // Update last request time before making the request
1679- this . lastApiRequestTime = Date . now ( )
1687+ // Update last request time before making the request so that subsequent
1688+ // requests — even from new subtasks — will honour the provider's rate-limit.
1689+ Task . lastGlobalApiRequestTime = Date . now ( )
16801690
16811691 const systemPrompt = await this . getSystemPrompt ( )
16821692 const { contextTokens } = this . getTokenUsage ( )
0 commit comments