Skip to content

fix: normalize httpx.URL base_url + strip thinking signatures for third-party endpoints#6289

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-6b365d9a
Apr 8, 2026
Merged

fix: normalize httpx.URL base_url + strip thinking signatures for third-party endpoints#6289
teknium1 merged 1 commit into
mainfrom
hermes/hermes-6b365d9a

Conversation

@teknium1

@teknium1 teknium1 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Two linked fixes for MiniMax Anthropic-compatible fallback crashes reported by Discord user tipofthespear:

Bug 1: httpx.URL has no rstrip

_try_activate_fallback() stored fb_client.base_url (an httpx.URL object) directly into _anthropic_base_url, then passed it to build_anthropic_client()_requires_bearer_auth().rstrip()AttributeError.

Fix: Added _normalize_base_url_text() helper that coerces httpx.URL to str. Applied to _is_third_party_anthropic_endpoint(), _requires_bearer_auth(), and build_anthropic_client(). Also fixed _try_activate_fallback() to use the already-stringified fb_base_url instead of the raw httpx.URL from getattr(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 accepts base_url and 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 stripping
  • run_agent.py — Fallback uses stringified fb_base_url, passes _anthropic_base_url to kwargs builder

Test plan

  • python -m pytest tests/agent/test_anthropic_adapter.py -n0 -q — 116 passed
  • python -m pytest tests/run_agent/test_run_agent.py -n0 -q — 228 passed
  • E2E: httpx.URL objects accepted by all helper functions
  • E2E: MiniMax fallback activation succeeds with httpx.URL base_url
  • E2E: Third-party endpoint → all thinking blocks stripped
  • E2E: Direct Anthropic → latest assistant keeps signed blocks
  • E2E: Redacted thinking also stripped for third-party

Fixes #4944. Supersedes #4945, #4968.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix fallback activation when provider client base_url is an httpx.URL

2 participants