feat: cap 503 overload key retries to 1 retry key and split Admin UI into subpages
This commit is contained in:
parent
343208216e
commit
9d44c92b01
15 changed files with 3372 additions and 2997 deletions
|
|
@ -117,16 +117,17 @@ async function runTests() {
|
|||
|
||||
try {
|
||||
// -------------------------------------------------------------------------
|
||||
// TEST 1: Zero-Tolerance 503 Overload Fast-Failover
|
||||
// Tier 0 has 3 keys for 'mock-overloaded-model'.
|
||||
// TEST 1: 1-Retry-Key (Max 2 Keys) 503 Overload Fast-Failover with 10 Keys
|
||||
// Tier 0 has 10 keys for 'mock-overloaded-model'.
|
||||
// Tier 1 has 1 key for 'mock-healthy-tier1-model'.
|
||||
// -------------------------------------------------------------------------
|
||||
console.log('1. Testing Zero-Tolerance 503 Overload Fast-Failover...');
|
||||
console.log('1. Testing 1-Retry-Key (Max 2 Keys) 503 Overload Fast-Failover across 10 Keys...');
|
||||
const tenOverloadedKeys = Array.from({ length: 10 }, (_, i) => `key-overloaded-${i + 1}`);
|
||||
const provOverloaded = configStore.saveProvider({
|
||||
name: 'Google AI Studio Mock (Overloaded)',
|
||||
name: 'Google AI Studio Mock (Overloaded 10 Keys)',
|
||||
type: 'custom',
|
||||
baseUrl: upstreamBaseUrl,
|
||||
keys: ['key-overloaded-1', 'key-overloaded-2', 'key-overloaded-3']
|
||||
keys: tenOverloadedKeys
|
||||
});
|
||||
|
||||
const provHealthy = configStore.saveProvider({
|
||||
|
|
@ -138,7 +139,7 @@ async function runTests() {
|
|||
|
||||
const testModelOverload = configStore.saveCustomModel({
|
||||
name: testModelOverloadName,
|
||||
description: 'Testing 503 zero-tolerance skip and fast-cascade',
|
||||
description: 'Testing 503 1-retry-key skip and fast-cascade',
|
||||
tiers: [
|
||||
{
|
||||
tierIndex: 0,
|
||||
|
|
@ -170,25 +171,27 @@ async function runTests() {
|
|||
const data1 = (await res1.json()) as any;
|
||||
assert.strictEqual(data1.choices[0].message.content, 'Tier 1 fallback served instantly.');
|
||||
|
||||
// Verify upstream only received 1 request for the overloaded model (NOT 3 keys!)
|
||||
assert.strictEqual(requestCount503, 1, 'Upstream should only be hit ONCE on 503 before cascading');
|
||||
// Verify upstream only received 2 requests for the overloaded model (Key 1 + 1 retry key = 2, NOT all 10 keys!)
|
||||
assert.strictEqual(requestCount503, 2, 'Upstream should only be hit TWICE (1 initial + 1 retry key) on 503 before cascading');
|
||||
|
||||
// Verify telemetry recorded the skip and nextAction
|
||||
// Verify telemetry recorded the retry, skip of remaining 8 keys, and nextAction
|
||||
const recentJourneys = telemetryTracker.getRecentJourneys(5);
|
||||
const j1 = recentJourneys.find(j => j.requestedModel === testModelOverload.name);
|
||||
assert.ok(j1, 'Journey must be recorded');
|
||||
assert.strictEqual(j1.totalHops, 2, 'Should only have 2 hops: Hop 1 (503) -> Hop 2 (Tier 1 200 OK)');
|
||||
assert.strictEqual(j1.totalHops, 3, 'Should have 3 hops: Hop 1 (503) -> Hop 2 (503 retry) -> Hop 3 (Tier 1 200 OK)');
|
||||
assert.strictEqual(j1.finalStatus, 'success_fallback');
|
||||
assert.strictEqual(j1.steps[0].status, 'server_error');
|
||||
assert.ok(j1.steps[0].nextAction?.includes('Model overloaded (503) — skipped 2 remaining key(s)'));
|
||||
assert.strictEqual(j1.steps[1].status, 'success');
|
||||
assert.ok(j1.steps[0].nextAction?.includes('Model overloaded (503) — retrying 1 more key'));
|
||||
assert.strictEqual(j1.steps[1].status, 'server_error');
|
||||
assert.ok(j1.steps[1].nextAction?.includes('Model overloaded (503) — skipped 8 remaining key(s)'));
|
||||
assert.strictEqual(j1.steps[2].status, 'success');
|
||||
|
||||
// Verify individual keys were NOT marked rate-limited (key quota preserved!)
|
||||
const updatedProvOverloaded = configStore.getProviderById(provOverloaded.id)!;
|
||||
for (const k of updatedProvOverloaded.keys) {
|
||||
assert.strictEqual(k.rateLimitedUntil, null, '503 must NEVER mark individual keys rate-limited');
|
||||
}
|
||||
console.log(' ✓ Zero-tolerance 503 fast-failover skipped remaining keys and preserved key quota.');
|
||||
console.log(' ✓ 503 fast-failover tried 1 retry key (2 total), skipped remaining 8 keys, and preserved key quota.');
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TEST 2: Circuit Breaker Bypasses Tier 0 Instantly on Subsequent Requests
|
||||
|
|
@ -211,8 +214,8 @@ async function runTests() {
|
|||
const data2 = (await res2.json()) as any;
|
||||
assert.strictEqual(data2.choices[0].message.content, 'Tier 1 fallback served instantly.');
|
||||
|
||||
// Request 503 count should STILL be 1 (Tier 0 was bypassed with 0ms delay!)
|
||||
assert.strictEqual(requestCount503, 1, 'Overloaded model must be bypassed completely while in cooldown');
|
||||
// Request 503 count should STILL be 2 (Tier 0 was bypassed with 0ms delay!)
|
||||
assert.strictEqual(requestCount503, 2, 'Overloaded model must be bypassed completely while in cooldown');
|
||||
assert.ok(req2Duration < 150, `Subsequent request should complete instantly without Tier 0 hops (took ${req2Duration}ms)`);
|
||||
|
||||
const j2 = telemetryTracker.getRecentJourneys(5)[0];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue