fix: honor channel affinity skip-retry when channel is disabled#3333
Conversation
WalkthroughThis change enhances channel affinity handling by adding logic to skip retries when a preferred channel is disabled. The middleware now calls Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
🧹 Nitpick comments (1)
service/channel_affinity_template_test.go (1)
119-177: Add the missingfalse-overrides-meta case to this table.Right now this proves
trueoverride and metadata fallback, but not that an explicitfalsebeatsmeta.SkipRetry=true. A buggy implementation likeflag || meta.SkipRetrywould still pass.🧪 Suggested table entry
{ name: "explicit skip retry flag in context", ctx: func() *gin.Context { ctx := buildChannelAffinityTemplateContextForTest(channelAffinityMeta{ RuleName: "rule-explicit-flag", SkipRetry: false, UsingGroup: "default", ModelName: "gpt-5", }) ctx.Set(ginKeyChannelAffinitySkipRetry, true) return ctx }, want: true, }, + { + name: "explicit false flag overrides matched rule meta", + ctx: func() *gin.Context { + ctx := buildChannelAffinityTemplateContextForTest(channelAffinityMeta{ + RuleName: "rule-explicit-false", + SkipRetry: true, + UsingGroup: "default", + ModelName: "gpt-5", + }) + ctx.Set(ginKeyChannelAffinitySkipRetry, false) + return ctx + }, + want: false, + }, { name: "fallback to matched rule meta",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@service/channel_affinity_template_test.go` around lines 119 - 177, Add a test case that verifies an explicit false flag in context overrides meta.SkipRetry=true so a buggy OR-based check (e.g., flag || meta.SkipRetry) would fail; specifically, in TestShouldSkipRetryAfterChannelAffinityFailure add an entry where buildChannelAffinityTemplateContextForTest is given channelAffinityMeta with SkipRetry: true but then ctx.Set(ginKeyChannelAffinitySkipRetry, false) is called, and assert want: false when calling ShouldSkipRetryAfterChannelAffinityFailure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@service/channel_affinity_template_test.go`:
- Around line 119-177: Add a test case that verifies an explicit false flag in
context overrides meta.SkipRetry=true so a buggy OR-based check (e.g., flag ||
meta.SkipRetry) would fail; specifically, in
TestShouldSkipRetryAfterChannelAffinityFailure add an entry where
buildChannelAffinityTemplateContextForTest is given channelAffinityMeta with
SkipRetry: true but then ctx.Set(ginKeyChannelAffinitySkipRetry, false) is
called, and assert want: false when calling
ShouldSkipRetryAfterChannelAffinityFailure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 06cdd65e-db94-435a-866c-b352a79fa3e7
📒 Files selected for processing (3)
middleware/distributor.goservice/channel_affinity.goservice/channel_affinity_template_test.go
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests