From 512c328815176f4be4a7659ad30b67bf63f1bcf0 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 16 Apr 2026 05:18:34 -0700 Subject: [PATCH] fix(copilot): eliminate redundant catalog fetch in api_mode resolution (#11008) copilot_model_api_mode() called normalize_copilot_model_id() which fetched the GitHub model catalog via HTTP, then the secondary endpoint check fetched it again because the catalog was never passed through. Fix: fetch the catalog once at the top of copilot_model_api_mode() and pass it to normalize_copilot_model_id(). The secondary check then sees a non-None catalog and skips the redundant fetch. For a Claude model switch on Copilot this eliminates one 5-second- timeout HTTP call from the interactive /model path. Surfaced during review of PR #10533. Co-authored-by: kshitijk4poor --- hermes_cli/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hermes_cli/models.py b/hermes_cli/models.py index 0ae32f11a05..36005548709 100644 --- a/hermes_cli/models.py +++ b/hermes_cli/models.py @@ -1570,6 +1570,11 @@ def copilot_model_api_mode( primary signal. Falls back to the catalog's ``supported_endpoints`` only for models not covered by the pattern check. """ + # Fetch the catalog once so normalize + endpoint check share it + # (avoids two redundant network calls for non-GPT-5 models). + if catalog is None and api_key: + catalog = fetch_github_model_catalog(api_key=api_key) + normalized = normalize_copilot_model_id(model_id, catalog=catalog, api_key=api_key) if not normalized: return "chat_completions" @@ -1579,9 +1584,6 @@ def copilot_model_api_mode( return "codex_responses" # Secondary: check catalog for non-GPT-5 models (Claude via /v1/messages, etc.) - if catalog is None and api_key: - catalog = fetch_github_model_catalog(api_key=api_key) - if catalog: catalog_entry = next((item for item in catalog if item.get("id") == normalized), None) if isinstance(catalog_entry, dict):