7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(router): an explicit pin must not resurrect an upstream-retired model (#1394) (#1423)
suantea (asuan_suan)5a427167a880
diff --git a/server/src/__tests__/services/router.test.ts b/server/src/__tests__/services/router.test.tsindex b9cd8949..da57de9b 100644--- a/server/src/__tests__/services/router.test.ts+++ b/server/src/__tests__/services/router.test.ts@@ -275,6 +275,70 @@ describe('Router', () => {});});+describe('Router explicit pin vs upstream retirement (#1394)', () => {+ beforeAll(() => {+ process.env.ENCRYPTION_KEY = '0'.repeat(64);+ initDb(':memory:');+ });++ beforeEach(() => {+ const db = getDb();+ setRoutingStrategy('priority');+ db.prepare('DELETE FROM api_keys').run();+ db.prepare("DELETE FROM settings WHERE key = 'active_profile_id'").run();+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it('does not inject a pinned model carrying an upstream_eol tombstone into the chain', () => {+ const db = getDb();+ const { encrypted, iv, authTag } = encrypt('test-groq-key');+ db.prepare(`+ INSERT INTO api_keys (platform, label, encrypted_key, iv, auth_tag, status, enabled)+ VALUES (?, ?, ?, ?, ?, ?, ?)+ `).run('groq', 'test', encrypted, iv, authTag, 'healthy', 1);++ // Retire a groq model upstream: chain off + tombstone, row stays enabled=1+ // (the documented retirement contract).+ const target = db.prepare(+ "SELECT id, model_id FROM models WHERE platform = 'groq' AND enabled = 1 ORDER BY intelligence_rank ASC LIMIT 1",+ ).get() as { id: number; model_id: string };+ db.prepare('UPDATE fallback_config SET enabled = 0 WHERE model_db_id = ?').run(target.id);+ db.prepare(`+ INSERT INTO catalog_model_tombstones (kind, platform, model_id, source, reason, created_at)+ VALUES ('chat', 'groq', ?, 'upstream_eol', 'HTTP 410 end of life', datetime('now'))+ `).run(target.model_id);++ // The pin must not re-add it: the request routes to some OTHER groq model,+ // never to the retired one.+ const result = routeRequest(1000, undefined, target.id);+ expect(result.modelDbId).not.toBe(target.id);+ });++ it('still pins a model whose tombstone is from the user, not upstream', () => {+ const db = getDb();+ const { encrypted, iv, authTag } = encrypt('test-groq-key');+ db.prepare(`+ INSERT INTO api_keys (platform, label, encrypted_key, iv, auth_tag, status, enabled)+ VALUES (?, ?, ?, ?, ?, ?, ?)+ `).run('groq', 'test', encrypted, iv, authTag, 'healthy', 1);++ const target = db.prepare(+ "SELECT id, model_id FROM models WHERE platform = 'groq' AND enabled = 1 ORDER BY intelligence_rank DESC LIMIT 1",+ ).get() as { id: number; model_id: string };+ db.prepare('UPDATE fallback_config SET enabled = 0 WHERE model_db_id = ?').run(target.id);+ db.prepare(`+ INSERT INTO catalog_model_tombstones (kind, platform, model_id, source, reason, created_at)+ VALUES ('chat', 'groq', ?, 'user', 'removed in dashboard', datetime('now'))+ `).run(target.model_id);++ const result = routeRequest(1000, undefined, target.id);+ expect(result.modelDbId).toBe(target.id);+ });+});+describe('Router exhaustion diagnostics (issue _1)', () => {beforeAll(() => {process.env.ENCRYPTION_KEY = '0'.repeat(64);diff --git a/server/src/services/router.ts b/server/src/services/router.tsindex d01fe7a6..c47ce4aa 100644--- a/server/src/services/router.ts+++ b/server/src/services/router.ts@@ -29,7 +29,7 @@ import {import { TIMEOUT_ERROR_MARKERS } from '../lib/error-classify.js';import { checkMonthlyBudget, reserveMonthlyBudget } from './key-budget.js';import { applyModelWeightOverride, getModelWeightOverrides } from './model-weight-overrides.js';-import { modelsWithOverriddenField } from './model-state.js';+import { modelsWithOverriddenField, getCatalogModelTombstone } from './model-state.js';import { parseBudget } from '../lib/budget.js';import { platformDropsResponseFormat } from '../lib/sampling-params.js';import { isUnifyEnabled, getModelGroups, resolveRequestedIdForDispatch } from './model-groups.js';@@ -2156,8 +2156,19 @@ export function routeRequest(estimatedTokens = 1000, skipKeys?: Set<string>, preFROM models mWHERE m.id = ? AND m.enabled = 1`).get(preferredModelDbId) as ChainRow | undefined;-- if (pinnedRow) {++ // A model retired upstream (#634: 410 end-of-life) must not be re-added+ // by a client pin — the row stays `models.enabled = 1` by design, but the+ // chain tables are off and the provider answers 410 on every call. An+ // explicit pin bypasses both chain tables, so skip the injection and let+ // the request fall through to the rest of the chain (or the normal+ // exhaustion error when nothing is left). A user tombstone still pins:+ // that deletion is dashboard-managed, and the user asking by name is+ // newer intent than their own earlier delete.+ const retiredUpstream = pinnedRow+ && getCatalogModelTombstone(db, 'chat', pinnedRow.platform, pinnedRow.model_id)?.source === 'upstream_eol';++ if (pinnedRow && !retiredUpstream) {sortedChain.unshift(pinnedRow);}}