Skip to content

fix(copilot): adapt catalog endpoint routing across current runtimes - #111552

Closed
Chenkeliang wants to merge 1 commit into
NousResearch:mainfrom
Chenkeliang:fix/copilot-catalog-endpoints
Closed

Chenkeliang wants to merge 1 commit into
NousResearch:mainfrom
Chenkeliang:fix/copilot-catalog-endpoints

Conversation

@Chenkeliang

Copy link
Copy Markdown

What does this PR do?

Fix Copilot models that advertise only /responses but are routed to /chat/completions. Grok 4.6 currently fails with HTTP 400 unsupported_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

  • Bug fix

Changes Made

  • hermes_cli/models.py: upgrade non-GPT models when their catalog entry advertises /responses without /chat/completions. Keep existing GPT heuristics, Claude chat transport, dual-endpoint behavior, and missing-catalog fallback.
  • agent/agent_init.py and run_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.
  • Reuse the upstream regressions for catalog routing, auxiliary requests, and fallback activation.

How to Test

On base 437116f9497c80d242ce034ff7f5d81dc277a337, the upstream catalog test reproduced the bug: 1 failed, 4 passed, with a Responses-only model resolving to chat_completions.

After the fix, run:

scripts/run_tests.sh \
  tests/hermes_cli/test_copilot_model_api_mode.py \
  tests/hermes_cli/test_copilot_runtime_api_mode.py \
  tests/hermes_cli/test_model_switch_copilot_api_mode.py \
  tests/hermes_cli/test_models.py \
  tests/hermes_cli/test_runtime_provider_resolution.py \
  tests/agent/test_auxiliary_main_first.py \
  tests/agent/test_fallback_api_mode_preservation.py \
  tests/agent/test_copilot_initiator.py \
  tests/agent/test_copilot_native_vision_headers.py -q

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, no model.api_mode override, and a minimal Reply exactly OK prompt:

Case Selected transport Result
Copilot Grok 4.6 codex_responses OK, completed, no fallback
Copilot Gemini 3.5 Flash chat_completions OK, completed, no fallback
Force Grok onto its unsupported chat endpoint in an isolated agent Automatic fallback to a configured custom chat provider OK, completed, fallback activated

No 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

  • Read CONTRIBUTING.md and applicable AGENTS.md files.
  • Conventional commit; original contributor authorship retained.
  • Searched open and merged PRs/issues; overlapping work is explicitly acknowledged above.
  • Only this repair is included; one commit on the verified official main base.
  • Relevant regression tests passed through scripts/run_tests.sh.
  • Full repository test suite run locally (not run; targeted results above).
  • Tested on Linux ARM64 in OrbStack.
  • Relevant docstring updated; no new config keys, dependencies, tools, or architecture changes.
  • Cross-platform impact checked; no new OS-specific behavior.

The existing explicit model.api_mode setting remains authoritative. Users who previously pinned chat_completions or codex_responses must remove that override to opt into automatic routing.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard provider/copilot GitHub Copilot (ACP + Chat) labels Sep 15, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

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.

@Chenkeliang

Copy link
Copy Markdown
Author

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 Chenkeliang/hermes-agent:fix/copilot-catalog-endpoints and commit c95ccc28a81db24c64cd3fb2036f9825208e2954 remain available; no branch deletion or history rewrite is requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/copilot GitHub Copilot (ACP + Chat) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Copilot grok-4.6 fails with HTTP 400 (not accessible via /chat/completions)

3 participants