@@ -158,7 +158,7 @@ import { paintUiText, formatUiBadge, formatUiHeader, formatUiItem, formatUiKeyVa
158158import {
159159 buildBeginnerChecklist ,
160160 buildBeginnerDoctorFindings ,
161- formatPromptCacheKey ,
161+ formatPromptCacheSnapshot ,
162162 recommendBeginnerNextAction ,
163163 summarizeBeginnerAccounts ,
164164 type BeginnerAccountSnapshot ,
@@ -2036,11 +2036,6 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
20362036 ) ;
20372037 runtimeMetrics . lastRequestAt = Date . now ( ) ;
20382038 runtimeMetrics . lastPromptCacheKey = promptCacheKey ?? null ;
2039- if ( promptCacheKey ) {
2040- runtimeMetrics . promptCacheEnabledRequests += 1 ;
2041- } else {
2042- runtimeMetrics . promptCacheMissingRequests += 1 ;
2043- }
20442039 const retryBudget = new RetryBudgetTracker ( retryBudgetLimits ) ;
20452040 const consumeRetryBudget = (
20462041 bucket : RetryBudgetClass ,
@@ -2329,17 +2324,25 @@ while (attempted.size < Math.max(1, accountCount)) {
23292324 : null ;
23302325
23312326 if ( abortSignal ?. aborted ) {
2332- clearTimeout ( fetchTimeoutId ) ;
2333- fetchController . abort ( abortSignal . reason ?? new Error ( "Aborted by user" ) ) ;
2334- } else if ( abortSignal && onUserAbort ) {
2335- abortSignal . addEventListener ( "abort" , onUserAbort , { once : true } ) ;
2336- }
2327+ clearTimeout ( fetchTimeoutId ) ;
2328+ fetchController . abort ( abortSignal . reason ?? new Error ( "Aborted by user" ) ) ;
2329+ } else if ( abortSignal && onUserAbort ) {
2330+ abortSignal . addEventListener ( "abort" , onUserAbort , { once : true } ) ;
2331+ }
23372332
2338- try {
2339- runtimeMetrics . totalRequests ++ ;
2340- response = await fetch ( url , {
2341- ...requestInit ,
2342- headers,
2333+ 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,
23432346 signal : fetchController . signal ,
23442347 } ) ;
23452348 } catch ( networkError ) {
@@ -5217,9 +5220,7 @@ while (attempted.size < Math.max(1, accountCount)) {
52175220 formatUiKeyValue (
52185221 ui ,
52195222 "Prompt cache" ,
5220- runtime . promptCacheEnabledRequests > 0
5221- ? `enabled=${ runtime . promptCacheEnabledRequests } , missing=${ runtime . promptCacheMissingRequests } , lastKey=${ formatPromptCacheKey ( runtime . lastPromptCacheKey ) } `
5222- : `enabled=0, missing=${ runtime . promptCacheMissingRequests } , lastKey=none` ,
5223+ formatPromptCacheSnapshot ( runtime ) ,
52235224 "muted" ,
52245225 ) ,
52255226 ) ;
@@ -5263,7 +5264,7 @@ while (attempted.size < Math.max(1, accountCount)) {
52635264 ` Runtime failures: failed=${ runtime . failedRequests } , rateLimited=${ runtime . rateLimitedResponses } , authRefreshFailed=${ runtime . authRefreshFailures } , server=${ runtime . serverErrors } , network=${ runtime . networkErrors } ` ,
52645265 ) ;
52655266 lines . push (
5266- ` Prompt cache: enabled= ${ runtime . promptCacheEnabledRequests } , missing= ${ runtime . promptCacheMissingRequests } , lastKey= ${ formatPromptCacheKey ( runtime . lastPromptCacheKey ) } ` ,
5267+ ` Prompt cache: ${ formatPromptCacheSnapshot ( runtime ) } ` ,
52675268 ) ;
52685269 }
52695270 return lines . join ( "\n" ) ;
0 commit comments