fix: normalize httpx.URL base_url + strip thinking signatures for third-party endpoints#6289
Merged
Conversation
…rd-party endpoints Two linked fixes for MiniMax Anthropic-compatible fallback: 1. Normalize httpx.URL to str before calling .rstrip() in auth/provider detection helpers. Some client objects expose base_url as httpx.URL, not str — crashed with AttributeError in _requires_bearer_auth() and _is_third_party_anthropic_endpoint(). Also fixes _try_activate_fallback() to use the already-stringified fb_base_url instead of raw httpx.URL. 2. Strip Anthropic-proprietary thinking block signatures when targeting third-party Anthropic-compatible endpoints (MiniMax, Azure AI Foundry, self-hosted proxies). These endpoints cannot validate Anthropic's signatures and reject them with HTTP 400 'Invalid signature in thinking block'. Now threads base_url through convert_messages_to_anthropic() → build_anthropic_kwargs() so signature management is endpoint-aware. Based on PR #4945 by kshitijk4poor (rstrip fix). Fixes #4944.
This was referenced Apr 8, 2026
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
Two linked fixes for MiniMax Anthropic-compatible fallback crashes reported by Discord user tipofthespear:
Bug 1:
httpx.URLhas norstrip_try_activate_fallback()storedfb_client.base_url(anhttpx.URLobject) directly into_anthropic_base_url, then passed it tobuild_anthropic_client()→_requires_bearer_auth()→.rstrip()→AttributeError.Fix: Added
_normalize_base_url_text()helper that coerceshttpx.URLtostr. Applied to_is_third_party_anthropic_endpoint(),_requires_bearer_auth(), andbuild_anthropic_client(). Also fixed_try_activate_fallback()to use the already-stringifiedfb_base_urlinstead of the rawhttpx.URLfromgetattr(fb_client, 'base_url').Based on PR #4945 by @kshitijk4poor — cherry-picked the rstrip fix with their authorship preserved.
Bug 2: "Invalid signature in thinking block" on third-party endpoints
Thinking block signatures are Anthropic-proprietary. When a session with Anthropic thinking blocks falls back to MiniMax's Anthropic-compatible endpoint, MiniMax rejects the signatures with HTTP 400. The user sees a cycle: Hermes recovers by stripping thinking blocks, but new ones accumulate and eventually get sent to the third-party endpoint again.
Fix:
convert_messages_to_anthropic()now acceptsbase_urland checks_is_third_party_anthropic_endpoint(). For third-party endpoints, ALL thinking/redacted_thinking blocks are stripped from ALL assistant messages. For direct Anthropic, existing behavior is preserved (signed blocks kept in latest assistant message for reasoning continuity).Threaded through:
build_anthropic_kwargs(base_url=...)→convert_messages_to_anthropic(base_url=...).Changes
agent/anthropic_adapter.py—_normalize_base_url_text()helper, base_url-aware signature strippingrun_agent.py— Fallback uses stringifiedfb_base_url, passes_anthropic_base_urlto kwargs builderTest plan
python -m pytest tests/agent/test_anthropic_adapter.py -n0 -q— 116 passedpython -m pytest tests/run_agent/test_run_agent.py -n0 -q— 228 passedFixes #4944. Supersedes #4945, #4968.