@@ -476,6 +476,14 @@ def _get_extension_suppressions(mod_loaders):
476476 # The index won't contain suppressed extensions
477477 _update_command_table_from_extensions ([], index_extensions )
478478
479+ # If we loaded all extensions as a safety fallback, refresh extension overlay cache
480+ # so subsequent runs can use blended targeted loading.
481+ if use_command_index and index_extensions is None and command_index .cloud_profile == 'latest' :
482+ command_index .update_extension_index (self .command_table )
483+ # We already paid the cost to load all extensions. Refresh help overlay as well so
484+ # top-level help can stay on packaged base + extension overlay fast path.
485+ self ._cache_help_index (command_index )
486+
479487 logger .debug ("Loaded %d groups, %d commands." , len (self .command_group_table ), len (self .command_table ))
480488 from azure .cli .core .util import roughly_parse_command
481489 # The index may be outdated. Make sure the command appears in the loaded command table
@@ -517,6 +525,15 @@ def _get_extension_suppressions(mod_loaders):
517525
518526 logger .debug ("Could not find a match in the command or command group table for '%s'. "
519527 "The index may be outdated." , raw_cmd )
528+
529+ if command_index .cloud_profile == 'latest' and lookup_args and \
530+ not self .cli_ctx .data ['completer_active' ]:
531+ top_command = lookup_args [0 ]
532+ packaged_core_index = command_index ._get_packaged_command_index (ignore_extensions = True ) or {}
533+ if top_command != 'help' and top_command not in packaged_core_index :
534+ logger .debug ("Top-level command '%s' is not in packaged core index. "
535+ "Skipping full core module reload." , top_command )
536+ return self .command_table
520537 else :
521538 logger .debug ("No module found from index for '%s'" , args )
522539
@@ -1048,12 +1065,19 @@ def get(self, args):
10481065 if result :
10491066 return result
10501067
1051- if force_load_all_extensions and normalized_args and not normalized_args [0 ].startswith ('-' ) and \
1052- not self .cli_ctx .data ['completer_active' ]:
1053- logger .debug ("No match found in blended latest index for '%s'. Loading all extensions." ,
1054- normalized_args [0 ])
1055- # Load all extensions to resolve extension-only top-level commands without rebuilding all modules.
1056- return [], None
1068+ if normalized_args and not normalized_args [0 ].startswith ('-' ) and \
1069+ not self .cli_ctx .data ['completer_active' ] and not force_packaged_for_version and \
1070+ top_command != 'help' :
1071+ # Unknown top-level command on latest should prefer extension-only retry and avoid
1072+ # full core module rebuild to preserve packaged-index startup benefit.
1073+ if has_non_always_loaded_extensions :
1074+ logger .debug ("No match found in blended latest index for '%s'. Loading all extensions." ,
1075+ normalized_args [0 ])
1076+ return [], None
1077+
1078+ logger .debug ("No match found in latest index for '%s' and no dynamic extensions are installed. "
1079+ "Skipping core module rebuild." , normalized_args [0 ])
1080+ return [], []
10571081
10581082 logger .debug ("No match found in blended latest index. Falling back to local command index." )
10591083
@@ -1225,21 +1249,27 @@ def update(self, command_table):
12251249 elapsed_time = timeit .default_timer () - start_time
12261250 self .INDEX [self ._COMMAND_INDEX ] = index
12271251
1228- # Maintain extension-only overlay for latest profile so packaged core can be blended.
1229- if self .cloud_profile == 'latest' :
1230- extension_index = defaultdict (list )
1231- for command_name , command in command_table .items ():
1232- top_command = command_name .split ()[0 ]
1233- module_name = command .loader .__module__
1234- if module_name .startswith ('azext_' ) and module_name not in extension_index [top_command ]:
1235- extension_index [top_command ].append (module_name )
1236-
1237- self .EXTENSION_INDEX [self ._COMMAND_INDEX_VERSION ] = __version__
1238- self .EXTENSION_INDEX [self ._COMMAND_INDEX_CLOUD_PROFILE ] = self .cloud_profile
1239- self .EXTENSION_INDEX [self ._COMMAND_INDEX ] = extension_index
1252+ self .update_extension_index (command_table )
12401253
12411254 logger .debug ("Updated command index in %.3f seconds." , elapsed_time )
12421255
1256+ def update_extension_index (self , command_table ):
1257+ """Update extension-only overlay index from a command table (latest profile only)."""
1258+ if self .cloud_profile != 'latest' :
1259+ return
1260+
1261+ from collections import defaultdict
1262+ extension_index = defaultdict (list )
1263+ for command_name , command in command_table .items ():
1264+ top_command = command_name .split ()[0 ]
1265+ module_name = command .loader .__module__
1266+ if module_name .startswith ('azext_' ) and module_name not in extension_index [top_command ]:
1267+ extension_index [top_command ].append (module_name )
1268+
1269+ self .EXTENSION_INDEX [self ._COMMAND_INDEX_VERSION ] = __version__
1270+ self .EXTENSION_INDEX [self ._COMMAND_INDEX_CLOUD_PROFILE ] = self .cloud_profile
1271+ self .EXTENSION_INDEX [self ._COMMAND_INDEX ] = extension_index
1272+
12431273 def invalidate (self ):
12441274 """Invalidate the command index.
12451275
0 commit comments