@@ -2331,21 +2331,22 @@ while (attempted.size < Math.max(1, accountCount)) {
23312331 }
23322332
23332333 try {
2334- // Request metrics are tracked at the fetch boundary, so retries and account
2335- // rotation are counted consistently. This is in-memory only: no filesystem I/O,
2336- // no token persistence, and prompt-cache keys stay redacted in doctor output.
2337- runtimeMetrics . totalRequests ++ ;
2338- if ( promptCacheKey ) {
2339- runtimeMetrics . promptCacheEnabledRequests ++ ;
2340- } else {
2341- runtimeMetrics . promptCacheMissingRequests ++ ;
2342- }
2343- response = await fetch ( url , {
2344- ...requestInit ,
2345- headers,
2334+ // Request metrics are tracked at the fetch boundary, so retries and
2335+ // account rotation are counted consistently. These increments are
2336+ // in-memory only and run on Node's single-threaded event loop, so no
2337+ // filesystem locking or token-redaction concerns are introduced here.
2338+ runtimeMetrics . totalRequests ++ ;
2339+ if ( promptCacheKey ) {
2340+ runtimeMetrics . promptCacheEnabledRequests ++ ;
2341+ } else {
2342+ runtimeMetrics . promptCacheMissingRequests ++ ;
2343+ }
2344+ response = await fetch ( url , {
2345+ ...requestInit ,
2346+ headers,
23462347 signal : fetchController . signal ,
23472348 } ) ;
2348- } catch ( networkError ) {
2349+ } catch ( networkError ) {
23492350 const errorMsg = networkError instanceof Error ? networkError . message : String ( networkError ) ;
23502351 logWarn ( `Network error for account ${ account . index + 1 } : ${ errorMsg } ` ) ;
23512352 if (
@@ -2378,21 +2379,21 @@ while (attempted.size < Math.max(1, accountCount)) {
23782379 accountManager . refundToken ( account , modelFamily , model ) ;
23792380 accountManager . recordFailure ( account , modelFamily , model ) ;
23802381 break ;
2381- } finally {
2382- clearTimeout ( fetchTimeoutId ) ;
2383- if ( abortSignal && onUserAbort ) {
2384- abortSignal . removeEventListener ( "abort" , onUserAbort ) ;
2385- }
2382+ } finally {
2383+ clearTimeout ( fetchTimeoutId ) ;
2384+ if ( abortSignal && onUserAbort ) {
2385+ abortSignal . removeEventListener ( "abort" , onUserAbort ) ;
23862386 }
2387- const fetchLatencyMs = Math . round ( performance . now ( ) - fetchStart ) ;
2388-
2389- logRequest ( LOG_STAGES . RESPONSE , {
2390- status : response . status ,
2391- ok : response . ok ,
2392- statusText : response . statusText ,
2393- latencyMs : fetchLatencyMs ,
2394- headers : Object . fromEntries ( response . headers . entries ( ) ) ,
2395- } ) ;
2387+ }
2388+ const fetchLatencyMs = Math . round ( performance . now ( ) - fetchStart ) ;
2389+
2390+ logRequest ( LOG_STAGES . RESPONSE , {
2391+ status : response . status ,
2392+ ok : response . ok ,
2393+ statusText : response . statusText ,
2394+ latencyMs : fetchLatencyMs ,
2395+ headers : Object . fromEntries ( response . headers . entries ( ) ) ,
2396+ } ) ;
23962397
23972398 if ( ! response . ok ) {
23982399 const contextOverflowResult = await handleContextOverflow ( response , model ) ;
0 commit comments