diff --git a/src/server/services/tokenRouter.test.ts b/src/server/services/tokenRouter.test.ts index e33ecbd..0c92742 100644 --- a/src/server/services/tokenRouter.test.ts +++ b/src/server/services/tokenRouter.test.ts @@ -76,6 +76,29 @@ describe('filterRecentlyFailedCandidates', () => { expect(result.map((c) => c.id).sort()).toEqual(['a', 'b']); }); + it('keeps candidates unchanged when avoidSec is omitted', () => { + const nowMs = Date.now(); + const candidates: Candidate[] = [ + { + id: 'recent-failure', + channel: { + failCount: 3, + lastFailAt: new Date(nowMs - 5 * 1000).toISOString(), + }, + }, + { + id: 'healthy', + channel: { + failCount: 0, + lastFailAt: null, + }, + }, + ]; + + const result = filterRecentlyFailedCandidates(candidates, nowMs); + expect(result).toEqual(candidates); + }); + it('does not penalize stale failures outside the avoidance window', () => { const nowMs = Date.now(); const candidates: Candidate[] = [ diff --git a/src/server/services/tokenRouter.ts b/src/server/services/tokenRouter.ts index 358a42d..4919e1d 100644 --- a/src/server/services/tokenRouter.ts +++ b/src/server/services/tokenRouter.ts @@ -167,13 +167,13 @@ export function filterRecentlyFailedCandidates !isChannelRecentlyFailed(candidate.channel, nowMs, avoidSec)); - // If all channels failed recently, keep them all and let weight/random decide. - return healthy.length > 0 ? healthy : candidates; -} + // If all channels failed recently, keep them all and let weight/random decide. + return healthy.length > 0 ? healthy : candidates; +} export interface RouteDecisionCandidate { channelId: number;