@@ -862,6 +862,63 @@ describe("pooled account columns", () => {
862862 row . columns . map ( ( member ) => ( member . window ? member . account . key : null ) ) ,
863863 ) ;
864864
865+ it . each ( [
866+ [ "claudeAgent" , "13:00" , 40 , "14:00" , 100 ] ,
867+ [ "codex" , "14:00" , 100 , "14:00" , 100 ] ,
868+ [ "claudeAgent" , "15:00" , 100 , "15:00" , 100 ] ,
869+ [ "codex" , "15:00" , 40 , "14:00" , 60 ] ,
870+ ] as const ) (
871+ "%s session resetting at %s with %i percent spent becomes usable at %s with %i percent restored" ,
872+ ( driver , sessionReset , usedPercent , usableAt , restoresPercent ) => {
873+ const at = ( time : string ) => `2026-09-03T${ time } :00.000Z` ;
874+ const a = {
875+ ...account ( "a" , [
876+ {
877+ ...window ,
878+ id : driver === "codex" ? "primary" : window . id ,
879+ usedPercent,
880+ resetsAt : at ( sessionReset ) ,
881+ } ,
882+ {
883+ ...weekly ,
884+ id : driver === "codex" ? "secondary" : weekly . id ,
885+ usedPercent : 100 ,
886+ resetsAt : at ( "14:00" ) ,
887+ } ,
888+ ] ) ,
889+ driver : ProviderDriverKind . make ( driver ) ,
890+ } ;
891+ const [ session ] = collectLimitPools ( [ a ] , now ) [ 0 ] ! . windows ;
892+ expect . soft ( session ?. remainingPercent ) . toBe ( 0 ) ;
893+ expect ( session ?. resets [ 0 ] ) . toMatchObject ( {
894+ at : Date . parse ( at ( usableAt ) ) ,
895+ restoresPercent,
896+ } ) ;
897+ } ,
898+ ) ;
899+
900+ it ( "excludes weekly-blocked sessions from the pool without changing snapshots or model allowances" , ( ) => {
901+ const blocked = account ( "blocked" , [
902+ window ,
903+ { ...weekly , usedPercent : 100 } ,
904+ { ...weekly , id : "seven_day_fable" , usedPercent : 20 } ,
905+ ] ) ;
906+ const accounts = [
907+ blocked ,
908+ account ( "available" , [
909+ { ...window , usedPercent : 20 } ,
910+ { ...weekly , usedPercent : 99 } ,
911+ { ...weekly , id : "seven_day_fable" , usedPercent : 40 } ,
912+ ] ) ,
913+ { ...blocked , key : "cursor" , driver : ProviderDriverKind . make ( "cursor" ) } ,
914+ ] ;
915+ const snapshot = structuredClone ( accounts ) ;
916+ const [ claude , cursor ] = collectLimitPools ( accounts , now ) ;
917+ expect . soft ( claude ?. windows . map ( ( row ) => row . remainingPercent ) ) . toEqual ( [ 40 , 1 , 70 ] ) ;
918+ expect . soft ( cursor ?. windows . map ( ( row ) => row . remainingPercent ) ) . toEqual ( [ 60 , 0 , 80 ] ) ;
919+ expect ( accounts ) . toEqual ( snapshot ) ;
920+ } ) ;
921+
865922 it ( "keeps session columns across rows with opposite reset and usage orders" , ( ) => {
866923 const accounts = [
867924 account ( "a" , [
@@ -884,6 +941,52 @@ describe("pooled account columns", () => {
884941 expect ( keys ( collectLimitPools ( accounts . toReversed ( ) , now ) [ 0 ] ! ) ) . toEqual ( keys ( pool ! ) ) ;
885942 } ) ;
886943
944+ it . each ( [ undefined , "invalid" , "2026-09-03T11:30:00.000Z" ] ) (
945+ "keeps blocked sessions empty without predicting a refill from a missing or stale clock (%s)" ,
946+ ( resetsAt ) => {
947+ const [ pool ] = collectLimitPools (
948+ [
949+ account ( "session-clock" , [
950+ { ...window , resetsAt } ,
951+ { ...weekly , usedPercent : 100 } ,
952+ ] ) ,
953+ account ( "weekly-clock" , [ window , { ...weekly , usedPercent : 100 , resetsAt } ] ) ,
954+ ] ,
955+ now ,
956+ ) ;
957+ expect ( pool ! . windows [ 0 ] ) . toMatchObject ( { remainingPercent : 0 , pace : null , resets : [ ] } ) ;
958+ expect ( pool ! . windows [ 0 ] ! . columns . map ( ( column ) => column . window ?. resetsAt ) ) . toEqual ( [
959+ undefined ,
960+ undefined ,
961+ ] ) ;
962+ } ,
963+ ) ;
964+
965+ it ( "orders by usable session refill and clears suppression after a fresh weekly reading" , ( ) => {
966+ const blocked = account ( "blocked" , [
967+ { ...window , resetsAt : "2026-09-03T13:00:00.000Z" } ,
968+ { ...weekly , usedPercent : 100 , resetsAt : "2026-09-03T15:00:00.000Z" } ,
969+ ] ) ;
970+ const available = account ( "available" , [ window ] ) ;
971+ const [ before ] = collectLimitPools ( [ blocked , available ] , now ) ;
972+ expect ( before ! . accounts . map ( ( account ) => account . key ) ) . toEqual ( [ "available" , "blocked" ] ) ;
973+ expect ( before ! . windows [ 0 ] ! . remainingPercent ) . toBe ( 30 ) ;
974+ const refreshed = {
975+ ...blocked ,
976+ limits : {
977+ checkedAt : "2026-09-03T12:00:00.000Z" ,
978+ windows : [ blocked . limits . windows [ 0 ] ! , { ...weekly , usedPercent : 10 } ] ,
979+ } ,
980+ } ;
981+ const [ after ] = collectLimitPools ( [ refreshed , available ] , now ) ;
982+ expect ( after ! . accounts . map ( ( account ) => account . key ) ) . toEqual ( [ "blocked" , "available" ] ) ;
983+ expect ( after ! . windows [ 0 ] ! . remainingPercent ) . toBe ( 60 ) ;
984+ expect ( after ! . windows [ 0 ] ! . resets [ 0 ] ) . toMatchObject ( {
985+ at : Date . parse ( "2026-09-03T13:00:00.000Z" ) ,
986+ restoresPercent : 20 ,
987+ } ) ;
988+ } ) ;
989+
887990 it ( "preserves gaps without counting missing windows toward pooled quota" , ( ) => {
888991 const [ pool ] = collectLimitPools (
889992 [
0 commit comments