fix: retry channel tests with stream when configured - #3303
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (6)
WalkthroughAdds an optional stream-retry mechanism for channel tests: when a non-stream test fails with configured HTTP status codes or error keywords, the backend may retry the same test with streaming enabled. Settings, UI controls, i18n entries, and unit tests were added to configure and validate this behavior. Changes
Sequence DiagramsequenceDiagram
participant User as User/Admin
participant Frontend as Frontend
participant API as Backend API
participant Monitor as Monitor Setting
participant Upstream as Upstream Service
User->>Frontend: Click "Test Channel"
Frontend->>API: POST /test-channel?manual_test=true (isStream=false)
API->>Upstream: Send non-stream request
Upstream-->>API: 400 + error text
API->>Monitor: shouldRetryChannelTestWithStream(400, errText)
Monitor-->>API: true
API->>Upstream: Retry request with isStream=true
Upstream-->>API: 200 OK
API-->>Frontend: Return aggregated result (statusCode, duration)
Frontend-->>User: Display test result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@controller/channel-test.go`:
- Around line 52-64: The wrapper testChannelWithOptionalStreamRetry currently
hides a retry and returns only the first attempt's timing, causing callers
(e.g., UpdateResponseTime and ChannelDisableThreshold) to include the failed
probe in latency; change testChannelWithOptionalStreamRetry to return the actual
successful-attempt result or a retried flag (e.g., return (testResult, bool
retried) or include a duration in testResult), adjust callers that call
testChannelWithOptionalStreamRetry to use the successful attempt's duration for
UpdateResponseTime/ChannelDisableThreshold, and ensure the retry path (when
shouldRetryChannelTestWithStream(result) is true and you call testChannel(...,
true)) propagates the second call's timing and sets retried=true so the
intentional first failure is not used for health-check latency.
- Around line 45-49: The retry logic is checking result.newAPIError.StatusCode
(shouldRetryChannelTestWithStream) but upstream errors are being wrapped as
http.StatusInternalServerError in testChannel, so preserve the original upstream
status before wrapping: ensure testChannel stores the upstream HTTP status (e.g.
as a field on testResult or by setting newAPIError.StatusCode to the upstream
status) so shouldRetryChannelTestWithStream sees the real upstream code; update
either testChannel's error construction or testResult to carry upstreamStatus
and make shouldRetryChannelTestWithStream consult that upstreamStatus (or the
preserved StatusCode) when calling
operation_setting.ShouldRetryChannelTestWithStream.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c098eba8-1706-4708-951e-c03a7ca1aeed
📒 Files selected for processing (15)
controller/channel-test.gocontroller/option.gosetting/operation_setting/monitor_setting.gosetting/operation_setting/monitor_setting_test.goweb/src/components/settings/OperationSetting.jsxweb/src/components/table/channels/modals/ModelTestModal.jsxweb/src/hooks/channels/useChannelsData.jsxweb/src/i18n/locales/en.jsonweb/src/i18n/locales/fr.jsonweb/src/i18n/locales/ja.jsonweb/src/i18n/locales/ru.jsonweb/src/i18n/locales/vi.jsonweb/src/i18n/locales/zh-CN.jsonweb/src/i18n/locales/zh-TW.jsonweb/src/pages/Setting/Operation/SettingsMonitoring.jsx
Closes #3298
Summary
stream=truewhen the configured status codes and error keywords matchDetails
monitor_setting.channel_test_stream_retry_enabledmonitor_setting.channel_test_stream_retry_status_codesmonitor_setting.channel_test_stream_retry_keywords400stream must be set to trueCloses 渠道自动测试硬编码为非流式,导致强制流式的渠道(如部分 Codex/Azure 接口)测试失败并无法自动启用/重试 #3298
Summary
manual_test=trueflag so user-selected test behavior is preservedSummary by CodeRabbit
New Features
Tests
Documentation