Real Bifrost (github.com/maximhq/bifrost) integration for the Geek Room hackathon's Bifrost-by-Maxim-AI track, replacing zero prior usage: - BENCH_LLM_GATEWAY=bifrost routes every LLM-backed call (leaderboard's llm row, the auto cascade, and the agent loop's judge stage) through Bifrost's universal OpenAI-compatible endpoint instead of the provider directly, via one choke point (callBifrostStructured in llm.server.ts). - Per-call telemetry read straight from Bifrost's own response (extra_fields), not recomputed: SystemOneBifrostTelemetry type, a new Gateway badge/column on /leaderboard (LeaderboardRow.gateway). - Real run against a local Bifrost v2.5.1 gateway + Anthropic: 93/93 gold calls (accuracy 0.9794), fault-injected re-run (67/93 calls, robustness 0.621), and a real Bifrost-side fallback demo (5/5 calls served by the fallback model, routing_info.is_fallback: true). Full numbers in bifrost-run-results.json; reproduce with verify-bifrost.mjs. Committed leaderboard.json's llm row now carries this real Bifrost-routed run. - README gets a "How Bifrost powers Umpirix" section; HACKATHON-SUBMISSION.md gets a dedicated Bifrost section + honest-limits bullet. - Pitch deck: new slide "How Bifrost powers Umpirix", title renamed to Umpirix — Benchmark Arena for AI Agents (the owner's submitted project title), now 14 slides; re-verified against the actual committed PDF (not just the Marp PNG preview) and fixed one real overflow found that way. PPTX/PDF rebuilt. - demo.mp4 rebuilt as a 42.9s real video (real Playwright screen recording of the Gateway badge + code-rendered stat cards, no AI footage); prior cuts kept as demo-v2-120s-narrated.mp4 / demo-v1-33s-silent.mp4. Repo/package name intentionally left as openjev (not renamed) per the owner's direction; Umpirix is the submission's project title. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
213 lines
11 KiB
JavaScript
213 lines
11 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Real, end-to-end verification of the Bifrost AI gateway integration
|
|
* (Geek Room hackathon, Bifrost by Maxim AI track: github.com/maximhq/bifrost).
|
|
* Every number this script prints is read back from a REAL run against a
|
|
* REAL locally-running Bifrost gateway talking to a REAL Anthropic model —
|
|
* no mocks, no staged numbers, no canned answers.
|
|
*
|
|
* Prerequisite (not started by this script): a local Bifrost gateway,
|
|
* running the documented way (`npx -y @maximhq/bifrost -port 8099`), with
|
|
* an `anthropic` provider configured (file-based `config.json` with
|
|
* `{"keys":[{"value":"env.ANTHROPIC_API_KEY", "models":["*"]}]}`, the
|
|
* gateway's own ANTHROPIC_API_KEY set in ITS process env — never this
|
|
* script's). Point this script at it with BIFROST_BASE_URL.
|
|
*
|
|
* BENCH_LLM_GATEWAY=bifrost BIFROST_BASE_URL=http://localhost:8099 \
|
|
* ANTHROPIC_API_KEY=... node hackathons/geekroom-2026/verify-bifrost.mjs
|
|
*
|
|
* Three real passes:
|
|
* 1. The full 93-case gold suite through `escalateToLlm` (the exact same
|
|
* call `scripts/leaderboard.mjs`'s "llm" row and the agent loop's
|
|
* judge stage already make — see llm.server.ts's module doc) with
|
|
* `BENCH_LLM_GATEWAY=bifrost`, wrapped in `instrumentRunner` for a
|
|
* real execution trace. Real accuracy/ECE from the SAME calibration
|
|
* engine every other backend is scored on, plus Bifrost's own
|
|
* per-call telemetry (`extra_fields`) aggregated across all 93 calls.
|
|
* 2. The SAME 93 cases again with fault injection enabled — proves the
|
|
* existing robustness machinery (buildRobustnessReport) still holds
|
|
* with a real Bifrost-backed runner: timeout/server_error faults must
|
|
* short-circuit before the real Bifrost call (fewer real hits than 93).
|
|
* 3. A small (5-case) Bifrost-powered FALLBACK demo: the primary model is
|
|
* deliberately set to a model that does not exist; `BIFROST_FALLBACK_MODEL`
|
|
* points at the real one. Bifrost's own server-side failover (not a
|
|
* client-side retry this app writes) must serve every case anyway,
|
|
* and its response must say so (`routing_info.is_fallback`).
|
|
*/
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { createJiti } from "jiti";
|
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
const jiti = createJiti(import.meta.url, {
|
|
alias: {
|
|
"@/lib/db": join(root, "scripts/leaderboard-db-shim.mjs"),
|
|
"@": join(root, "src"),
|
|
},
|
|
});
|
|
const mod = (p) => jiti.import(join(root, p));
|
|
|
|
function assertReal(cond, message) {
|
|
if (!cond) throw new Error(`ASSERTION FAILED: ${message}`);
|
|
}
|
|
|
|
async function main() {
|
|
process.env.BENCH_LLM_GATEWAY = "bifrost";
|
|
process.env.BIFROST_BASE_URL ??= "http://localhost:8099";
|
|
process.env.LLM_PROVIDER = "anthropic";
|
|
process.env.ANTHROPIC_MODEL ??= "claude-opus-5";
|
|
// 93 real calls per pass; lift the preview cap just like scripts/leaderboard.mjs does.
|
|
process.env.LLM_RATE_LIMIT_PER_5MIN = "100000";
|
|
assertReal(
|
|
Boolean(process.env.ANTHROPIC_API_KEY),
|
|
"ANTHROPIC_API_KEY must be set in THIS process's env (read from products/.env's CLAUDE_API_KEY by the caller script, never printed)",
|
|
);
|
|
|
|
const llmMod = await mod("src/lib/jev/llm.server.ts");
|
|
const benchmarkScoring = await mod("src/lib/jev/benchmark-scoring.ts");
|
|
const goldMod = await mod("src/lib/jev/gold.ts");
|
|
const { GOLD, evalGoldWith } = goldMod;
|
|
const { instrumentRunner, normalizeFaultInjectionConfig, buildRobustnessReport, toSubmissionResult } =
|
|
benchmarkScoring;
|
|
|
|
console.log("Gateway:", process.env.BIFROST_BASE_URL, "| provider: anthropic | model:", process.env.ANTHROPIC_MODEL);
|
|
console.log("Gold cases:", GOLD.length);
|
|
|
|
// ── Pass 1: clean run through Bifrost, full gold suite ───────────────────
|
|
console.log("\n=== Pass 1: real 93-case gold run through Bifrost (escalateToLlm) ===");
|
|
const bifrostSamples = [];
|
|
let realCalls1 = 0;
|
|
const cleanRunner = async (req) => {
|
|
const r = await llmMod.escalateToLlm(req);
|
|
if (!r.ok) return null;
|
|
realCalls1 += 1;
|
|
if (r.bifrost) bifrostSamples.push(r.bifrost);
|
|
return { model: r.model, answers: r.answers, usage: r.usage, latency_ms: r.latency_ms };
|
|
};
|
|
const cleanTraced = instrumentRunner(cleanRunner, { outboundCallsPerCase: 1 });
|
|
const t0 = Date.now();
|
|
const cleanReport = await evalGoldWith(cleanTraced.runner);
|
|
const wallMs1 = Date.now() - t0;
|
|
const cleanResult = toSubmissionResult(cleanReport);
|
|
const cleanTrace = cleanTraced.getTrace();
|
|
|
|
console.log("real escalateToLlm calls:", realCalls1, "of", GOLD.length, "| wall time (ms):", wallMs1);
|
|
console.log("accuracy:", cleanResult.accuracy, "ece:", cleanResult.ece, "adaptive_ece:", cleanResult.adaptive_ece);
|
|
console.log("execution trace: outboundCalls", cleanTrace.totalOutboundCalls, "| latency p50/p95 (ms, our timer):", cleanTrace.latencyP50Ms, cleanTrace.latencyP95Ms);
|
|
console.log("tokens in/out (sum of real usage):", cleanTrace.totalTokensIn, cleanTrace.totalTokensOut);
|
|
console.log("errors/timeouts:", cleanTrace.errorCount, cleanTrace.timeoutCount);
|
|
|
|
const bifrostLatencies = bifrostSamples.map((b) => b.latencyMs).filter((n) => typeof n === "number").sort((a, b) => a - b);
|
|
const bifrostTokensIn = bifrostSamples.reduce((s, b) => s + (b.tokensIn ?? 0), 0);
|
|
const bifrostTokensOut = bifrostSamples.reduce((s, b) => s + (b.tokensOut ?? 0), 0);
|
|
const pct = (arr, p) => (arr.length ? arr[Math.min(arr.length - 1, Math.ceil((p / 100) * arr.length) - 1)] : null);
|
|
console.log("\nBifrost's OWN telemetry (from extra_fields on each response, source=%s):", bifrostSamples[0]?.source ?? "n/a");
|
|
console.log(" samples with real telemetry:", bifrostSamples.filter((b) => b.source === "response_body").length, "of", bifrostSamples.length);
|
|
console.log(" Bifrost-measured latency p50/p95 (ms):", pct(bifrostLatencies, 50), pct(bifrostLatencies, 95));
|
|
console.log(" Bifrost-measured tokens in/out (sum):", bifrostTokensIn, bifrostTokensOut);
|
|
console.log(" provider/model served:", bifrostSamples[0]?.provider, bifrostSamples[0]?.model);
|
|
|
|
assertReal(realCalls1 === GOLD.length, `expected ${GOLD.length} real Bifrost calls, got ${realCalls1}`);
|
|
assertReal(cleanTrace.totalOutboundCalls === GOLD.length, "trace must count every real call");
|
|
assertReal(bifrostSamples.length === GOLD.length, "every call must report Bifrost telemetry");
|
|
assertReal(
|
|
bifrostSamples.every((b) => b.source === "response_body" && b.gateway === "bifrost"),
|
|
"every sample must be real Bifrost telemetry, not a fabricated/unavailable placeholder",
|
|
);
|
|
assertReal(cleanTrace.totalTokensIn > 0 && cleanTrace.totalTokensOut > 0, "real tokens must be reported");
|
|
console.log("OK: pass 1 — real Bifrost-routed gold run + execution trace verified.");
|
|
|
|
// ── Pass 2: fault injection against the SAME real Bifrost-backed runner ──
|
|
console.log("\n=== Pass 2: fault injection over the SAME 93 cases, real Bifrost calls ===");
|
|
let realCalls2 = 0;
|
|
const faultedRunner = async (req) => {
|
|
const r = await llmMod.escalateToLlm(req);
|
|
realCalls2 += 1;
|
|
if (!r.ok) return null;
|
|
return { model: r.model, answers: r.answers, usage: r.usage, latency_ms: r.latency_ms };
|
|
};
|
|
const faultCfg = normalizeFaultInjectionConfig({ seed: 7, timeoutRate: 0.15, serverErrorRate: 0.15, malformedRate: 0.1 });
|
|
const faultedTraced = instrumentRunner(faultedRunner, { outboundCallsPerCase: 1, faultInjection: faultCfg });
|
|
const faultedReport = await evalGoldWith(faultedTraced.runner);
|
|
const faultedResult = toSubmissionResult(faultedReport);
|
|
const faultedTrace = faultedTraced.getTrace();
|
|
const robustness = buildRobustnessReport(faultCfg, cleanResult.accuracy, faultedResult.accuracy, faultedTrace);
|
|
|
|
console.log("real Bifrost calls made during faulted pass:", realCalls2, "of", GOLD.length);
|
|
console.log("faulted accuracy:", faultedResult.accuracy, "clean accuracy:", cleanResult.accuracy);
|
|
console.log("robustness (faulted/clean):", robustness.robustness);
|
|
console.log("faulted errors/timeouts:", faultedTrace.errorCount, faultedTrace.timeoutCount);
|
|
|
|
assertReal(faultedTrace.errorCount > 0, "a 40%-total fault rate must inject at least one real failure");
|
|
assertReal(
|
|
realCalls2 < GOLD.length,
|
|
"timeout/server_error faults must short-circuit before the real Bifrost call — fewer real calls than gold cases",
|
|
);
|
|
assertReal(robustness.robustness >= 0 && robustness.robustness <= 1, "robustness must be a real ratio in [0, 1]");
|
|
console.log("OK: pass 2 — fault injection over real Bifrost calls verified.");
|
|
|
|
// ── Pass 3: Bifrost's OWN fallback feature (server-side, not ours) ───────
|
|
console.log("\n=== Pass 3: Bifrost's real `fallbacks` feature (primary model deliberately invalid) ===");
|
|
const savedModel = process.env.ANTHROPIC_MODEL;
|
|
process.env.ANTHROPIC_MODEL = "claude-totally-fake-model-xyz";
|
|
process.env.BIFROST_FALLBACK_MODEL = `anthropic/${savedModel}`;
|
|
const fallbackSamples = [];
|
|
for (const g of GOLD.slice(0, 5)) {
|
|
const r = await llmMod.escalateToLlm({ state: g.state, questions: g.questions });
|
|
assertReal(r.ok, `fallback-covered call must still succeed for case ${g.id}: ${r.ok ? "" : r.detail}`);
|
|
assertReal(Boolean(r.bifrost), "fallback call must report Bifrost telemetry");
|
|
fallbackSamples.push(r.bifrost);
|
|
}
|
|
delete process.env.BIFROST_FALLBACK_MODEL;
|
|
process.env.ANTHROPIC_MODEL = savedModel;
|
|
|
|
console.log("fallback samples:", fallbackSamples.length);
|
|
for (const s of fallbackSamples) {
|
|
console.log(" requestId:", s.requestId, "| served model:", s.model, "| fallbackUsed:", s.fallbackUsed);
|
|
}
|
|
assertReal(
|
|
fallbackSamples.every((s) => s.fallbackUsed === true),
|
|
"every one of these calls must show Bifrost's real server-side fallback engaging (invalid primary model)",
|
|
);
|
|
assertReal(
|
|
fallbackSamples.every((s) => s.model === savedModel),
|
|
"the fallback model actually served must be the real working model, not the invalid primary",
|
|
);
|
|
console.log("OK: pass 3 — Bifrost's real fallback feature verified end to end.");
|
|
|
|
console.log("\nAll real Bifrost verification passes succeeded — no mocks, no staged numbers.");
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
pass1: {
|
|
realCalls: realCalls1,
|
|
wallMs: wallMs1,
|
|
accuracy: cleanResult.accuracy,
|
|
ece: cleanResult.ece,
|
|
adaptive_ece: cleanResult.adaptive_ece,
|
|
strict_pass_rate: cleanResult.strict_pass_rate,
|
|
trace: cleanTrace,
|
|
bifrostLatencyP50: pct(bifrostLatencies, 50),
|
|
bifrostLatencyP95: pct(bifrostLatencies, 95),
|
|
bifrostTokensIn,
|
|
bifrostTokensOut,
|
|
},
|
|
pass2: {
|
|
realCalls: realCalls2,
|
|
accuracy: faultedResult.accuracy,
|
|
robustness: robustness.robustness,
|
|
faultedTrace,
|
|
},
|
|
pass3: { fallbackSamples },
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|