@@ -111,6 +111,7 @@ public partial class SessionView : UserControl, INotifyPropertyChanged
111111 private const long ContextBaselineTokens = 12000 ;
112112 private static readonly string [ ] FileTreeIgnoredFolders = new [ ] { ".git" , "node_modules" , "bin" , "obj" , ".idea" , ".vs" } ;
113113 private bool _verboseLogging ;
114+ private bool _modelListUseLegacyPaging ;
114115 private bool _mcpEnabled ;
115116 private bool _allowNetworkAccess ;
116117 private bool _loginInProgress ;
@@ -644,17 +645,36 @@ private async Task<List<ModelCatalogEntry>> FetchModelCatalogAsync()
644645
645646 while ( true )
646647 {
647- var parameters = new JObject
648+ var parameters = new JObject ( ) ;
649+ if ( _modelListUseLegacyPaging )
648650 {
649- [ "limit" ] = PageSize ,
650- [ "pageSize" ] = PageSize // legacy field for older Codex builds
651- } ;
651+ parameters [ "pageSize" ] = PageSize ;
652+ }
653+ else
654+ {
655+ parameters [ "limit" ] = PageSize ;
656+ parameters [ "pageSize" ] = PageSize ; // fallback for older builds; ignored by newer ones
657+ }
658+
652659 if ( ! string . IsNullOrWhiteSpace ( cursor ) )
653660 parameters [ "cursor" ] = cursor ;
654661
655- var response = await SendRequestAsync ( "model/list" , parameters ) . ConfigureAwait ( false ) ;
656- if ( response is not JObject obj )
657- break ;
662+ JObject obj ;
663+ try
664+ {
665+ var response = await SendRequestAsync ( "model/list" , parameters ) . ConfigureAwait ( false ) ;
666+ if ( response is not JObject json )
667+ break ;
668+ obj = json ;
669+ }
670+ catch ( Exception ex ) when ( ShouldFallbackToLegacyModelList ( ex ) )
671+ {
672+ if ( _modelListUseLegacyPaging )
673+ throw ;
674+ _modelListUseLegacyPaging = true ;
675+ AppendCliLog ( "System: CLI returned legacy pagination error; retrying model catalog request." ) ;
676+ return await FetchModelCatalogAsync ( ) . ConfigureAwait ( false ) ;
677+ }
658678
659679 if ( obj [ "items" ] is JArray items )
660680 {
@@ -3463,6 +3483,14 @@ private static bool IsPathAncestorOrSame(string? ancestor, string? target)
34633483 return separator == Path . DirectorySeparatorChar || separator == Path . AltDirectorySeparatorChar ;
34643484 }
34653485
3486+ private static bool ShouldFallbackToLegacyModelList ( Exception ex )
3487+ {
3488+ if ( ex is not InvalidOperationException ioe )
3489+ return false ;
3490+ var message = ioe . Message ?? string . Empty ;
3491+ return message . IndexOf ( "invalid request" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
3492+ }
3493+
34663494 private void ResetEditorViewport ( TextEditor ? editor )
34673495 {
34683496 if ( editor is null ) return ;
0 commit comments