fix(copilot): adapt catalog endpoint routing across current runtimes - #111552
Chenkeliang wants to merge 1 commit into
Conversation
Related: this is a current-main rebase of open #88538 (same commit, authorship retained), which is the canonical PR for the Responses-only Copilot routing fix for #96902; the broader Copilot api_mode routing cluster is led by #57625. Maintainers may prefer to take this rebase into #88538 rather than review two copies. |
|
Closing this duplicate in favor of the canonical #88538, following the triage suggestion. The tested adaptation, retained contributor attribution, patch link, and validation evidence are being transferred to #88538 for integration by its author/maintainers. The branch |
What does this PR do?
Fix Copilot models that advertise only
/responsesbut are routed to/chat/completions. Grok 4.6 currently fails with HTTP 400unsupported_api_for_model; with this change, the primary agent, auxiliary clients, and fallback activation use the shared catalog-aware resolver.This is a current-main adaptation of #88538, not an independent claim of the same fix. Its commit was cherry-picked without committing, conflicts from subsequent function extraction were resolved, and the resulting commit retains Eleanor Berger's authorship. The dual-endpoint regression from that PR is included. The original PR credits earlier work in #58835; related work also includes #74377, #85224, and #86075. Maintainers may prefer to incorporate this adaptation and validation into the existing PR.
Related Issue
Fixes #96902
Type of Change
Changes Made
hermes_cli/models.py: upgrade non-GPT models when their catalog entry advertises/responseswithout/chat/completions. Keep existing GPT heuristics, Claude chat transport, dual-endpoint behavior, and missing-catalog fallback.agent/agent_init.pyandrun_agent.py: pass the initialization credential to the shared resolver before client construction.agent/auxiliary_client.py: resolve catalog capabilities before constructing request headers and wrap Responses-only clients appropriately.agent/chat_completion_helpers.py: pass the fallback credential through the extracted API-mode resolver. Explicit API-mode overrides still win.How to Test
On base
437116f9497c80d242ce034ff7f5d81dc277a337, the upstream catalog test reproduced the bug: 1 failed, 4 passed, with a Responses-only model resolving tochat_completions.After the fix, run:
Result: 209 passed, 0 failed across nine files. Ruff 0.15.10,
git diff --check, and the Windows-footgun check on all eight changed files also passed.Live verification on Linux ARM64, with real imports and a temporary
HERMES_HOME, nomodel.api_modeoverride, and a minimalReply exactly OKprompt:codex_responsesOK, completed, no fallbackchat_completionsOK, completed, no fallbackOK, completed, fallback activatedNo messaging-channel test messages were sent. Auxiliary and Copilot-as-fallback routing are covered by regression tests; the live fallback test exercises Copilot-to-custom failover.
Checklist
scripts/run_tests.sh.The existing explicit
model.api_modesetting remains authoritative. Users who previously pinnedchat_completionsorcodex_responsesmust remove that override to opt into automatic routing.