Skip to content

feat: add passive channel monitoring mode - #5592

Merged
seefs001 merged 4 commits into
QuantumNous:mainfrom
exherb:passive-channel-monitoring
Jun 22, 2026
Merged

feat: add passive channel monitoring mode#5592
seefs001 merged 4 commits into
QuantumNous:mainfrom
exherb:passive-channel-monitoring

Conversation

@exherb

@exherb exherb commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • This PR was AI-assisted. The description below was structured from the implementation and local verification results instead of pasting raw model output.

📝 变更描述 / Description

新增渠道测试模式配置 monitor_setting.channel_test_mode,支持在现有定时全量测试之外选择“仅被动恢复”模式。

  • scheduled_all 保持原行为:后台按间隔测试所有非手动禁用渠道,可自动禁用失败渠道,也可恢复自动禁用渠道。
  • passive_recovery 下,真实接口请求命中渠道并匹配自动禁用规则时才会禁用渠道;后台定时任务只测试 自动禁用 状态的渠道,用于恢复,不再主动探测启用渠道。
  • 渠道测试本地失败时不会被当作恢复成功,避免本地不支持测试的渠道被误开启。
  • 在默认前端监控设置页加入模式选择,并补齐 en/zh/fr/ja/ru/vi 翻译。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

通过:

GOPROXY=https://proxy.golang.org,direct go test ./controller -run 'TestSelectChannelsForAutomaticTest|TestResolveChannelTestUserIDUsesRequestUser|TestSettleTestQuotaUsesTieredBilling|TestBuildTestLogOtherInjectsTieredInfo'
go test ./setting/operation_setting
cd web/default && bun run typecheck
cd web/default && bun run build
cd web/default && bun run i18n:sync

web/default/src/i18n/locales/_reports/_sync-report.json 显示 en/fr/ja/ru/vi/zh 的 missing/extras/untranslated 均为 0。

说明:

cd web/default && bun run lint

当前失败于既有未修改文件中的 React hooks / query lint 规则(例如 src/components/ai-elements/web-preview.tsxsrc/components/data-table/hooks/use-debounced-column-filter.tssrc/features/channels/components/dialogs/* 等),本 PR 修改的文件未出现在 lint 报错列表中。

Summary by CodeRabbit

  • New Features
    • Added a configurable “Channel test mode” setting with options: “Scheduled full test” (probes non-manually-disabled channels) and “Passive recovery only” (rechecks only auto-disabled channels after request failures).
  • Bug Fixes
    • Improved channel enablement logic so channels are only enabled after local test success.
  • Documentation
    • Added UI translations, labels, and mode-specific helper text for channel testing across multiple languages.
  • Tests
    • Added coverage for channel selection behavior per test mode.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ebb36b7-c6fb-4d18-8df1-a262d035cc1d

📥 Commits

Reviewing files that changed from the base of the PR and between 091bb86 and 7e5c6eb.

📒 Files selected for processing (7)
  • setting/operation_setting/monitor_setting.go
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
✅ Files skipped from review due to trivial changes (6)
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/zh.json
  • web/default/src/i18n/locales/vi.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • setting/operation_setting/monitor_setting.go

Walkthrough

Introduces a ChannelTestMode setting (scheduled_all / passive_recovery) to MonitorSetting. The channel-test controller gains a shared testChannels worker, a selectChannelsForAutomaticTest filter, and a testAutoDisabledChannels path. The scheduler branches on the new mode. A frontend Select control and i18n strings across six locales expose the setting.

Changes

Channel Test Mode Feature

Layer / File(s) Summary
ChannelTestMode setting constants and MonitorSetting field
setting/operation_setting/monitor_setting.go
Adds ChannelTestMode field, ChannelTestModeScheduledAll / ChannelTestModePassiveRecovery constants, default initialization to scheduled_all, and env-based override logic in GetMonitorSetting that preserves passive_recovery while forcing scheduled_all otherwise.
testChannels worker, selectChannelsForAutomaticTest, and scheduler branching
controller/channel-test.go
Introduces testChannels with concurrency guard and allowDisable flag, tightens auto-enable to require result.localErr == nil, adds selectChannelsForAutomaticTest for mode-based channel filtering, adds testAutoDisabledChannels for passive recovery, and branches AutomaticallyTestChannels on ChannelTestMode.
Unit tests for selectChannelsForAutomaticTest
controller/channel_test_internal_test.go
Adds two tests covering passive recovery mode (only auto-disabled channels selected) and scheduled mode (enabled and auto-disabled, excluding manually disabled).
Frontend type contract and defaults
web/default/src/features/system-settings/types.ts, web/default/src/features/models/components/drawers/model-mutate-drawer.tsx, web/default/src/features/system-settings/models/index.tsx
Extends ModelSettings type with monitor_setting.channel_test_mode string union, and adds default initializations ('scheduled_all') in two model component locations.
Form schema, normalization, validation, and section wiring
web/default/src/features/system-settings/models/routing-reliability-section.tsx, web/default/src/features/system-settings/models/section-registry.tsx
Adds ChannelTestMode union type and Zod enum validation, introduces normalizeChannelTestMode helper to coerce optional strings to valid modes, wires the field through buildFormDefaults, normalizeDefaults, and normalizeFormValues, and passes the value from the section registry into RoutingReliabilitySection.
Channel test mode Select field and conditional description
web/default/src/features/system-settings/models/routing-reliability-section.tsx
Watches monitor_setting.channel_test_mode, renders a Select with Scheduled full test and Passive recovery only options, and makes the auto_test_channel_minutes description conditional on the active mode.
i18n translations (6 locales)
web/default/src/i18n/locales/en.json, web/default/src/i18n/locales/fr.json, web/default/src/i18n/locales/ja.json, web/default/src/i18n/locales/ru.json, web/default/src/i18n/locales/vi.json, web/default/src/i18n/locales/zh.json
Adds Channel test mode label, frequency description for checking auto-disabled channels, Passive recovery only option, Scheduled full test label, and its explanatory description distinguishing full probing from passive recovery behavior across all six locales.

Sequence Diagram(s)

sequenceDiagram
    participant Scheduler as AutomaticallyTestChannels
    participant Setting as GetMonitorSetting
    participant Selector as selectChannelsForAutomaticTest
    participant Worker as testChannels

    Scheduler->>Setting: read ChannelTestMode
    alt passive_recovery
        Scheduler->>Selector: mode=passive_recovery
        Selector-->>Scheduler: auto-disabled channels only
        Scheduler->>Worker: testChannels(channels, allowDisable=false)
    else scheduled_all
        Scheduler->>Selector: mode=scheduled_all
        Selector-->>Scheduler: enabled + auto-disabled channels
        Scheduler->>Worker: testChannels(channels, allowDisable=false)
    end
    Worker-->>Scheduler: results, enable/disable per channel
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • QuantumNous/new-api#2119: Overlaps on auto-test scheduling interval handling in controller/channel-test.go and monitor_setting.go's AutoTestChannelMinutes configuration.

Suggested reviewers

  • seefs001

Poem

🐇 Hop hop, the channels align,
Passive recovery, a gentler sign!
Scheduled tests probe far and wide,
Auto-disabled get a second try with pride.
The rabbit checks each mode with care —
scheduled_all or passive, it's fair! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add passive channel monitoring mode' accurately describes the main feature introduced in this PR—a new passive recovery mode for channel monitoring.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/default/src/i18n/locales/en.json`:
- Around line 3631-3632: The description for "Scheduled full test" in the
en.json file overstates the actual behavior by claiming it "probes all channels"
when it actually excludes manually disabled channels. Update the longer
description string that starts with "Scheduled full test probes all channels" to
clarify that the scheduled mode only tests non-manually-disabled channels,
thereby removing the misleading implication that all channels are tested
regardless of their manual disable status.

In `@web/default/src/i18n/locales/ja.json`:
- Line 3631: The Japanese translation for the "Scheduled full test" key in the
ja.json file uses unnatural phrasing. Replace the current value "スケジュール全体テスト"
with the more natural and clearer Japanese term "定期フルテスト" to improve readability
and consistency with the description on Line 3632.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05853858-40a8-44d7-bb07-8fe7906ca952

📥 Commits

Reviewing files that changed from the base of the PR and between 55b00fc and 184d972.

📒 Files selected for processing (13)
  • controller/channel-test.go
  • controller/channel_test_internal_test.go
  • setting/operation_setting/monitor_setting.go
  • web/default/src/features/system-settings/integrations/monitoring-settings-section.tsx
  • web/default/src/features/system-settings/operations/index.tsx
  • web/default/src/features/system-settings/operations/section-registry.tsx
  • web/default/src/features/system-settings/types.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json

Comment thread web/default/src/i18n/locales/en.json Outdated
Comment thread web/default/src/i18n/locales/ja.json Outdated
@exherb

exherb commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

hi, how to review this?

…itoring

# Conflicts:
#	web/default/src/features/system-settings/integrations/monitoring-settings-section.tsx
#	web/default/src/features/system-settings/operations/index.tsx
#	web/default/src/features/system-settings/operations/section-registry.tsx
#	web/default/src/features/system-settings/types.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@web/default/src/features/system-settings/models/routing-reliability-section.tsx`:
- Around line 386-414: Remove the unused items prop from the Select component.
The items prop (containing the array with value and label objects for
'scheduled_all' and 'passive_recovery') is not part of the Select component API
from `@base-ui/react/select` and will be ignored. The SelectItem children
components with the same values ('scheduled_all' and 'passive_recovery') already
define the select options, making the items prop redundant. Delete the entire
items array and the prop assignment while keeping the SelectItem children
intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24659143-4cfc-4774-961b-9ebe8ff20129

📥 Commits

Reviewing files that changed from the base of the PR and between 770cc8f and 091bb86.

📒 Files selected for processing (11)
  • web/default/src/features/models/components/drawers/model-mutate-drawer.tsx
  • web/default/src/features/system-settings/models/index.tsx
  • web/default/src/features/system-settings/models/routing-reliability-section.tsx
  • web/default/src/features/system-settings/models/section-registry.tsx
  • web/default/src/features/system-settings/types.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
💤 Files with no reviewable changes (2)
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
✅ Files skipped from review due to trivial changes (4)
  • web/default/src/features/models/components/drawers/model-mutate-drawer.tsx
  • web/default/src/features/system-settings/models/index.tsx
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json

@exherb

exherb commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@seefs001 有空帮忙 review 下不?感谢啦

@seefs001

Copy link
Copy Markdown
Collaborator

看了下没问题可以合并,把这个冲突改掉就ok了。

@seefs001 seefs001 self-assigned this Jun 22, 2026
@exherb

exherb commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

好呢

…itoring

# Conflicts:
#	setting/operation_setting/monitor_setting.go
@exherb

exherb commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@seefs001 fixed

@seefs001
seefs001 merged commit efd6c44 into QuantumNous:main Jun 22, 2026
1 check passed
jahnli added a commit to jahnli/new-api that referenced this pull request Jun 22, 2026
Merge upstream changes including:
- ClickHouse log database support (QuantumNous#5663)
- System task for persistent log cleanup progress
- Passive channel monitoring mode (QuantumNous#5592)
- Channel test environment toggle
- Node name defaults to hostname when NODE_NAME unset (QuantumNous#5659)
- tsgo for web type checking
- Refactored database type detection API (UsingMainDatabase/UsingLogDatabase)

Conflict resolution:
- AGENTS.md, CLAUDE.md: kept local Chinese version, added UsingMainDatabase/UsingLogDatabase docs
- controller/channel-test.go: kept AIHubError naming, adopted allowDisable + localErr checks
- docker-compose.yml: kept ai-hub naming, added ClickHouse config
- model/redemption.go: kept local deletion (feature removed)
- web/default/package.json: adopted upstream tsgo/oxlint/oxfmt toolchain
- use-sidebar-data.ts: kept local (no redemption codes)
- i18n locale files: kept local translations, added 8 new upstream keys
ruanhangjian pushed a commit to ruanhangjian/new-api that referenced this pull request Jul 11, 2026
* feat: add passive channel monitoring mode

* fix: clarify passive monitor mode copy
noah-wung pushed a commit to noah-wung/new-api that referenced this pull request Jul 17, 2026
* feat: add passive channel monitoring mode

* fix: clarify passive monitor mode copy
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
* feat: add passive channel monitoring mode

* fix: clarify passive monitor mode copy
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* feat: add passive channel monitoring mode

* fix: clarify passive monitor mode copy
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.

2 participants