mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 08:47:02 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=false was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (1062 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(lint): reattach two guards the reformat detached Both effects were one-liners, so a trailing eslint-disable-line covered the setState call: useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ... prettier expanded the block. The comment stayed on the closing line while the call moved above it, so the guard protected nothing and the rule its author had deliberately silenced failed the build. This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line variant. Both come from the same fact: an eslint directive binds to a line number, so reformatting can silently unbind it, which makes 'mechanical, no behaviour change' false for any bulk reformat. * chore(desktop): bump the runner version the reformat requires desktop-release-drift enforces that anything built into Fleet Runner which differs from the last released tag must carry a version ahead of that tag — main read 0.8.15 and fleet-runner-v0.8.15 already shipped. A whole-repo reformat changes bytes under desktop/, so the gate fires. The alternative was adding desktop/ to .prettierignore, which would buy a quiet PR by carving a permanent hole in the formatter's coverage — the precise shape of silent drift this test was written to catch. Bumping is what the rule asks for and costs one patch release whose only content is whitespace. * chore: merge main and re-format A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR runs no checks at all while reporting nothing. Conflicts resolved to main, which is correct because this branch changes formatting and nothing else. * chore: leave desktop/ out of this reformat desktop-release-drift is right to refuse this. Everything under desktop/ is built into Fleet Runner, so changing it means shipping: bump the version AND add a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed Fleet Runner and wants to know what changed'. For a whitespace-only build the honest answer is 'nothing', so that release should not exist — and I should not write release notes claiming otherwise. I had bumped to 0.8.16 to get the gate green. That was the wrong direction: publishing a build to three OS runners to keep a formatting PR quiet. Reverted. desktop/ is excluded in .prettierignore with the reasoning recorded there, to be formatted alongside the next real runner change, where the bump and the notes are true anyway. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
148 lines
7.2 KiB
TypeScript
148 lines
7.2 KiB
TypeScript
/**
|
|
* Inline tests for Groq 429 classification (lib/agent/groq-error.ts).
|
|
*
|
|
* The three kinds of 429 need OPPOSITE responses, and getting it wrong is not a
|
|
* near-miss: treating a size error as capacity made the handler step down to the
|
|
* model with HALF the token ceiling and wait 25s for a window that could never
|
|
* be big enough — so Loki's tool loop died on every question and every answer
|
|
* came from the toolless fallback. Treating a DAILY cap as capacity is the same
|
|
* mistake one level deeper: the step-down model shares the exhausted daily
|
|
* budget, so the operator pays two dead round trips and ~25s per turn for the
|
|
* rest of the day to reach the identical failure.
|
|
*
|
|
* The strings below are REAL bodies captured from the live API on 2026-08-14,
|
|
* not paraphrases — this classifier is only as good as its fidelity to them.
|
|
*
|
|
* Run: npm run test:groq-error
|
|
*/
|
|
import {
|
|
classifyGroqLimit,
|
|
groqRetryAfterSeconds,
|
|
humanizeWait,
|
|
rateLimitMessage,
|
|
type GroqLimitKind,
|
|
} from "@/lib/agent/groq-error";
|
|
|
|
function assert(condition: boolean, message: string): void {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
|
|
let passed = 0;
|
|
const is = (kind: GroqLimitKind, body: string, why: string) => {
|
|
const got = classifyGroqLimit(body);
|
|
assert(got === kind, `expected ${kind}, got ${got} — ${why}\n body: ${body.slice(0, 120)}`);
|
|
passed += 1;
|
|
};
|
|
const check = (label: string, fn: () => void) => {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
// Captured verbatim: one request larger than the whole per-minute allowance.
|
|
is(
|
|
"size",
|
|
'{"error":{"message":"Request too large for model `llama-3.1-8b-instant` in organization `org_01jy16rk1yffks8jdsmfn4s7rj` service tier `on_demand` on tokens per minute (TPM): Limit 6000, Requested 15041, please reduce your message size and try again. Need more tokens? Upgrade to Dev Tier today at https://console.groq.com/settings/billing","type":"tokens","code":"rate_limit_exceeded"}}',
|
|
"the real oversized-prompt body — waiting and stepping down both make it worse",
|
|
);
|
|
|
|
// Captured verbatim: the window is momentarily spent. Waiting DOES help here.
|
|
is(
|
|
"capacity",
|
|
'{"error":{"message":"Rate limit reached for model `llama-3.1-8b-instant` in organization `org_01jy16rk1yffks8jdsmfn4s7rj` service tier `on_demand` on tokens per minute (TPM): Limit 6000, Used 5959, Requested 400. Please try again in 3.6s","type":"tokens","code":"rate_limit_exceeded"}}',
|
|
"the real capacity body — step down and retry",
|
|
);
|
|
|
|
// Both bodies share status, type, code AND the phrase "tokens per minute (TPM)".
|
|
// Only the opening verb differs, which is exactly why this is keyed on the body
|
|
// text and not on any structured field.
|
|
is("size", "Request too large for model X", "minimal size phrasing");
|
|
is("capacity", "Rate limit reached for model X", "minimal capacity phrasing");
|
|
|
|
// The daily cap. Captured shape from the groq-daily-token-cap note. It opens
|
|
// with the SAME "Rate limit reached" wording as capacity, so the daily check has
|
|
// to run first or the cheaper pattern silently absorbs it — which is exactly the
|
|
// bug this case pins.
|
|
is(
|
|
"daily",
|
|
"Rate limit reached ... on tokens per day (TPD): Limit 100000, Used 99331, Requested 4589. Please try again in 56m26.88s",
|
|
"a spent DAY must not be treated as a spent minute — stepping down and waiting 25s both fail",
|
|
);
|
|
|
|
// Requests-per-day is the same situation: nothing helps before the reset.
|
|
is(
|
|
"daily",
|
|
"Rate limit reached ... on requests per day (RPD): Limit 14400",
|
|
"RPD is a daily cap too",
|
|
);
|
|
|
|
// Context-window overflow is a size problem by another name.
|
|
is("size", "please reduce the length of the messages", "context overflow wording");
|
|
|
|
// Unrecognisable bodies must default to capacity: that path retries and
|
|
// degrades, where guessing "size" would shed context that was never the problem
|
|
// and guessing "daily" would abandon a turn that might have succeeded.
|
|
is("capacity", "", "empty body defaults to the safe path");
|
|
is("capacity", "upstream connect error", "unrelated body defaults to the safe path");
|
|
|
|
// ── the wait Groq named ──────────────────────────────────────────────────────
|
|
// Passing on the real figure is the whole difference between a message the
|
|
// operator can act on and one that invites a retry guaranteed to fail.
|
|
check("parses a seconds-only wait", () => {
|
|
assert(groqRetryAfterSeconds("Please try again in 3.6s") === 4, "expected 4s (rounded up)");
|
|
});
|
|
|
|
check("parses a minutes+seconds wait", () => {
|
|
const got = groqRetryAfterSeconds("Please try again in 56m26.88s");
|
|
assert(got === 3387, `expected 3387s, got ${got}`);
|
|
});
|
|
|
|
check("a body naming no wait yields null, not a fabricated one", () => {
|
|
assert(groqRetryAfterSeconds("Rate limit reached") === null, "invented a wait");
|
|
assert(groqRetryAfterSeconds("") === null, "invented a wait from an empty body");
|
|
});
|
|
|
|
check("waits are phrased for a person", () => {
|
|
assert(humanizeWait(4) === "4s", `got ${humanizeWait(4)}`);
|
|
assert(humanizeWait(3387) === "57 minutes", `got ${humanizeWait(3387)}`);
|
|
assert(humanizeWait(7200) === "about 2 hours", `got ${humanizeWait(7200)}`);
|
|
assert(humanizeWait(null) === null, "null wait must stay null");
|
|
assert(humanizeWait(0) === null, "a zero wait is no wait");
|
|
});
|
|
|
|
// ── what the operator is actually told ───────────────────────────────────────
|
|
check("an exhausted day names the reset instead of saying 'try again shortly'", () => {
|
|
const msg = rateLimitMessage(
|
|
"groq 429: Rate limit reached ... on tokens per day (TPD): Limit 100000, Used 99331, Requested 4589. Please try again in 56m26.88s",
|
|
);
|
|
assert(/daily/.test(msg), `message does not mention the daily quota: ${msg}`);
|
|
assert(/57 minutes/.test(msg), `message does not name the real wait: ${msg}`);
|
|
assert(!/shortly/.test(msg), `still invites an immediate retry: ${msg}`);
|
|
});
|
|
|
|
check("a spent minute still invites a retry, with the real delay", () => {
|
|
const msg = rateLimitMessage("groq 429: Rate limit reached ... (TPM). Please try again in 3.6s");
|
|
assert(/rate-limited/.test(msg) && /4s/.test(msg), `unhelpful capacity message: ${msg}`);
|
|
});
|
|
|
|
check("an oversized request does not tell the operator to wait — waiting cannot fix it", () => {
|
|
const msg = rateLimitMessage("groq 429: Request too large ... please reduce your message size");
|
|
assert(
|
|
!/try again|resets in/.test(msg),
|
|
`told the operator to retry a request that cannot fit: ${msg}`,
|
|
);
|
|
});
|
|
|
|
check("the message is a clause the caller can embed, not a sentence", () => {
|
|
// Callers wrap it as "Loki is offline — ${msg}." A capitalised, Loki-naming
|
|
// sentence would render "Loki is offline — Loki is rate-limited — ...".
|
|
for (const body of ["tokens per day (TPD)", "Rate limit reached", "Request too large"]) {
|
|
const msg = rateLimitMessage(body);
|
|
assert(msg[0] === msg[0]!.toLowerCase(), `message is capitalised: ${msg}`);
|
|
assert(!/Loki/i.test(msg), `message names Loki, which the caller already did: ${msg}`);
|
|
assert(!msg.endsWith("."), `message ends with a period the caller also adds: ${msg}`);
|
|
}
|
|
});
|
|
|
|
console.log(`\n✓ groq-error tests passed (${passed} assertions)`);
|