@@ -150,9 +150,17 @@ export class Task extends EventEmitter<ClineEvents> {
150150 // API
151151 readonly apiConfiguration : ProviderSettings
152152 api : ApiHandler
153- private lastApiRequestTime ?: number
153+ private static lastGlobalApiRequestTime ?: number
154154 private consecutiveAutoApprovedRequestsCount : number = 0
155155
156+ /**
157+ * Reset the global API request timestamp. This should only be used for testing.
158+ * @internal
159+ */
160+ static resetGlobalApiRequestTime ( ) : void {
161+ Task . lastGlobalApiRequestTime = undefined
162+ }
163+
156164 toolRepetitionDetector : ToolRepetitionDetector
157165 rooIgnoreController ?: RooIgnoreController
158166 rooProtectedController ?: RooProtectedController
@@ -1677,10 +1685,11 @@ export class Task extends EventEmitter<ClineEvents> {
16771685
16781686 let rateLimitDelay = 0
16791687
1680- // Only apply rate limiting if this isn't the first request
1681- if ( this . lastApiRequestTime ) {
1688+ // Use the shared timestamp so that subtasks respect the same rate-limit
1689+ // window as their parent tasks.
1690+ if ( Task . lastGlobalApiRequestTime ) {
16821691 const now = Date . now ( )
1683- const timeSinceLastRequest = now - this . lastApiRequestTime
1692+ const timeSinceLastRequest = now - Task . lastGlobalApiRequestTime
16841693 const rateLimit = apiConfiguration ?. rateLimitSeconds || 0
16851694 rateLimitDelay = Math . ceil ( Math . max ( 0 , rateLimit * 1000 - timeSinceLastRequest ) / 1000 )
16861695 }
@@ -1695,8 +1704,9 @@ export class Task extends EventEmitter<ClineEvents> {
16951704 }
16961705 }
16971706
1698- // Update last request time before making the request
1699- this . lastApiRequestTime = Date . now ( )
1707+ // Update last request time before making the request so that subsequent
1708+ // requests — even from new subtasks — will honour the provider's rate-limit.
1709+ Task . lastGlobalApiRequestTime = Date . now ( )
17001710
17011711 const systemPrompt = await this . getSystemPrompt ( )
17021712 const { contextTokens } = this . getTokenUsage ( )
0 commit comments