@@ -592,7 +592,7 @@ async function retryCodexPoolOnAlternateAccount(
592592 invalidateCodexModelEntitlementsForAccount ( firstAuthCtx . accountId ) ;
593593 const refreshed = await resolveCodexModelEntitlements ( config ) ;
594594 if ( entitledCodexAccountIdsForModel ( refreshed , route . modelId ) ?. has ( firstAuthCtx . accountId ) ) {
595- // The authenticated roster still grants this exact model. Retry once on the same account:
595+ // The authenticated roster still grants this exact model. Retry on the same account:
596596 // upstream shards can briefly disagree during a gated-model rollout, but a pre-stream 400
597597 // proves no output was committed and keeps this replay bounded.
598598 retryAuthCtx = firstAuthCtx ;
@@ -693,27 +693,50 @@ async function retryCodexPoolOnAlternateAccount(
693693 logCtx . accountLogLabel ,
694694 ) ;
695695
696- noteAttemptSend ( logCtx . activeAttempt , passthroughEstimate ) ;
696+ const retrySameConfirmedAccount = outcomeStatus === 400
697+ && ACCOUNT_GATED_NATIVE_OPENAI_MODELS . has ( route . modelId )
698+ && retryAuthCtx . accountId === firstAuthCtx . accountId ;
699+ // Live Daybreak traffic has produced long runs of unsupported-model 400s from different
700+ // upstream shards even while the authenticated roster continues to grant the model. Permit
701+ // seven additional same-account sends (eight total including the original), re-checking the
702+ // exact allow-listed body and fresh entitlement before every later send. Alternate-account and
703+ // quota recovery retain their historical one-send bound.
704+ const maxRetrySends = retrySameConfirmedAccount ? 7 : 1 ;
705+ let retrySendCount = 0 ;
697706 let upstreamResponse : Response ;
698707 try {
699- upstreamResponse = await fetchWithHeaderTimeout (
700- request . url ,
701- {
702- method : request . method ,
703- headers : request . headers ,
704- body : request . body ,
705- } ,
706- upstream . signal ,
707- connectMs ,
708- stream ,
709- providerFetch ( route . provider , options . codexWsRuntimeIdentity , {
710- providerName : route . providerName ,
711- modelId : route . modelId ,
712- } ) ,
713- // Credential-bearing forward send: never follow a redirect into a
714- // dead-host rejection after the credential was seen (#914).
715- route . provider . authMode === "forward" ,
716- ) ;
708+ while ( true ) {
709+ noteAttemptSend ( logCtx . activeAttempt , passthroughEstimate ) ;
710+ upstreamResponse = await fetchWithHeaderTimeout (
711+ request . url ,
712+ {
713+ method : request . method ,
714+ headers : request . headers ,
715+ body : request . body ,
716+ } ,
717+ upstream . signal ,
718+ connectMs ,
719+ stream ,
720+ providerFetch ( route . provider , options . codexWsRuntimeIdentity , {
721+ providerName : route . providerName ,
722+ modelId : route . modelId ,
723+ } ) ,
724+ // Credential-bearing forward send: never follow a redirect into a
725+ // dead-host rejection after the credential was seen (#914).
726+ route . provider . authMode === "forward" ,
727+ ) ;
728+ retrySendCount += 1 ;
729+ if ( ! retrySameConfirmedAccount || retrySendCount >= maxRetrySends ) break ;
730+ if ( ! await shouldRetryCodexPoolAccountModel400 (
731+ upstreamResponse ,
732+ route . modelId ,
733+ options . abortSignal ,
734+ ) ) break ;
735+ invalidateCodexModelEntitlementsForAccount ( retryAuthCtx . accountId ) ;
736+ const refreshed = await resolveCodexModelEntitlements ( config ) ;
737+ if ( ! entitledCodexAccountIdsForModel ( refreshed , route . modelId ) ?. has ( retryAuthCtx . accountId ) ) break ;
738+ await upstreamResponse . body ?. cancel ( ) . catch ( ( ) => undefined ) ;
739+ }
717740 } catch ( error ) {
718741 // Attribute the transport failure to the alternate account (already selected).
719742 return { kind : "transport" , error, authCtx : retryAuthCtx } ;
0 commit comments