Release 0.15.0: endpoints instead of deployments
Release / release (push) Successful in 12m32s

Kaname keeps two jobs: the model downloader and benchmarks. Benchmarks
now run against endpoints (any OpenAI-compatible server added by URL,
with an optional server-side API key and hand-written hardware notes)
instead of deployments Kaname started itself.

Removed: runtimes, deployments, sweeps, resource telemetry, hardware
detection, the /api/v1 API with tokens and guardrails, and all Docker
access. The quality eval's coding tests run in a network-less sandbox
container that shares only an exchange folder with the worker.

The previous state is kept in branch backup / tag backup-0.14.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-26 21:43:42 +01:00
1 parent 1d2f908b75
commit 276108932d
199 files changed
+5462 -15961

No files matched your search

+40 -74
View File
@@ -3,9 +3,10 @@ import { rm } from "node:fs/promises";
import { and, asc, desc, eq, gt, inArray, or } from "drizzle-orm";
import { z } from "zod";
import { runDir } from "@/lib/benchmark-paths";
import { deploymentSnapshot } from "@/lib/benchmark-snapshot";
import { libraryModelId, modelFor, snapshotOf } from "@/lib/benchmark-snapshot";
import { db } from "@/lib/db/client";
import { BENCHMARK_PHASES, benchmarkLogs, benchmarkRuns, QUALITY_SECTIONS } from "@/lib/db/schema";
import { BENCHMARK_PHASES, benchmarkLogs, benchmarkRuns, endpoints, QUALITY_SECTIONS } from "@/lib/db/schema";
import { probeEndpoint } from "@/lib/endpoint-probe";
export class BenchmarkError extends Error {
constructor(
@@ -20,7 +21,9 @@ export class BenchmarkError extends Error {
export const DESCRIPTION_MAX = 4000;
export const BenchmarkBody = z.object({
deploymentId: z.string().min(1),
endpointId: z.string().min(1),
/** The model to request; default: the endpoint's (or the only one it serves). */
model: z.string().trim().max(300).nullable().optional(),
label: z.string().trim().max(120).nullable().optional(),
/** Free text: what this run tries out. Passed to BetterBench and launch80 with the system summary. */
description: z.string().trim().max(DESCRIPTION_MAX).nullable().optional(),
@@ -29,53 +32,50 @@ export const BenchmarkBody = z.object({
warmup: z.number().int().min(0).max(50).nullable().optional(),
/** Empty: all phases. */
phases: z.array(z.enum(BENCHMARK_PHASES)).max(3).default([]),
/** A/B: the second deployment (B), the target minimum detectable effect in % and the pair ceiling. */
deploymentBId: z.string().min(1).nullable().optional(),
/** A/B: the second endpoint (B), the target minimum detectable effect in % and the pair ceiling. */
endpointBId: z.string().min(1).nullable().optional(),
mdePct: z.number().min(0.1).max(50).nullable().optional(),
maxPairs: z.number().int().min(12).max(2000).nullable().optional(),
/** Set by sweeps. */
sweepId: z.string().nullable().optional(),
/** "eval": the quality eval instead of BetterBench (default: run, or ab with deploymentBId). */
/** "eval": the quality eval instead of BetterBench (default: run, or ab with endpointBId). */
kind: z.enum(["run", "ab", "eval"]).optional(),
/** eval: which sections (empty: all). */
evalSections: z.array(z.enum(QUALITY_SECTIONS)).max(3).optional(),
});
export type BenchmarkInput = z.infer<typeof BenchmarkBody>;
/** A running deployment as it is now: what a run measures and records. */
async function snapshotOf(deploymentId: string, role: string) {
const d = await deploymentSnapshot(deploymentId);
if (!d) throw new BenchmarkError("not_found", `${role} not found.`, 404);
if (d.state !== "running") throw new BenchmarkError("invalid", `Start ${role.toLowerCase()} first; benchmarks run against a running server.`, 409);
return d;
/** The endpoint, asked right now: a run against a server that doesn't answer fails at once. */
async function endpointFor(id: string, role: string) {
const e = await db().query.endpoints.findFirst({ where: eq(endpoints.id, id) });
if (!e) throw new BenchmarkError("not_found", `${role} not found.`, 404);
const probe = await probeEndpoint({ baseUrl: e.baseUrl, apiKey: e.apiKey, engine: e.engine });
await db().update(endpoints).set({ probe }).where(eq(endpoints.id, e.id));
if (!probe.ok) throw new BenchmarkError("invalid", `${role} (${e.name}): ${probe.error}`, 409);
return { e, probe };
}
/**
* Queue a run against a running deployment, or a paired A/B between two running deployments of the
* same model (BetterBench sends one model name to both). The worker runs one benchmark at a time.
* Queue a run against an endpoint, or a paired A/B between two endpoints serving the same model
* (BetterBench sends one model name to both). The worker runs one benchmark at a time.
*/
/** Requested through the API: who asked, whether it waits for approval, and its time limit. */
export type AgentRequest = { requestedBy: { tokenId: string; name: string }; pendingApproval: boolean; timeLimitS: number };
export async function createBenchmark(input: BenchmarkInput, agent?: AgentRequest) {
const kind = input.kind ?? (input.deploymentBId ? "ab" : "run");
export async function createBenchmark(input: BenchmarkInput) {
const kind = input.kind ?? (input.endpointBId ? "ab" : "run");
const ab = kind === "ab";
if (ab && !input.deploymentBId) throw new BenchmarkError("invalid", "An A/B needs a second deployment.", 400);
const a = await snapshotOf(input.deploymentId, ab ? "Deployment A" : "The deployment");
const b = ab ? await snapshotOf(input.deploymentBId!, "Deployment B") : null;
if (b) {
if (b.id === a.id) throw new BenchmarkError("invalid", "Pick two different deployments for an A/B.", 400);
if (b.snapshot.repoId !== a.snapshot.repoId) {
throw new BenchmarkError("invalid", "An A/B compares two deployments of the same model (BetterBench requests one model name from both).", 400);
}
if (ab && !input.endpointBId) throw new BenchmarkError("invalid", "An A/B needs a second endpoint.", 400);
if (ab && input.endpointBId === input.endpointId) throw new BenchmarkError("invalid", "Pick two different endpoints for an A/B.", 400);
const a = await endpointFor(input.endpointId, ab ? "Endpoint A" : "The endpoint");
const picked = modelFor(a.e, a.probe, input.model);
if ("error" in picked) throw new BenchmarkError("invalid", picked.error, 400);
const b = ab ? await endpointFor(input.endpointBId!, "Endpoint B") : null;
if (b && b.probe.models.length && !b.probe.models.includes(picked.model)) {
throw new BenchmarkError("invalid", `Endpoint B doesn't serve "${picked.model}". An A/B sends the same model name to both servers.`, 400);
}
const [row] = await db()
.insert(benchmarkRuns)
.values({
kind,
deploymentId: a.id,
deploymentBId: b?.id ?? null,
modelId: a.modelId,
endpointId: a.e.id,
endpointBId: b?.e.id ?? null,
modelId: await libraryModelId(picked.model),
label: input.label || null,
description: input.description || null,
settings:
@@ -88,17 +88,8 @@ export async function createBenchmark(input: BenchmarkInput, agent?: AgentReques
phases: input.phases,
...(ab ? { mdePct: input.mdePct ?? null, maxPairs: input.maxPairs ?? null } : {}),
},
snapshot: a.snapshot,
snapshotB: b?.snapshot ?? null,
sweepId: input.sweepId ?? null,
...(agent
? {
requestedByTokenId: agent.requestedBy.tokenId,
requestedBy: agent.requestedBy.name,
timeLimitS: agent.timeLimitS,
state: agent.pendingApproval ? ("pending_approval" as const) : ("queued" as const),
}
: {}),
snapshot: snapshotOf(a.e, picked.model, a.probe),
snapshotB: b ? snapshotOf(b.e, picked.model, b.probe) : null,
})
.returning({ id: benchmarkRuns.id });
return row;
@@ -106,7 +97,7 @@ export async function createBenchmark(input: BenchmarkInput, agent?: AgentReques
const listColumns = {
id: benchmarkRuns.id,
deploymentId: benchmarkRuns.deploymentId,
endpointId: benchmarkRuns.endpointId,
modelId: benchmarkRuns.modelId,
tool: benchmarkRuns.tool,
label: benchmarkRuns.label,
@@ -121,15 +112,10 @@ const listColumns = {
summary: benchmarkRuns.summary,
hasReport: benchmarkRuns.hasReport,
kind: benchmarkRuns.kind,
deploymentBId: benchmarkRuns.deploymentBId,
endpointBId: benchmarkRuns.endpointBId,
snapshotB: benchmarkRuns.snapshotB,
ab: benchmarkRuns.ab,
resources: benchmarkRuns.resources,
quality: benchmarkRuns.quality,
sweepId: benchmarkRuns.sweepId,
requestedBy: benchmarkRuns.requestedBy,
requestedByTokenId: benchmarkRuns.requestedByTokenId,
timeLimitS: benchmarkRuns.timeLimitS,
meta: benchmarkRuns.meta,
metaB: benchmarkRuns.metaB,
system: benchmarkRuns.system,
@@ -139,13 +125,13 @@ const listColumns = {
export type BenchmarkRow = Awaited<ReturnType<typeof listBenchmarks>>[number];
export async function listBenchmarks(filter: { deploymentId?: string; modelId?: string } = {}) {
export async function listBenchmarks(filter: { endpointId?: string; modelId?: string } = {}) {
return db()
.select(listColumns)
.from(benchmarkRuns)
.where(
and(
filter.deploymentId ? or(eq(benchmarkRuns.deploymentId, filter.deploymentId), eq(benchmarkRuns.deploymentBId, filter.deploymentId)) : undefined,
filter.endpointId ? or(eq(benchmarkRuns.endpointId, filter.endpointId), eq(benchmarkRuns.endpointBId, filter.endpointId)) : undefined,
filter.modelId ? eq(benchmarkRuns.modelId, filter.modelId) : undefined,
),
)
@@ -163,37 +149,17 @@ export async function getBenchmarks(ids: string[]) {
return ids.map((id) => rows.find((r) => r.id === id)).filter((r) => r != null);
}
/** Queued (or still unapproved) runs are cancelled right away; a running one is stopped by the worker. */
/** Queued runs are cancelled right away; a running one is stopped by the worker. */
export async function cancelBenchmark(id: string) {
const run = await getBenchmark(id);
if (!run) throw new BenchmarkError("not_found", "Benchmark not found.", 404);
if (run.state === "queued" || run.state === "pending_approval") {
if (run.state === "queued") {
await db().update(benchmarkRuns).set({ state: "cancelled", finishedAt: new Date() }).where(and(eq(benchmarkRuns.id, id), eq(benchmarkRuns.state, run.state)));
} else if (run.state === "running") {
await db().update(benchmarkRuns).set({ cancelRequestedAt: new Date() }).where(eq(benchmarkRuns.id, id));
}
}
/** Let a run an agent asked for start (it joins the queue). */
export async function approveBenchmark(id: string) {
const res = await db()
.update(benchmarkRuns)
.set({ state: "queued" })
.where(and(eq(benchmarkRuns.id, id), eq(benchmarkRuns.state, "pending_approval")))
.returning({ id: benchmarkRuns.id });
if (res.length === 0) throw new BenchmarkError("invalid", "This run doesn't wait for approval.", 409);
}
/** Turn down a run an agent asked for. */
export async function rejectBenchmark(id: string) {
const res = await db()
.update(benchmarkRuns)
.set({ state: "cancelled", finishedAt: new Date(), error: "Rejected by the user." })
.where(and(eq(benchmarkRuns.id, id), eq(benchmarkRuns.state, "pending_approval")))
.returning({ id: benchmarkRuns.id });
if (res.length === 0) throw new BenchmarkError("invalid", "This run doesn't wait for approval.", 409);
}
/** Rename a run (label) and/or change its description; fields left out stay as they are. */
export async function updateBenchmark(id: string, patch: { label?: string | null; description?: string | null }) {
const set: Partial<typeof benchmarkRuns.$inferInsert> = {};