fix: 清理 stale channel affinity 并继续正常 fallback#3413
fix: 清理 stale channel affinity 并继续正常 fallback#3413constansino wants to merge 2 commits intoQuantumNous:mainfrom
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 (2)
✅ Files skipped from review due to trivial changes (1)
WalkthroughIntroduces a centralized preferred-channel selection helper, changes handling of stale or disabled preferred affinity to clear cache entries (instead of aborting), updates cache-lookup failure behavior to clear affinity, and adds utilities + tests for clearing affinity and recording stale-affinity metadata. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Distributor as Middleware/Distributor
participant Selector as selectPreferredAffinityChannel
participant Cache as ChannelAffinityCache
participant Service as ClearCurrentChannelAffinity
participant Fallback as ChannelSelectionFallback
Client->>Distributor: request arrives (model, group, affinity key)
Distributor->>Selector: check preferred affinity (channel)
Selector->>Cache: CacheGetChannel(affinityKey)
alt cache hit -> channel info available
Selector-->>Selector: validate channel status & group match
alt channel disabled or mismatch
Selector->>Service: ClearCurrentChannelAffinity(reason)
Service-->>Selector: deleted=true
Selector->>Fallback: continue normal selection
Fallback-->>Distributor: select alternate channel
else matches
Selector-->>Distributor: return preferred channel
end
else cache lookup error / miss
Selector->>Service: ClearCurrentChannelAffinity("lookup failed")
Service-->>Selector: deleted=true/false
Selector->>Fallback: continue normal selection
end
Distributor->>Client: forward to chosen channel / respond
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
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)
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@service/channel_affinity.go`:
- Around line 663-677: Clear the leftover per-request retry override when
abandoning an affinity in ClearCurrentChannelAffinity: after successfully
deleting the cache key (cache.DeleteMany) also unset or reset the
request-context value that stores the skip-retry flag (the
ginKeyChannelAffinitySkipRetry / channelAffinityMeta.SkipRetry entry placed by
GetPreferredChannelByAffinity) so that
ShouldSkipRetryAfterChannelAffinityFailure does not inherit a stale SkipRetry
value; you can do this by removing the gin context key or setting it to the
default (false) before calling appendChannelAffinityClearedAdminInfo.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f6d26478-44d0-4120-aafa-03e4b9afb54b
📒 Files selected for processing (4)
middleware/distributor.gomiddleware/distributor_test.goservice/channel_affinity.goservice/channel_affinity_cache_test.go
|
已根据 CodeRabbit 的评论补上最后一个修复:清理 stale affinity 时同步重置请求上下文里的 skip-retry 状态,避免后续 relay retry 误继承旧 affinity。另已把 issue / PR 标题和正文改成中文模板,当前关联 issue 为 #3414。 |
💡 沟通提示 / Pre-submission
📝 变更描述 / Description
当 channel affinity 命中的首选渠道已经失效、缺失,或已经不再匹配当前 group/model 时,原逻辑会被这条 stale affinity 卡住,导致请求不能继续正常选路。
这个 PR 做了两件事:
skip retry状态清掉,避免controller/relay.go后续重试逻辑误继承旧 affinity 的SkipRetryOnFailure。另外补了测试,覆盖 stale affinity 清理、auto group 不再匹配、以及清理后
ShouldSkipRetryAfterChannelAffinityFailure应返回false的场景。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Summary by CodeRabbit
Bug Fixes
Refactor
Tests