@@ -165,10 +165,21 @@ export class LimitsPresenter extends BasePresenter {
165165 where : { organizationId } ,
166166 } ) ;
167167
168+ const runtimeEnv = await this . _replica . runtimeEnvironment . findFirst ( {
169+ where : { id : environmentId } ,
170+ select : {
171+ id : true ,
172+ parentEnvironmentId : true ,
173+ maximumConcurrencyLimit : true ,
174+ concurrencyLimitBurstFactor : true ,
175+ } ,
176+ } ) ;
177+ const apiRateLimitEnvironmentId = runtimeEnv ?. parentEnvironmentId ?? environmentId ;
178+
168179 // Get current rate limit tokens for this environment's API bucket
169180 const apiRateLimitTokens = await getRateLimitRemainingTokens (
170181 "api" ,
171- environmentId ,
182+ apiRateLimitEnvironmentId ,
172183 apiRateLimitConfig
173184 ) ;
174185 // Batch rate limiter uses environment ID directly (not hashed) with a different key prefix
@@ -178,15 +189,6 @@ export class LimitsPresenter extends BasePresenter {
178189 ) ;
179190
180191 // Get current queue size for this environment
181- // We need the runtime environment fields for the engine query
182- const runtimeEnv = await this . _replica . runtimeEnvironment . findFirst ( {
183- where : { id : environmentId } ,
184- select : {
185- id : true ,
186- maximumConcurrencyLimit : true ,
187- concurrencyLimitBurstFactor : true ,
188- } ,
189- } ) ;
190192
191193 let currentQueueSize = 0 ;
192194 if ( runtimeEnv ) {
0 commit comments