File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2130,6 +2130,19 @@ while (attempted.size < Math.max(1, accountCount)) {
21302130 refreshToken : fallbackAccount . refreshToken ,
21312131 index : fallbackAccount . index ,
21322132 } ) ;
2133+ const fallbackEntitlementBlock = entitlementCache . isBlocked (
2134+ fallbackEntitlementAccountKey ,
2135+ model ?? modelFamily ,
2136+ ) ;
2137+ if ( fallbackEntitlementBlock . blocked ) {
2138+ runtimeMetrics . accountRotations ++ ;
2139+ runtimeMetrics . lastError =
2140+ `Entitlement cached block for account ${ fallbackAccount . index + 1 } ` ;
2141+ logWarn (
2142+ `Skipping account ${ fallbackAccount . index + 1 } due to cached entitlement block (${ formatWaitTime ( fallbackEntitlementBlock . waitMs ) } remaining).` ,
2143+ ) ;
2144+ continue ;
2145+ }
21332146
21342147 if ( ! accountManager . consumeToken ( fallbackAccount , modelFamily , model ) ) {
21352148 continue ;
Original file line number Diff line number Diff line change @@ -120,16 +120,18 @@ vi.mock("../lib/accounts.js", async () => {
120120 source,
121121 storedEmail,
122122 accessToken,
123+ idToken,
123124 } : {
124125 storedAccountId ?: string ;
125126 source ?: string ;
126127 storedEmail ?: string ;
127128 accessToken ?: string ;
129+ idToken ?: string ;
128130 } ) => {
129131 const tokenUtilsModule = tokenUtils as typeof import ( "../lib/auth/token-utils.js" ) ;
130132 const tokenAccountId = accessToken ? "account-1" : undefined ;
131133 const tokenEmail = tokenUtilsModule . sanitizeEmail (
132- tokenUtilsModule . extractAccountEmail ( accessToken , undefined ) ,
134+ tokenUtilsModule . extractAccountEmail ( accessToken , idToken ) ,
133135 ) ;
134136 const sanitizedStoredEmail = tokenUtilsModule . sanitizeEmail ( storedEmail ) ;
135137 return {
Original file line number Diff line number Diff line change @@ -1237,19 +1237,22 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
12371237 } ) ;
12381238
12391239 it ( "uses the refreshed token email when checking entitlement blocks" , async ( ) => {
1240- mockStorage . accounts = [
1240+ const { AccountManager } = await import ( "../lib/accounts.js" ) ;
1241+ const manager = buildRoutingManager ( [
12411242 {
1243+ index : 0 ,
12421244 accountId : "acc-1" ,
12431245 email : "stale@example.com" ,
12441246 refreshToken : "refresh-1" ,
12451247 } ,
1246- ] ;
1248+ ] ) ;
1249+ vi . spyOn ( AccountManager , "loadFromDisk" ) . mockResolvedValueOnce ( manager as never ) ;
12471250 extractAccountEmailMock . mockReturnValueOnce ( "fresh@example.com" ) ;
12481251 const entitlementModule = await import ( "../lib/entitlement-cache.js" ) ;
12491252 const isBlockedSpy = vi
12501253 . spyOn ( entitlementModule . EntitlementCache . prototype , "isBlocked" )
12511254 . mockImplementation ( ( ) => {
1252- expect ( mockStorage . accounts [ 0 ] ?. email ) . toBe ( "stale@example.com" ) ;
1255+ expect ( manager . getAccountsSnapshot ( ) [ 0 ] ?. email ) . toBe ( "stale@example.com" ) ;
12531256 return { blocked : false , waitMs : 0 } ;
12541257 } ) ;
12551258 globalThis . fetch = vi . fn ( ) . mockResolvedValue (
@@ -1267,6 +1270,7 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
12671270 "account:acc-1::email:fresh@example.com" ,
12681271 "gpt-5.1" ,
12691272 ) ;
1273+ expect ( manager . getAccountsSnapshot ( ) [ 0 ] ?. email ) . toBe ( "fresh@example.com" ) ;
12701274 } ) ;
12711275
12721276 it . each ( [
You can’t perform that action at this time.
0 commit comments