@@ -208,16 +208,6 @@ async function readUsageStats(agentDir: string) {
208208 return ensureAuthProfileStore ( agentDir , { syncExternalCli : false } ) . usageStats ?? { } ;
209209}
210210
211- function expectFailureCount (
212- usageStats : Record < string , Record < string , unknown > | undefined > ,
213- profileId : string ,
214- reason : AuthProfileFailureReason ,
215- expected : number ,
216- ) {
217- const failureCounts = usageStats [ profileId ] ?. failureCounts as Record < string , unknown > | undefined ;
218- expect ( failureCounts ?. [ reason ] ) . toBe ( expected ) ;
219- }
220-
221211async function writeMultiProfileAuthStore (
222212 agentDir : string ,
223213 options ?: { openAiProfileCount ?: 2 | 3 } ,
@@ -550,7 +540,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
550540 } ) ;
551541 } ) ;
552542
553- it ( "falls back across providers after overloaded primary failure and persists transient cooldown " , async ( ) => {
543+ it ( "falls back after overloaded primary failure without poisoning profile health " , async ( ) => {
554544 await withAgentWorkspace ( async ( { agentDir, workspaceDir } ) => {
555545 await writeAuthStore ( agentDir ) ;
556546 mockPrimaryOverloadedThenFallbackSuccess ( ) ;
@@ -568,8 +558,8 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
568558 expect ( result . result . payloads ?. [ 0 ] ?. text ?? "" ) . toContain ( "fallback ok" ) ;
569559
570560 const usageStats = await readUsageStats ( agentDir ) ;
571- expect ( typeof usageStats [ "openai:p1" ] ?. cooldownUntil ) . toBe ( "number" ) ;
572- expectFailureCount ( usageStats , "openai:p1" , " overloaded" , 1 ) ;
561+ expect ( usageStats [ "openai:p1" ] ?. cooldownUntil ) . toBeUndefined ( ) ;
562+ expect ( usageStats [ "openai:p1" ] ?. failureCounts ?. overloaded ) . toBeUndefined ( ) ;
573563 expect ( typeof usageStats [ "groq:p1" ] ?. lastUsed ) . toBe ( "number" ) ;
574564
575565 expectOpenAiThenGroqAttemptOrder ( ) ;
@@ -756,7 +746,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
756746 } ) ;
757747 } ) ;
758748
759- it ( "persists overloaded cooldown across turns while still allowing one probe and fallback" , async ( ) => {
749+ it ( "keeps overloaded failures provider-scoped across turns while continuing fallback" , async ( ) => {
760750 await withAgentWorkspace ( async ( { agentDir, workspaceDir } ) => {
761751 await writeAuthStore ( agentDir ) ;
762752 mockPrimaryOverloadedThenFallbackSuccess ( ) ;
@@ -787,14 +777,14 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
787777 expectOpenAiThenGroqAttemptOrder ( { expectOpenAiAuthProfileId : "openai:p1" } ) ;
788778
789779 const usageStats = await readUsageStats ( agentDir ) ;
790- expect ( typeof usageStats [ "openai:p1" ] ?. cooldownUntil ) . toBe ( "number" ) ;
791- expectFailureCount ( usageStats , "openai:p1" , " overloaded" , 2 ) ;
780+ expect ( usageStats [ "openai:p1" ] ?. cooldownUntil ) . toBeUndefined ( ) ;
781+ expect ( usageStats [ "openai:p1" ] ?. failureCounts ?. overloaded ) . toBeUndefined ( ) ;
792782 expect ( computeBackoffMock ) . not . toHaveBeenCalled ( ) ;
793783 expect ( sleepWithAbortMock ) . not . toHaveBeenCalled ( ) ;
794784 } ) ;
795785 } ) ;
796786
797- it ( "keeps bare service-unavailable failures in the timeout lane without persisting cooldown " , async ( ) => {
787+ it ( "classifies bare service-unavailable failures as overloaded without cooling the profile " , async ( ) => {
798788 await withAgentWorkspace ( async ( { agentDir, workspaceDir } ) => {
799789 await writeAuthStore ( agentDir ) ;
800790 mockPrimaryErrorThenFallbackSuccess ( "LLM error: service unavailable" ) ;
@@ -807,7 +797,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
807797 } ) ;
808798
809799 expect ( result . provider ) . toBe ( "groq" ) ;
810- expect ( result . attempts [ 0 ] ?. reason ) . toBe ( "timeout " ) ;
800+ expect ( result . attempts [ 0 ] ?. reason ) . toBe ( "overloaded " ) ;
811801
812802 const usageStats = await readUsageStats ( agentDir ) ;
813803 expect ( usageStats [ "openai:p1" ] ?. cooldownUntil ) . toBeUndefined ( ) ;
0 commit comments