🌳
pt0/serverF/aiF/markModelFailedAI.mts
1import type { OrrErrClass } from './classifyOrrErrAI.mts'
4type FailedRec = { failedAt: number, classification: OrrErrClass }
6const runtimeFailedModels = new Map<string, FailedRec>()
8const ttlMsFor = (classification: OrrErrClass) =>
9 classification === 'permanent' ? Infinity
10 : classification === 'rateLimit' ? 60_000
11 : 5 * 60_000 // transient | unknown
13export const markModelFailed = (modelId: string, classification: OrrErrClass = 'permanent') => {
14 const prev = runtimeFailedModels.get(modelId)
15 if (!prev) mcpDebugLog(`Model failed at runtime, will skip: ${modelId} (${classification})`)
16 runtimeFailedModels.set(modelId, {failedAt: Date.now(), classification})
19export const isModelFailed = (modelId: string) => {
20 const rec = runtimeFailedModels.get(modelId)
21 if (!rec) return false
22 if (Date.now() - rec.failedAt >= ttlMsFor(rec.classification)) {
23 runtimeFailedModels.delete(modelId)
24 return false
25 }
26 return true
29export const getFailedModelInfo = (modelId: string) => runtimeFailedModels.get(modelId)