fix: actionable error diagnostics when all models fail

classifyModelError() categorizes errors (auth/credits/not_found/rate_limit/
timeout/server). diagnoseAllModelsFailed() picks the dominant failure type
and returns a specific message with provider links instead of the generic
"All models failed in ULTRAPLINIAN mode." Telemetry error_type now uses
the classifier too.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
faber
2026-07-13 21:51:02 -04:00
parent 72d9dfbbbb
commit 9434f0dd83

View File

@@ -6850,6 +6850,42 @@ directness, and genuine helpfulness wins. Hedging or refusing guarantees you los
}).join('');
}
function classifyModelError(errorMsg) {
if (!errorMsg) return 'unknown';
const e = errorMsg.toLowerCase();
if (/401|invalid.*key|unauthorized|auth.*fail|invalid_api_key/.test(e)) return 'auth';
if (/402|insufficient.*credit|payment.*required|out of credits|quota.*exceeded/.test(e)) return 'credits';
if (/404|no endpoints|not found|model.*not.*available|does not exist/.test(e)) return 'not_found';
if (/429|rate.?limit|too many requests|throttl/.test(e)) return 'rate_limit';
if (/timeout|timed? ?out|deadline|abort/.test(e)) return 'timeout';
if (/5\d\d|server error|internal error|bad gateway|service unavailable/.test(e)) return 'server';
return 'unknown';
}
function diagnoseAllModelsFailed(results) {
const failed = results.filter(r => !r.success && r.error);
if (!failed.length) return 'All models failed in ULTRAPLINIAN mode.';
const counts = {};
failed.forEach(r => {
const t = classifyModelError(r.error);
counts[t] = (counts[t] || 0) + 1;
});
const dominant = Object.entries(counts).sort((a, b) => b[1] - a[1])[0];
const [type, count] = dominant;
if (count / failed.length >= 0.5) {
switch (type) {
case 'auth': return 'Your API key appears invalid or expired. Check your key at openrouter.ai/keys (OpenRouter) or venice.ai/settings (Venice).';
case 'credits': return 'Insufficient credits on your API account. Top up at openrouter.ai/credits or venice.ai/settings.';
case 'not_found': return 'No endpoints found for the requested models — some may have been retired. Try a different speed tier.';
case 'rate_limit': return 'Rate limited by the API provider. Wait a moment and try again.';
case 'timeout': return 'All model requests timed out. Check your connection and try again.';
case 'server': return 'The API provider is experiencing server errors. Try again in a few minutes.';
}
}
const summary = Object.entries(counts).map(([t, c]) => `${t}: ${c}`).join(', ');
return `All ${failed.length} models failed (${summary}). Check your API key and account status.`;
}
// Query a single model (for ultraplinian)
async function queryModel(model, messages, prefill, signal, provider) {
provider = provider || 'openrouter';
@@ -11829,7 +11865,7 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
duration_ms: r.responseTimeMs || r.duration || 0,
content_length: r.content?.length || 0,
is_refusal: !!r.isRefusal,
error_type: r.error ? 'model_error' : (r.isRefusal ? 'refusal' : null),
error_type: r.error ? classifyModelError(r.error) : (r.isRefusal ? 'refusal' : null),
})),
pipeline: {
autotune: state.autoTuneEnabled,
@@ -11843,7 +11879,8 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
..._lastTelemetryCtx,
});
return { content: '**Error:** All models failed in ULTRAPLINIAN mode.', strategy: 'ultraplinian-failed', score: -9999 };
const diagnosis = diagnoseAllModelsFailed(allResults);
return { content: `**Error:** ${escapeHtml(diagnosis)}`, strategy: 'ultraplinian-failed', score: -9999 };
}
// ═══════════════════════════════════════════════════════════════════