Skip to content

Feat/retry mechanism#1504

Open
xiaoyouqiang wants to merge 6 commits into
tmc:mainfrom
xiaoyouqiang:feat/retry-mechanism
Open

Feat/retry mechanism#1504
xiaoyouqiang wants to merge 6 commits into
tmc:mainfrom
xiaoyouqiang:feat/retry-mechanism

Conversation

@xiaoyouqiang

@xiaoyouqiang xiaoyouqiang commented Jun 10, 2026

Copy link
Copy Markdown

PR Checklist

  • Read the Contributing documentation.
  • Read the Code of conduct documentation.
  • Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • Describes the source of new concepts.
  • References existing implementations as appropriate.
  • Contains test coverage for new functions.
  • Passes all golangci-lint checks.

Your Name and others added 6 commits April 24, 2026 12:07
Add EnableThinking and ThinkingBudget fields to ChatRequest for Qwen
deep thinking mode via OpenAI-compatible API. This allows toggling
Qwen's reasoning mode and limiting thinking token budget.
Add opt-in automatic retry for transient HTTP failures across all LLM
providers. The mechanism handles:

- HTTP 429 (rate limit), 500, 502, 503, 504 (server errors)
- Network errors (connection refused, DNS failure, TLS timeout)
- Provider body-level errors (e.g., ERNIE HTTP 200 + error_code:18)
- Retry-After header: waits server-specified duration instead of backoff

Two internal retry strategies, unified under the same RetryConfig API:
- RetryOnError (application-layer): OpenAI, Anthropic, ERNIE — checks
  network errors, HTTP status codes, AND body-level errors via MapError
- RetryTransport (transport-layer): Ollama, Cohere, Cloudflare,
  HuggingFace, Llamafile, Maritaca — checks HTTP status codes and
  network errors at the RoundTripper level

Usage:
  llm, _ := openai.New(
      openai.WithToken("sk-xxx"),
      openai.WithRetryConfig(httputil.DefaultRetryConfig()),
  )

Also includes:
- ERNIE error_code:17 fix (daily quota was wrongly classified as rate limit)
- ERNIE error_code:19 coverage (total request limit)
- 46 unit/integration tests
- Documentation in doc.go and httputil/doc.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- errcheck: discard WithRetryAfter return value with _ =
- gosec G404: add nolint comments for jitter rand.Float64
- gofmt: format retry.go, retry_test.go, anthropicllm_option.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant