Skip to content

fix(auxiliary): _wrap_if_needed uses the effective (post-override) base_url in the API-key branch - #85632

Open
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/auxiliary-client-api-key-wrap-base-url
Open

fix(auxiliary): _wrap_if_needed uses the effective (post-override) base_url in the API-key branch#85632
ygd58 wants to merge 1 commit into
NousResearch:mainfrom
ygd58:fix/auxiliary-client-api-key-wrap-base-url

Conversation

@ygd58

@ygd58 ygd58 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #85535.

Root cause

In the generic API-key branch of resolve_provider_client(), when a fallback entry carries an explicit_base_url override, the actual OpenAI client is built with the override (base_url) -- but the final _wrap_if_needed() call 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 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 of raw_base_url.

Verification

Used a real repro: an explicit_base_url override to api.kimi.com/coding, rewritten to api.kimi.com/coding/v1 for 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 to build_anthropic_client does. 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).

…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).
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API area/config Config system, migrations, profiles P3 Low — cosmetic, nice to have sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 13, 2026
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference, author can ignore or act on any point.

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:

  1. Sibling branch may share the stale-value hazard. The test comment notes the /anthropic-suffix branch is entangled with the separate fix(auxiliary): only rewrite /anthropic to /v1 for dual-surface hosts (salvage #83782) #85532 rewrite-policy fix. Confirm that follow-up covers the sibling branch so the wrap decision there cannot diverge from the actual client endpoint the same way this PR fixes here.

  2. raw_base_url may now be a trap. If raw_base_url is only referenced by this now-fixed branch, consider removing it (or renaming to make "pre-rewrite" explicit) so a future edit can't accidentally reintroduce the mismatch; if it is still used elsewhere, a brief comment at its definition would help.

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

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] API-key branch: _wrap_if_needed receives creds raw_base_url instead of the explicit_base_url override — wrap decision uses wrong URL

3 participants