Skip to content

[BUG] AI translation gets 502 from OpenAI-compatible gateway while profile test passes #1044

Description

@DDmouth

Bug Description

AI translation fails consistently with HTTP 502 from the configured OpenAI-compatible provider, then falls back to Google Translate which returns 429. The AI Profile connection test passes, but actual translation requests fail.

Environment

  • OS: Windows 11
  • MrRSS Version: 1.3.28 (desktop release)
  • Installation Method: official release installer

Steps To Reproduce

  1. Create an AI Profile pointing to an OpenAI-compatible chat completions endpoint (custom gateway, not api.openai.com).
  2. Run the profile connection test (POST /api/ai/profiles/{id}/test) → passes: connection_success: true, model_available: true, ~2-5s response.
  3. Set translation_provider=ai and ai_translation_profile_id to that profile.
  4. Call POST /api/articles/translate-text with an English text and target_language=zh-CN.
  5. Observe failure: log shows AI translation failed code=request_failed status=502; using Google Translate fallback, then Error translating text: translation api returned status: 429.

Key Observation (mechanism-level)

The same endpoint, same API key, and an equivalent request body (model, messages with system+user prompts, temperature 0.3, max_tokens 2048, stream:false) succeed with HTTP 200 when issued externally (curl, Python urllib, httpx — both HTTP/1.1 and HTTP/2). Only the in-process MrRSS request gets 502.

This suggests the failure is not about the provider or the payload, but about how the translation path constructs its HTTP client vs. how the profile test path does:

  • Profile test (testAIProfileConnection in internal/handlers/ai/ai_profiles_handlers.go) uses a plain &http.Client{} (default transport, HTTP/2 negotiation).
  • Translation path (AITranslatorai.NewClienthttputil.CreateHTTPClient in internal/utils/httputil/httputil.go) uses a transport with ForceAttemptHTTP2: false and an explicit TLSClientConfig (MinVersion TLS1.2, InsecureSkipVerify from env).

Hypothesis: the explicit TLSClientConfig changes the Go TLS ClientHello fingerprint, and some OpenAI-compatible gateways (especially those behind WAF/anti-bot layers) reject that fingerprint with 502. The default transport (used by the passing profile test) negotiates differently and is accepted.

Expected Behavior

  • Translation requests should use the same HTTP client construction as the profile test path (which demonstrably works), or
  • The HTTP client should be configurable (custom headers / User-Agent / HTTP version) per profile so gateway-specific quirks can be worked around.

Additional Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions