File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2131,6 +2131,19 @@ while (attempted.size < Math.max(1, accountCount)) {
21312131 refreshToken : fallbackAccount . refreshToken ,
21322132 index : fallbackAccount . index ,
21332133 } ) ;
2134+ const fallbackEntitlementBlock = entitlementCache . isBlocked (
2135+ fallbackEntitlementAccountKey ,
2136+ model ?? modelFamily ,
2137+ ) ;
2138+ if ( fallbackEntitlementBlock . blocked ) {
2139+ runtimeMetrics . accountRotations ++ ;
2140+ runtimeMetrics . lastError =
2141+ `Entitlement cached block for account ${ fallbackAccount . index + 1 } ` ;
2142+ logWarn (
2143+ `Skipping account ${ fallbackAccount . index + 1 } due to cached entitlement block (${ formatWaitTime ( fallbackEntitlementBlock . waitMs ) } remaining).` ,
2144+ ) ;
2145+ continue ;
2146+ }
21342147
21352148 if ( ! accountManager . consumeToken ( fallbackAccount , modelFamily , model ) ) {
21362149 continue ;
Original file line number Diff line number Diff line change @@ -121,16 +121,18 @@ vi.mock("../lib/accounts.js", async () => {
121121 source,
122122 storedEmail,
123123 accessToken,
124+ idToken,
124125 } : {
125126 storedAccountId ?: string ;
126127 source ?: string ;
127128 storedEmail ?: string ;
128129 accessToken ?: string ;
130+ idToken ?: string ;
129131 } ) => {
130132 const tokenUtilsModule = tokenUtils as typeof import ( "../lib/auth/token-utils.js" ) ;
131133 const tokenAccountId = accessToken ? "account-1" : undefined ;
132134 const tokenEmail = tokenUtilsModule . sanitizeEmail (
133- tokenUtilsModule . extractAccountEmail ( accessToken , undefined ) ,
135+ tokenUtilsModule . extractAccountEmail ( accessToken , idToken ) ,
134136 ) ;
135137 const sanitizedStoredEmail = tokenUtilsModule . sanitizeEmail ( storedEmail ) ;
136138 return {
Original file line number Diff line number Diff line change @@ -1240,19 +1240,22 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
12401240 } ) ;
12411241
12421242 it ( "uses the refreshed token email when checking entitlement blocks" , async ( ) => {
1243- mockStorage . accounts = [
1243+ const { AccountManager } = await import ( "../lib/accounts.js" ) ;
1244+ const manager = buildRoutingManager ( [
12441245 {
1246+ index : 0 ,
12451247 accountId : "acc-1" ,
12461248 email : "stale@example.com" ,
12471249 refreshToken : "refresh-1" ,
12481250 } ,
1249- ] ;
1251+ ] ) ;
1252+ vi . spyOn ( AccountManager , "loadFromDisk" ) . mockResolvedValueOnce ( manager as never ) ;
12501253 extractAccountEmailMock . mockReturnValueOnce ( "fresh@example.com" ) ;
12511254 const entitlementModule = await import ( "../lib/entitlement-cache.js" ) ;
12521255 const isBlockedSpy = vi
12531256 . spyOn ( entitlementModule . EntitlementCache . prototype , "isBlocked" )
12541257 . mockImplementation ( ( ) => {
1255- expect ( mockStorage . accounts [ 0 ] ?. email ) . toBe ( "stale@example.com" ) ;
1258+ expect ( manager . getAccountsSnapshot ( ) [ 0 ] ?. email ) . toBe ( "stale@example.com" ) ;
12561259 return { blocked : false , waitMs : 0 } ;
12571260 } ) ;
12581261 globalThis . fetch = vi . fn ( ) . mockResolvedValue (
@@ -1270,6 +1273,7 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
12701273 "account:acc-1::email:fresh@example.com" ,
12711274 "gpt-5.1" ,
12721275 ) ;
1276+ expect ( manager . getAccountsSnapshot ( ) [ 0 ] ?. email ) . toBe ( "fresh@example.com" ) ;
12731277 } ) ;
12741278
12751279 it . each ( [
You can’t perform that action at this time.
0 commit comments