@@ -11,6 +11,7 @@ import { resolveProfileUnusableUntil } from "./usage-state.js";
1111import {
1212 clearAuthProfileCooldown ,
1313 clearExpiredCooldowns ,
14+ getSoonestCooldownExpiry ,
1415 isProfileInCooldown ,
1516 markAuthProfileBlockedUntil ,
1617 markAuthProfileFailure ,
@@ -298,6 +299,40 @@ describe("isProfileInCooldown", () => {
298299 ) ;
299300 } ) ;
300301
302+ it ( "returns false for a different model when cooldown is model-scoped (model_not_found) — #116464" , ( ) => {
303+ const store = makeStore ( {
304+ "github-copilot:github" : {
305+ cooldownUntil : Date . now ( ) + 60_000 ,
306+ cooldownReason : "model_not_found" ,
307+ cooldownModel : "claude-sonnet-4.6" ,
308+ } ,
309+ } ) ;
310+ // A healthy sibling model on the same auth profile bypasses the cooldown
311+ expect ( isProfileInCooldown ( store , "github-copilot:github" , undefined , "gpt-4.1" ) ) . toBe ( false ) ;
312+ // The failed model itself stays blocked
313+ expect (
314+ isProfileInCooldown ( store , "github-copilot:github" , undefined , "claude-sonnet-4.6" ) ,
315+ ) . toBe ( true ) ;
316+ // No model specified — blocked (conservative)
317+ expect ( isProfileInCooldown ( store , "github-copilot:github" ) ) . toBe ( true ) ;
318+ } ) ;
319+
320+ it ( "blocks all models when a model_not_found cooldown has no cooldownModel (profile-wide) — #116464" , ( ) => {
321+ const store = makeStore ( {
322+ "github-copilot:github" : {
323+ cooldownUntil : Date . now ( ) + 60_000 ,
324+ cooldownReason : "model_not_found" ,
325+ cooldownModel : undefined ,
326+ } ,
327+ } ) ;
328+ // Without a scoped model, the cooldown stays profile-wide so neither a
329+ // sibling model nor the originally failing model can bypass it.
330+ expect ( isProfileInCooldown ( store , "github-copilot:github" , undefined , "gpt-4.1" ) ) . toBe ( true ) ;
331+ expect (
332+ isProfileInCooldown ( store , "github-copilot:github" , undefined , "claude-sonnet-4.6" ) ,
333+ ) . toBe ( true ) ;
334+ } ) ;
335+
301336 it ( "does not bypass model-scoped cooldown when disabledUntil is active" , ( ) => {
302337 const store = makeStore ( {
303338 "github-copilot:github" : {
@@ -343,6 +378,47 @@ describe("isProfileInCooldown", () => {
343378 } ) ;
344379} ) ;
345380
381+ describe ( "getSoonestCooldownExpiry" , ( ) => {
382+ it ( "treats a model_not_found cooldown for the requested model as model-scoped — #116464" , ( ) => {
383+ const now = Date . now ( ) ;
384+ const store = makeStore ( {
385+ "github-copilot:github" : {
386+ cooldownUntil : now + 60_000 ,
387+ cooldownReason : "model_not_found" ,
388+ cooldownModel : "claude-sonnet-4.6" ,
389+ } ,
390+ } ) ;
391+ // Same model: expiry is tracked as the matching model-scoped cooldown
392+ const sameModel = getSoonestCooldownExpiry ( store , [ "github-copilot:github" ] , {
393+ now,
394+ forModel : "claude-sonnet-4.6" ,
395+ } ) ;
396+ expect ( sameModel ) . toBe ( now + 60_000 ) ;
397+ // Different model bypasses the cooldown entirely
398+ const sibling = getSoonestCooldownExpiry ( store , [ "github-copilot:github" ] , {
399+ now,
400+ forModel : "gpt-4.1" ,
401+ } ) ;
402+ expect ( sibling ) . toBeNull ( ) ;
403+ } ) ;
404+
405+ it ( "keeps profile-wide cooldowns visible to all models" , ( ) => {
406+ const now = Date . now ( ) ;
407+ const store = makeStore ( {
408+ "github-copilot:github" : {
409+ cooldownUntil : now + 60_000 ,
410+ cooldownReason : "model_not_found" ,
411+ cooldownModel : undefined ,
412+ } ,
413+ } ) ;
414+ const soonest = getSoonestCooldownExpiry ( store , [ "github-copilot:github" ] , {
415+ now,
416+ forModel : "gpt-4.1" ,
417+ } ) ;
418+ expect ( soonest ) . toBe ( now + 60_000 ) ;
419+ } ) ;
420+ } ) ;
421+
346422describe ( "resolveProfilesUnavailableReason" , ( ) => {
347423 it ( "prefers active disabledReason when profiles are disabled" , ( ) => {
348424 const now = Date . now ( ) ;
@@ -1631,6 +1707,138 @@ describe("markAuthProfileFailure — per-model cooldown metadata", () => {
16311707 expect ( stats ?. cooldownModel ) . toBe ( "claude-sonnet-4.6" ) ;
16321708 } ) ;
16331709
1710+ it ( "records cooldownModel on first model_not_found failure — #116464" , async ( ) => {
1711+ const now = 1_000_000 ;
1712+ const store = makeStoreWithCopilot ( { } ) ;
1713+ vi . useFakeTimers ( ) ;
1714+ vi . setSystemTime ( now ) ;
1715+ mockLockedUpdateForStore ( store ) ;
1716+ try {
1717+ await markAuthProfileFailure ( {
1718+ store,
1719+ profileId : "github-copilot:github" ,
1720+ reason : "model_not_found" ,
1721+ modelId : "claude-sonnet-4.6" ,
1722+ } ) ;
1723+ } finally {
1724+ vi . useRealTimers ( ) ;
1725+ }
1726+ const stats = store . usageStats ?. [ "github-copilot:github" ] ;
1727+ expect ( stats ?. cooldownReason ) . toBe ( "model_not_found" ) ;
1728+ expect ( stats ?. cooldownModel ) . toBe ( "claude-sonnet-4.6" ) ;
1729+ } ) ;
1730+
1731+ it ( "widens cooldownModel to undefined when a different model fails during active model_not_found cooldown" , async ( ) => {
1732+ const now = 1_000_000 ;
1733+ const store = makeStoreWithCopilot ( {
1734+ "github-copilot:github" : {
1735+ cooldownUntil : now + 30_000 ,
1736+ cooldownReason : "model_not_found" ,
1737+ cooldownModel : "claude-sonnet-4.6" ,
1738+ errorCount : 1 ,
1739+ lastFailureAt : now - 1000 ,
1740+ } ,
1741+ } ) ;
1742+ vi . useFakeTimers ( ) ;
1743+ vi . setSystemTime ( now ) ;
1744+ mockLockedUpdateForStore ( store ) ;
1745+ try {
1746+ await markAuthProfileFailure ( {
1747+ store,
1748+ profileId : "github-copilot:github" ,
1749+ reason : "model_not_found" ,
1750+ modelId : "gpt-4.1" ,
1751+ } ) ;
1752+ } finally {
1753+ vi . useRealTimers ( ) ;
1754+ }
1755+ const stats = store . usageStats ?. [ "github-copilot:github" ] ;
1756+ // Scope widened to all models so the sibling failure cannot bypass stale metadata
1757+ expect ( stats ?. cooldownModel ) . toBeUndefined ( ) ;
1758+ expect ( stats ?. cooldownReason ) . toBe ( "model_not_found" ) ;
1759+ } ) ;
1760+
1761+ it ( "preserves cooldownModel when the same model fails again during active model_not_found cooldown" , async ( ) => {
1762+ const now = 1_000_000 ;
1763+ const store = makeStoreWithCopilot ( {
1764+ "github-copilot:github" : {
1765+ cooldownUntil : now + 30_000 ,
1766+ cooldownReason : "model_not_found" ,
1767+ cooldownModel : "claude-sonnet-4.6" ,
1768+ errorCount : 1 ,
1769+ lastFailureAt : now - 1000 ,
1770+ } ,
1771+ } ) ;
1772+ vi . useFakeTimers ( ) ;
1773+ vi . setSystemTime ( now ) ;
1774+ mockLockedUpdateForStore ( store ) ;
1775+ try {
1776+ await markAuthProfileFailure ( {
1777+ store,
1778+ profileId : "github-copilot:github" ,
1779+ reason : "model_not_found" ,
1780+ modelId : "claude-sonnet-4.6" ,
1781+ } ) ;
1782+ } finally {
1783+ vi . useRealTimers ( ) ;
1784+ }
1785+ const stats = store . usageStats ?. [ "github-copilot:github" ] ;
1786+ expect ( stats ?. cooldownModel ) . toBe ( "claude-sonnet-4.6" ) ;
1787+ } ) ;
1788+
1789+ it ( "widens cooldownModel when model_not_found failure during active cooldown has no modelId" , async ( ) => {
1790+ const now = 1_000_000 ;
1791+ const store = makeStoreWithCopilot ( {
1792+ "github-copilot:github" : {
1793+ cooldownUntil : now + 30_000 ,
1794+ cooldownReason : "model_not_found" ,
1795+ cooldownModel : "claude-sonnet-4.6" ,
1796+ errorCount : 1 ,
1797+ lastFailureAt : now - 1000 ,
1798+ } ,
1799+ } ) ;
1800+ vi . useFakeTimers ( ) ;
1801+ vi . setSystemTime ( now ) ;
1802+ mockLockedUpdateForStore ( store ) ;
1803+ try {
1804+ await markAuthProfileFailure ( {
1805+ store,
1806+ profileId : "github-copilot:github" ,
1807+ reason : "model_not_found" ,
1808+ modelId : undefined ,
1809+ } ) ;
1810+ } finally {
1811+ vi . useRealTimers ( ) ;
1812+ }
1813+ const stats = store . usageStats ?. [ "github-copilot:github" ] ;
1814+ expect ( stats ?. cooldownReason ) . toBe ( "model_not_found" ) ;
1815+ expect ( stats ?. cooldownModel ) . toBeUndefined ( ) ;
1816+ } ) ;
1817+
1818+ it ( "keeps a healthy sibling model available after a model_not_found failure on the same profile — #116464" , async ( ) => {
1819+ const now = 1_000_000 ;
1820+ const store = makeStoreWithCopilot ( { } ) ;
1821+ vi . useFakeTimers ( ) ;
1822+ vi . setSystemTime ( now ) ;
1823+ mockLockedUpdateForStore ( store ) ;
1824+ try {
1825+ await markAuthProfileFailure ( {
1826+ store,
1827+ profileId : "github-copilot:github" ,
1828+ reason : "model_not_found" ,
1829+ modelId : "claude-sonnet-4.6" ,
1830+ } ) ;
1831+ } finally {
1832+ vi . useRealTimers ( ) ;
1833+ }
1834+ // The failed model stays blocked, but a sibling fallback on the same auth
1835+ // profile remains available — the exact fallback scenario from #116464.
1836+ expect ( isProfileInCooldown ( store , "github-copilot:github" , now , "claude-sonnet-4.6" ) ) . toBe (
1837+ true ,
1838+ ) ;
1839+ expect ( isProfileInCooldown ( store , "github-copilot:github" , now , "gpt-4.1" ) ) . toBe ( false ) ;
1840+ } ) ;
1841+
16341842 it ( "widens cooldownModel to undefined when a different model fails during active cooldown" , async ( ) => {
16351843 const now = 1_000_000 ;
16361844 const store = makeStoreWithCopilot ( {
0 commit comments