fix(auxiliary): _wrap_if_needed uses the effective (post-override) base_url in the API-key branch - #85632
Conversation
…se_url in the API-key branch Fixes NousResearch#85535. In the generic API-key branch of resolve_provider_client() (any named built-in provider that doesn't hit a more specific branch), when a fallback entry carries an explicit_base_url override, the actual OpenAI client is built with the override (base_url, computed via _to_openai_base_url() at :6585) -- but the final _wrap_if_needed() call at :6656 still passed raw_base_url, the pre-rewrite value, not the effective URL the client was actually constructed with. Every other _wrap_if_needed call site across this file was already guarded against this class of bug (NousResearch#85466, NousResearch#85532, plus three older PRs targeting other branches); this was the one residual, uncovered site in the API-key branch specifically. Fixed by passing base_url (the local variable already holding the correct, override-aware, effective URL) instead of raw_base_url. Verified with a real repro: an explicit_base_url override to api.kimi.com/coding, rewritten by _to_openai_base_url() to api.kimi.com/coding/v1 for the OpenAI client. Both the pre-rewrite and post-rewrite forms match the "api.kimi.com/coding" Anthropic-wrap heuristic, so whether the wrap happens at all doesn't distinguish the bug -- but the EXACT URL string passed to build_anthropic_client does. Before the fix it received the stale, /v1-less URL, inconsistent with the endpoint the underlying OpenAI client was actually pointed at. (An /anthropic-suffixed override wasn't used for the regression test since that rewrite path is separately affected by the not-yet-merged NousResearch#85532 rewrite-policy fix -- this fix and that one are independent and this test isolates just the variable-selection bug.) Added a regression test extending the existing test_auxiliary_explicit_base_anthropic.py file, following its established mocking pattern. Verified as a genuine regression by reverting the fix and confirming the test fails with the exact stale, inconsistent URL. 191/191 pass across four directly related auxiliary_client test files (no regression).
fix(auxiliary): _wrap_if_needed uses the effective (post-override) base_url in the API-key branch No blocking issues found. This is a correct, minimal one-line fix with a strong regression test (asserts the exact URL the Anthropic client is built against, not just the wrap decision). Minor observations:
|
Fixes #85535.
Root cause
In the generic API-key branch of
resolve_provider_client(), when a fallback entry carries anexplicit_base_urloverride, the actual OpenAI client is built with the override (base_url) -- but the final_wrap_if_needed()call still passedraw_base_url, the pre-rewrite value, not the effective URL the client was actually constructed with. Every other_wrap_if_neededcall site was already guarded against this class of bug (#85466, #85532, plus three older PRs); this was the one residual, uncovered site.Fix
Pass
base_url(already holding the correct, override-aware, effective URL) instead ofraw_base_url.Verification
Used a real repro: an
explicit_base_urloverride toapi.kimi.com/coding, rewritten toapi.kimi.com/coding/v1for the OpenAI client. Both forms match the Anthropic-wrap heuristic, so whether the wrap happens doesn't distinguish the bug -- but the exact URL string passed tobuild_anthropic_clientdoes. Before the fix it received the stale,/v1-less URL, inconsistent with the endpoint the underlying OpenAI client actually used.Added a regression test extending the existing test file. Verified as a genuine regression by reverting the fix and confirming the test fails with the exact stale, inconsistent URL.
191/191 pass across four directly related test files (no regression).