Skip to content

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

@kshitijk4poor

Description

@kshitijk4poor

Summary

MiniMax fallback activation can crash inside run_agent.py::_try_activate_fallback() when the routed provider client exposes base_url as an httpx.URL object instead of a plain string.

Observed runtime symptom:

  • AttributeError: 'URL' object has no attribute 'rstrip'

This is similar in shape to #1071 (type assumption bug in a hot runtime path), but the failing assumption here is URL normalization during fallback activation / Anthropic-compatible auth detection.

Root cause

Current fallback activation does this:

  • resolves a provider client
  • detects Anthropic-compatible mode from fb_client.base_url
  • builds an Anthropic client for providers like MiniMax

The Anthropic adapter helpers currently assume base_url is always a string and call base_url.rstrip("/") in helper paths such as:

  • _requires_bearer_auth()
  • _is_third_party_anthropic_endpoint()

That crashes when the provider router returns an OpenAI/httpx-style client whose base_url is an httpx.URL object.

Minimal reproduction from current main:

from httpx import URL
from agent.anthropic_adapter import _requires_bearer_auth
_requires_bearer_auth(URL("https://api.minimax.io/anthropic"))
# AttributeError: 'URL' object has no attribute 'rstrip'

Why this matters

This makes the fallback chain brittle for Anthropic-compatible providers, especially MiniMax, even when the provider is otherwise configured correctly.

Proposed fix

  • normalize base_url to plain text before provider/auth inspection in agent/anthropic_adapter.py
  • keep fallback state in run_agent.py string-normalized when switching to Anthropic-compatible fallback providers
  • add regression coverage for both:
    • Anthropic adapter handling httpx.URL
    • _try_activate_fallback() with a MiniMax-style fallback client exposing base_url as httpx.URL

Validation

I reproduced the crash locally and verified the fix with targeted tests. I also checked broader suite behavior on fresh origin/main; unrelated existing failures remain in tests/tools/test_file_read_guards.py on my machine and are not introduced by this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions