Skip to content

Open source CapCut alternative.

TypeScript

feat(site): a provider-failure eval reads real provider errors

David Le12e9ae11e5d7
diff --git a/site/package.json b/site/package.json
index c9e99b9a..1cfd7083 100644
--- a/site/package.json
+++ b/site/package.json
@@ -23,6 +23,10 @@
"bench:watch": "bun run scripts/bench-watch.ts",
"eval:cut-chat": "bun run scripts/eval-cut-chat.ts",
"eval:cut-queue": "bun run scripts/eval-cut-queue.ts",
+ "eval:cut-judge": "bun run scripts/eval-cut-judge.ts",
+ "eval:chatgpt-oauth": "bun run scripts/eval-chatgpt-oauth.ts",
+ "eval:cut-turn-job": "bun run scripts/eval-cut-turn-job.ts",
+ "eval:cut-headless-export": "bun run scripts/eval-cut-headless-export.ts",
"eval:cut-routing": "bun run scripts/eval-cut-routing.ts",
"eval:chatgpt-workflow": "bun run scripts/eval-chatgpt-workflow.ts",
"eval:cut-headless": "bun run scripts/eval-cut-headless.ts",
diff --git a/site/scripts/eval-cut-judge.ts b/site/scripts/eval-cut-judge.ts
new file mode 100644
index 00000000..61305216
--- /dev/null
+++ b/site/scripts/eval-cut-judge.ts
@@ -0,0 +1,116 @@
+#!/usr/bin/env bun
+/**
+ * The provider-failure eval: what a hosted provider's error means.
+ *
+ * A render or a music call fails, and the next step turns on why. The
+ * content declined means the ladder may drop to its text-only rung and a
+ * music prompt is worth rewriting; a timeout means neither. That reading is a
+ * judgment over the provider's own error text, so it is measured here against
+ * errors real providers returned.
+ *
+ * Run with the site dev server up:
+ * bun run scripts/eval-cut-judge.ts [--base http://localhost:3000] [--only <substring>]
+ *
+ * Auth is the dev bypass header (scripts only — never the app), so runs are
+ * dev-server-only and spend no credits.
+ */
+
+import { PROVIDER_FAILURE_QUESTION, providerFailureClass, type ProviderFailureClass } from "../src/cut/lib/providerFailure";
+
+const args = process.argv.slice(2);
+const argValue = (flag: string) => {
+ const i = args.indexOf(flag);
+ return i >= 0 ? args[i + 1] : undefined;
+};
+const BASE = argValue("--base") ?? "http://localhost:3000";
+const ONLY = argValue("--only");
+
+interface FailureCase {
+ /** What the case pins, in the words of the decision it drives. */
+ name: string;
+ /** The provider's error text, as it reached us. */
+ error: string;
+ want: ProviderFailureClass;
+}
+
+const cases: FailureCase[] = [
+ {
+ name: "person-policy refusal",
+ error:
+ "The input image contains content that has been blocked by your current safety settings for person/face generation. Support codes: 17301594",
+ want: "content_refused",
+ },
+ {
+ name: "unreadable anchor format",
+ error: "Unsupported image format. Expected JPEG or PNG.",
+ want: "content_refused",
+ },
+ {
+ name: "filtered render came back empty",
+ error: "Omni returned no video for this request.",
+ want: "content_refused",
+ },
+ {
+ name: "prompt blocked before the render",
+ error: "The prompt was blocked by the safety filter (PROHIBITED_CONTENT).",
+ want: "content_refused",
+ },
+ {
+ name: "render ran out of time",
+ error: "The video render is taking too long — try again.",
+ want: "transient_failure",
+ },
+ {
+ name: "the model was overloaded",
+ error: "503 The model is overloaded. Please try again later.",
+ want: "transient_failure",
+ },
+ {
+ name: "rate limited",
+ error: "429 Resource has been exhausted (e.g. check quota).",
+ want: "transient_failure",
+ },
+ {
+ name: "a bad request names no cause",
+ error: "400 Invalid JSON payload received. Unknown name \"durationSecond\".",
+ want: "other",
+ },
+ {
+ name: "an internal error names no cause",
+ error: "500 Internal error encountered.",
+ want: "other",
+ },
+];
+
+async function judgeFailure(error: string): Promise<{ cls: ProviderFailureClass; confidence: number; ms: number }> {
+ const started = Date.now();
+ const res = await fetch(`${BASE}/api/inference/judge`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "x-donkey-client-id": "donkey-cut-eval",
+ "x-donkey-dev-auth-bypass": "1",
+ },
+ body: JSON.stringify({ state: { error }, questions: { cause: PROVIDER_FAILURE_QUESTION } }),
+ });
+ if (!res.ok) throw new Error(`judge ${res.status}: ${await res.text()}`);
+ const { answers } = (await res.json()) as {
+ answers: { cause: { choice: ProviderFailureClass; confidence: number } };
+ };
+ return { cls: providerFailureClass(answers.cause), confidence: answers.cause.confidence, ms: Date.now() - started };
+}
+
+const picked = cases.filter((c) => !ONLY || c.name.includes(ONLY) || c.error.includes(ONLY));
+let failed = 0;
+for (const c of picked) {
+ const { cls, confidence, ms } = await judgeFailure(c.error);
+ const ok = cls === c.want;
+ if (!ok) failed++;
+ console.log(
+ `[${ok ? "ok" : "FAIL"}] ${c.name.padEnd(34)} ${cls}${ok ? "" : ` (wanted ${c.want})`} · ${(confidence * 100).toFixed(0)}% · ${ms}ms`,
+ );
+ if (!ok) console.log(` ${c.error}`);
+}
+
+console.log(`\n${picked.length - failed}/${picked.length} classified as they must be`);
+process.exit(failed ? 1 : 0);
diff --git a/site/scripts/lib/cut-eval/README.md b/site/scripts/lib/cut-eval/README.md
index efa42db6..3099c61d 100644
--- a/site/scripts/lib/cut-eval/README.md
+++ b/site/scripts/lib/cut-eval/README.md
@@ -60,6 +60,15 @@ checks what the turn judge decides for the labelled asks in
gate side. Every ask is judged once and the route recomposed under a grid of
thresholds, so the sweep that sets the registry defaults costs no extra calls.
+## The provider-failure eval
+
+`npm run eval:cut-judge -- [--only <substring>]`
+checks what a hosted provider's error text means — the content declined, a
+transient failure, anything else — against errors real providers returned. The
+class decides whether the render ladder may drop to its text-only rung and
+whether a music prompt is worth rewriting, so a case is added whenever a new
+error reached us and was read wrong.
+
## The report
A full run writes `evals/cut-chat.latest-report.json` (schema