Skip to content

feat: 增加渠道重试优先级模式和避开已用渠道功能 - #2754

Closed
zhang2023san-oss wants to merge 4971 commits into
QuantumNous:mainfrom
zhang2023san-oss:feature/retry-priority-modes
Closed

feat: 增加渠道重试优先级模式和避开已用渠道功能#2754
zhang2023san-oss wants to merge 4971 commits into
QuantumNous:mainfrom
zhang2023san-oss:feature/retry-priority-modes

Conversation

@zhang2023san-oss

@zhang2023san-oss zhang2023san-oss commented Jan 26, 2026

Copy link
Copy Markdown

功能1:重试时避开已尝试渠道

  • 新增配置选项 RetryAvoidUsedChannelEnabled
  • 重试时自动排除已经尝试过的渠道
  • 前端新增开关按钮支持动态配置

功能2:渠道重试优先级模式

实现两种渠道重试的优先级模式:

  • Sequential(顺序模式):同一优先级内尝试所有渠道后才降级到下一优先级
  • Round-robin(轮询模式):每个优先级轮流尝试,实现负载均衡

代码质量改进

  • 添加 validateOptionValue 函数在保存前验证配置值
  • 修复 RetryPriorityMode 验证逻辑,防止无效值保存到数据库
  • 修复自动分组模式下可能跳过较低优先级的问题
  • 为 RetryParam 及其所有方法添加完整的英文文档注释
  • 使用中文错误消息,符合项目代码风格

修改的文件

  • common/constants.go - 新增配置常量
  • model/option.go - 添加配置项的加载、验证和更新逻辑
  • controller/relay.go - 在重试循环中记录已使用的渠道ID
  • service/channel_select.go - 新增 UsedChannelIds 字段和优先级处理逻辑
  • model/ability.go & model/channel_cache.go - 在渠道查询时应用排除逻辑
  • web/* - 前端UI控件和国际化文本

Summary by CodeRabbit

  • New Features
    • Added option to avoid reusing channels during retries, reducing redundant failures with the same channel
    • Introduced two retry priority modes: Sequential (exhaust current priority level before downgrading) and Round-robin (cycle through priorities)
    • New retry configuration settings available in the monitoring panel

✏️ Tip: You can customize this high-level summary in your review settings.

creamlike1024 and others added 30 commits November 27, 2025 17:24
…-i2v

Gemini Veo3.1[AI Studio]增加图生视频支持
Ensure image file is closed using defer after opening.
…edit

Gemini Image系列支持图像编辑
…d-oai

feat: 视频下载和界面预览统一使用OAI标准接口
…-err-code

fix(aws): extract HTTP status code from AWS SDK errors
…na-err

fix: nano-banana not compatible imageSize
…nce-playground-debugging

feat(playground): enhance SSE debugging and add image paste support with i18n
fix: nano banana pro 4k(StreamScannerMaxBufferMB env)
feat: glm coding plan && kimi coding plan
fix(i18n): fill missing translations in i18n.
…ix-gemini-ImageConfig

Revert "fix: gemini image correct generationConfig"
…emini-veo3.1-i2v

Revert "Gemini Veo3.1[AI Studio]增加图生视频支持"
…emini-image-edit

Revert "Gemini Image系列支持图像编辑"
…ix-nano-banana-err

Revert "fix: nano-banana not compatible imageSize"
…dd-gemini-3-pro-image-preview-oai

Revert "OAI生图接口支持gemini 3 pro image preview"
xyfacai and others added 26 commits January 6, 2026 11:14
…task-logging

fix(task): 修复使用 auto 分组时 Task Relay 不记录日志和不扣费的问题
Use the native Gemini Models API (/v1beta/models) instead of the OpenAI-compatible
path when listing models for Gemini channels, improving compatibility with
third-party Gemini-format providers that don't implement OpenAI routes.

- Add paginated model listing with timeout and optional proxy support
- Select an enabled key for multi-key Gemini channels
…etchModels

fix: remove Minimax from FETCHABLE channels
…tchModels

fix(gemini): fetch model list via native v1beta/models endpoint
* feat: /v1/chat/completion -> /v1/response
…-auto-disable

feat: status code auto-disable configuration
* fix: setting ui

* fix: rm global.chat_completions_to_responses_policy

* fix: rm global.chat_completions_to_responses_policy
…Names

fix: clean propertyNames for gemini function
…t-param-override

feat: channel testing supports parameter overriding
* feat: codex channel

* feat: codex channel

* feat: codex oauth flow

* feat: codex refresh cred

* feat: codex usage

* fix: codex err message detail

* fix: codex setting ui

* feat: codex refresh cred task

* fix: import err

* fix: codex store must be false

* fix: chat -> responses tool call

* fix: chat -> responses tool call
…sing Claude's rendering logs, the two approaches handle input rendering differently.
## 功能1:重试时避开已尝试渠道
- 新增配置选项 RetryAvoidUsedChannelEnabled
- 重试时自动排除已经尝试过的渠道
- 前端新增开关按钮支持动态配置

## 功能2:渠道重试优先级模式
实现两种渠道重试的优先级模式:
- Sequential(顺序模式):同一优先级内尝试所有渠道后才降级到下一优先级
- Round-robin(轮询模式):每个优先级轮流尝试,实现负载均衡

## 代码质量改进
- 添加 validateOptionValue 函数在保存前验证配置值
- 修复 RetryPriorityMode 验证逻辑,防止无效值保存到数据库
- 修复自动分组模式下可能跳过较低优先级的问题
- 为 RetryParam 及其所有方法添加完整的英文文档注释
- 使用中文错误消息,符合项目代码风格

## 修改的文件
- common/constants.go - 新增配置常量
- model/option.go - 添加配置项的加载、验证和更新逻辑
- controller/relay.go - 在重试循环中记录已使用的渠道ID
- service/channel_select.go - 新增 UsedChannelIds 字段和优先级处理逻辑
- model/ability.go & model/channel_cache.go - 在渠道查询时应用排除逻辑
- web/* - 前端UI控件和国际化文本
@coderabbitai

coderabbitai Bot commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces two new configuration flags for channel retry behavior: RetryAvoidUsedChannelEnabled to skip previously failed channels during retries, and RetryPriorityMode to support sequential (priority-downgrade) and round-robin retry strategies. Changes span backend configuration, channel selection logic, service-layer enhancements, and corresponding frontend UI with localization.

Changes

Cohort / File(s) Summary
Configuration Management
common/constants.go, model/option.go
Added two new global flags with runtime validation: RetryAvoidUsedChannelEnabled (bool, default false) and RetryPriorityMode (string, default "sequential"). Option validation enforces "sequential" or "round-robin" values for RetryPriorityMode.
Channel Selection Core
model/ability.go, model/channel_cache.go
Updated GetChannel and GetRandomSatisfiedChannel to accept excludeIds parameter for filtering out previously used channels. Added round-robin priority selection logic when RetryPriorityMode == "round-robin". Returns nil for exhausted priorities instead of errors to signal retry escalation.
Relay and Controller
controller/relay.go
Enhanced retry loop to advance to next priority when current priority yields no channels. Constructs exclusion set from used channels when RetryAvoidUsedChannelEnabled is on. Logs channel selection details and returns API error when all channels exhausted.
Service Layer Retry Tracking
service/channel_select.go
Introduced new RetryParam struct with methods to track used channels (UsedChannelIds), manage retry count, and advance priority index (CurrentPriorityIndex). Updated CacheGetRandomSatisfiedChannel to pass exclusion set and handle priority escalation for auto-group retries.
Frontend Settings UI
web/src/pages/Setting/Operation/SettingsMonitoring.jsx, web/src/components/settings/OperationSetting.jsx
Added toggle switch for RetryAvoidUsedChannelEnabled and dropdown selector for RetryPriorityMode ("sequential"/"round-robin") in monitoring settings panel.
Localization
web/src/i18n/locales/en.json, web/src/i18n/locales/zh.json
Added seven new translation keys covering retry avoidance feature label/description and retry mode options.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Relay as controller/relay
    participant ChannelCache as model/channel_cache
    participant Ability as model/ability
    participant DB as Database

    Client->>Relay: Request (initial retry=0)
    loop Retry Loop (sequential priorities)
        Relay->>ChannelCache: GetRandomSatisfiedChannel(group, model, retry, excludeIds)
        ChannelCache->>Ability: GetChannel(group, model, retry, excludeIds)
        Ability->>DB: Query channels (priority-based, exclude used)
        DB-->>Ability: Filtered channels
        Ability-->>ChannelCache: Channel or nil
        
        alt Channel Found
            ChannelCache-->>Relay: Channel + weight data
            Relay->>Relay: Log selection, return channel
            Relay-->>Client: Success
        else No Channel (priority exhausted)
            ChannelCache-->>Relay: nil, nil
            Relay->>Relay: Add used channel to excludeIds
            Relay->>Relay: Increase priority index
            Note over Relay: Continue loop with next priority
        end
    end
    
    alt All Priorities Exhausted
        Relay-->>Client: API Error (all channels excluded/unavailable)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • xyfacai

Poem

🐰 A clever rabbit hops through channels bright,
Remembering which ones failed last night,
Sequential or round-robin, take your pick—
Retry smarter, not just retry quick!
Smart exclusions make the magic click! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main additions: retry priority modes for channels and a feature to avoid already-used channels during retries.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@StageDog

Copy link
Copy Markdown
Contributor

any progress?

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.