@@ -644,12 +644,13 @@ async function retryMainAccountInfoIfIdentityChanged(
644644 requestAccountId : string | null ,
645645 retriesRemaining : number ,
646646 nativeMainLease : AdmissionLease ,
647+ explicitRefresh : boolean ,
647648) : Promise < MainAccountInfoFetchResult | null > {
648649 const currentAccountId = getMainChatgptAccountId ( ) ;
649650 if ( currentAccountId === null || currentAccountId === requestAccountId ) return null ;
650651 reconcileMainCodexAccountRuntimeState ( ) ;
651652 return retriesRemaining > 0
652- ? fetchMainAccountInfoWhileOwned ( true , retriesRemaining - 1 , nativeMainLease )
653+ ? fetchMainAccountInfoWhileOwned ( true , retriesRemaining - 1 , nativeMainLease , explicitRefresh )
653654 : { info : EMPTY_MAIN_ACCOUNT_INFO , credentialChecked : true , hasCredential : true } ;
654655}
655656
@@ -696,6 +697,13 @@ async function fetchMainAccountInfoWhileOwned(
696697 forceRefresh : boolean ,
697698 retriesRemaining : number ,
698699 nativeMainLease : AdmissionLease ,
700+ /**
701+ * Whether the *caller* asked for this refresh. `forceRefresh` also means "bypass the
702+ * cache", and `retryMainAccountInfoIfIdentityChanged` re-enters with it set purely to
703+ * re-read after the identity changed. Keeping the two apart stops that retry from
704+ * promoting a background poll into operator intent below.
705+ */
706+ explicitRefresh : boolean = forceRefresh ,
699707) : Promise < MainAccountInfoFetchResult > {
700708 const writerGeneration = captureConfigGeneration ( ) ;
701709 reconcileMainCodexAccountRuntimeState ( ) ;
@@ -724,7 +732,7 @@ async function fetchMainAccountInfoWhileOwned(
724732 } ) ;
725733 if ( ! resp . ok ) {
726734 const terminalAuthFailure = await isTerminalMainAuthResponse ( resp , isMainAccountTokenVerifiablyLive ( ) ) ;
727- const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease ) ;
735+ const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease , explicitRefresh ) ;
728736 if ( retried ) return retried ;
729737 if ( terminalAuthFailure ) {
730738 clearMainAccountInfoCache ( ) ;
@@ -733,7 +741,7 @@ async function fetchMainAccountInfoWhileOwned(
733741 return { info : EMPTY_MAIN_ACCOUNT_INFO , credentialChecked : true , hasCredential : true } ;
734742 }
735743 const data = ( await resp . json ( ) ) as WhamUsageResponse ;
736- const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease ) ;
744+ const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease , explicitRefresh ) ;
737745 if ( retried ) return retried ;
738746 const plan = nonEmptyPlan ( data . plan_type ) ?? nonEmptyPlan ( cached ?. plan ) ?? nonEmptyPlan ( getMainAccountPlan ( ) ) ;
739747 const quota = parseUsageQuota ( { ...data , ...( plan ? { plan_type : plan } : { } ) } ) ;
@@ -745,7 +753,16 @@ async function fetchMainAccountInfoWhileOwned(
745753 ts : Date . now ( ) ,
746754 } ;
747755 setMainAccountInfoCache ( result ) ;
748- clearAccountNeedsReauth ( MAIN_CODEX_ACCOUNT_ID ) ;
756+ // Only an explicit refresh may retract a reauth quarantine. A 200 from
757+ // /wham/usage proves the token authenticates to the usage endpoint; it does not
758+ // prove the account can serve Responses traffic, which is a different backend path
759+ // and still answers 403 for a workspace the token may no longer select (#327).
760+ // Letting the background poll clear the flag put such an account straight back into
761+ // rotation: the next request failed the same way and re-marked it, so needsReauth
762+ // never settled and the dashboard kept showing nothing — the symptom #327 reported.
763+ // An explicit refresh is an operator asking to re-evaluate, normally right after
764+ // signing in again, so it stays authoritative.
765+ if ( explicitRefresh ) clearAccountNeedsReauth ( MAIN_CODEX_ACCOUNT_ID ) ;
749766 // Mirror main quota + plan into the shared stores so the rotation engine can
750767 // score and auto-switch the main account exactly like a pool account (Option A).
751768 setMainAccountPlan ( result . plan ) ;
@@ -760,7 +777,7 @@ async function fetchMainAccountInfoWhileOwned(
760777 ...( freshResetCredits !== undefined ? { freshResetCredits } : { } ) ,
761778 } ;
762779 } catch {
763- const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease ) ;
780+ const retried = await retryMainAccountInfoIfIdentityChanged ( requestAccountId , retriesRemaining , nativeMainLease , explicitRefresh ) ;
764781 return retried ?? { info : EMPTY_MAIN_ACCOUNT_INFO , credentialChecked : true , hasCredential : true } ;
765782 }
766783}
0 commit comments