mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:07:40 +01:00
fix(dispatch): surface real Groq failure in fallback reason
Probed the /api/control/dispatch endpoint on production: it returns
{action:"queue", reason:"Groq unavailable — using queue order.",
source:"fallback"} regardless of the actual error. Direct curl against
api.groq.com with the GROQ_API_KEY from Vercel env shows 401
"Invalid API Key" — the key on prod is invalid, so the smart-dispatch
streak reasoning hasn't been working at all since outcome tracking
shipped, and the UI gave no hint why.
Catch now inspects the error and classifies (key invalid / rate-limited /
server error / timeout / verbatim) into the reason field, plus a
console.error so debug_logs picks up failures the same way the auth path
already does. Behaviour on success is unchanged.
Action item out of this commit: rotate GROQ_API_KEY on Vercel
production — the current value returns 401 from the Groq API.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+12
-3
@@ -190,11 +190,20 @@ export async function POST(req: NextRequest) {
|
||||
reason: `${reason}${streakSuffix}`,
|
||||
source: "groq",
|
||||
} satisfies DispatchResult);
|
||||
} catch {
|
||||
// Groq unavailable or no key — fall back to queue drain (existing behaviour).
|
||||
} catch (e) {
|
||||
// Groq unavailable, key invalid, or timeout — surface the actual cause so
|
||||
// the user knows whether to top up credits / rotate the key / wait it out.
|
||||
// Without this the UI just said "Groq unavailable" with no hint to action.
|
||||
const raw = e instanceof Error ? e.message : String(e);
|
||||
const hint = /\b401\b|invalid.api.key/i.test(raw) ? "key invalid"
|
||||
: /\b429\b/.test(raw) ? "rate-limited"
|
||||
: /\b5\d\d\b/.test(raw) ? "Groq server error"
|
||||
: /timeout|abort/i.test(raw) ? "Groq timed out"
|
||||
: raw;
|
||||
console.error("[dispatch] groq fallback:", raw);
|
||||
return NextResponse.json({
|
||||
action: "queue",
|
||||
reason: `Groq unavailable — using queue order.${streakSuffix}`,
|
||||
reason: `Groq unavailable (${hint}) — using queue order.${streakSuffix}`,
|
||||
source: "fallback",
|
||||
} satisfies DispatchResult);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user