fix(runtime_provider): honour transport field on v12+ providers dict#17901
Merged
Conversation
…rt field on v12+ providers dict
The v11→v12 migrate_config step writes the API mode for every entry
under the new transport: field (per the v12+ schema in
_normalize_custom_provider_entry). _get_named_custom_provider
read the legacy api_mode: spelling only, so for every migrated
config the lookup returned None for the api mode.
Downstream, _resolve_named_custom_runtime then falls back through
custom_provider.get("api_mode") or _detect_api_mode_for_url(base_url)
or "chat_completions". For loopback URLs (proxies, local servers)
or unknown hostnames, the URL detector returns None and the resolver
silently downgrades the configured codex_responses /
anthropic_messages transport to chat_completions. Requests
get sent to /v1/chat/completions instead of /v1/responses or
/v1/messages and the provider 404s — or worse, returns a usable
chat_completions response while skipping the model's reasoning /
caching surface.
Fix: read both field names — entry.get("api_mode") or
entry.get("transport") — at the two match-by-key + match-by-name
branches in _get_named_custom_provider. The runtime normaliser
_normalize_custom_provider_entry already accepts both spellings;
this lifts the same compat into the direct-dict reader so v12+
configs work without going through the shim.
Adds three regression tests under
tests/hermes_cli/test_user_providers_model_switch.py:
- transport field is read on the match-by-key branch
- legacy api_mode spelling still works for hand-edited configs
- transport is read on the match-by-display-name branch
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
v12+
providers:dict lookups now respect thetransport:field, not only the legacyapi_mode:spelling.Salvage of #17860 by @zicochaos onto current main.
Root cause
migrate_configv11→v12 writes every custom provider's API mode under the newtransport:field (per_normalize_custom_provider_entry's_KNOWN_KEYS). But_get_named_custom_providershort-circuits on the providers-dict before reachingget_compatible_custom_providers, reading onlyentry.get("api_mode")— so on every migrated config the lookup returnsNonefor api_mode.Downstream,
_resolve_named_custom_runtimethen falls back through_detect_api_mode_for_url(base_url) or "chat_completions". For loopback URLs (proxies, local servers) or unknown hostnames the URL detector returnsNone, silently downgrading configuredcodex_responses/anthropic_messagesproviders tochat_completions— routing requests to/v1/chat/completionsinstead of/v1/responses.Changes
entry.get("api_mode") or entry.get("transport")at both match branches (by-key and by-display-name). The runtime normaliser_normalize_custom_provider_entryalready does this — the fix lifts the same compat into the direct-dict reader.Validation
transport: codex_responseson loopback URLchat_completionscodex_responsesapi_mode:scripts/run_tests.sh tests/hermes_cli/test_user_providers_model_switch.py→ 25 passedtransport: codex_responsespointing athttp://127.0.0.1:4000/v1,resolve_runtime_provider(requested="my-codex-proxy")returnedapi_mode="codex_responses"(would bechat_completionswithout the fix)Closes #17860