fix(channel-affinity): reselect stale cached channels - #5256
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 (3)
WalkthroughThe PR modifies channel affinity matching in the distributor middleware to clear the affinity cache when a preferred channel is unavailable or disabled, enabling fallback selection. It adds a service helper ChangesChannel affinity clearing for unavailable preferred channels
Sequence DiagramsequenceDiagram
participant Request
participant Distributor
participant AffinityCache
participant ChannelService
Request->>Distributor: POST /v1/responses with prompt cache key
Distributor->>AffinityCache: GetPreferredChannelByAffinity
AffinityCache-->>Distributor: preferred channel id (or nil)
alt Preferred channel not found or disabled
Distributor->>ChannelService: ClearMatchedChannelAffinity
ChannelService->>AffinityCache: delete affinity cache key
AffinityCache-->>ChannelService: deletion confirmed
ChannelService-->>Distributor: cleared
end
Distributor->>ChannelService: select fallback available channel
ChannelService-->>Distributor: available channel
Distributor-->>Request: response with fallback channel
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
Summary
Root cause
A channel affinity hit could resolve to a channel that had since been disabled. For rules with
SkipRetryOnFailureenabled, the distributor returned403 affinity_channel_disabledimmediately, leaving the stale affinity key intact and preventing normal fallback selection.Test Plan
go test ./middleware -run TestDistributeClearsDisabledAffinityAndSelectsAvailableChannel -count=1go test ./middleware ./service -count=1git diff --checkgo test ./... -count=1currently fails on existing unrelated issues in this checkout:main.go:44:12: pattern web/classic/dist: no matching files foundcontroller: sqlite DB closed inTestListModelsTokenLimitIncludesTieredBillingModelrelay/channel/claude: existing file content conversion expectationsrelay/helper: existingTestStreamScannerHandler_StreamStatus_PreInitializedcounter mismatchSummary by CodeRabbit
Bug Fixes
Tests