Files
loki/scripts
404007eb3e fix(loki): a spent day is not a spent minute (#284)
Groq returns 429 for three unrelated conditions, and the classifier only knew
two. A tokens-per-day cap opens with the same "Rate limit reached" wording as an
ordinary per-minute burst, so it was classified as capacity - and every recovery
that is right for capacity is actively harmful for a spent day:

  - the step-down to llama-3.1-8b-instant draws on the SAME org-wide daily
    budget, so it is a guaranteed-identical failure one round trip later;
  - the bounded ~25s wait is measured against a reset Groq reports in tens of
    minutes ("try again in 56m26.88s").

Net cost to the operator: two dead round trips and ~25s of latency on every Loki
turn for the rest of the day, ending in "Groq rate-limited - try again shortly",
which invites exactly the retry that cannot succeed for another hour.

This is the same mistake as the size/capacity conflation one level deeper. The
distinction that matters is not which limit was hit but what, if anything, the
caller can do about it, so the type now names all three.

  - classifyGroqLimit gains "daily", tested BEFORE size/capacity because the
    daily body also matches the cheaper capacity pattern (RPD counts too).
  - llm.ts short-circuits a daily cap instead of stepping down and sleeping.
  - groqRetryAfterSeconds/humanizeWait pass on the figure Groq already stated;
    rateLimitMessage turns it into a clause the operator can act on, and lives
    beside the classifier so both Groq wrappers say the same thing.
  - the size case stops telling the operator to retry at all - waiting cannot
    fix an oversized request, and the real repair is ours, not theirs.

The suite previously asserted the daily body WAS capacity, with the reasoning
"the budget refills, so retry/degrade is right". It refills in an hour, not in
25 seconds, and not on the model we degrade to. That case is corrected and
pinned, and the tests grow 8 -> 17 assertions.

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-15 09:45:30 +00:00
..