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:
1 parent
1d2f908b75
commit
276108932d
199 files changed
+5462
-15961
No files matched your search
@@ -0,0 +1,82 @@
|
||||
// The code sandbox: runs the quality eval's coding answers (model-written Python plus unit tests).
|
||||
// Started as its own container (`sandbox` role) with no network, a read-only root, no capabilities
|
||||
// and small limits; it sees only the exchange folder. Each program also gets per-process limits
|
||||
// (memory, CPU time, file size, processes) and is killed after RUN_TIMEOUT_S.
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { ALIVE_FILE, ALIVE_MS, isJobId, programFile, resultFile, RUN_TIMEOUT_S, type SandboxResult } from "./protocol";
|
||||
|
||||
const dir = process.env.SANDBOX_DIR ?? "/sandbox";
|
||||
const MAX_OUTPUT = 8_000;
|
||||
|
||||
// Applied inside the child before the program runs; the program arrives on stdin.
|
||||
const LIMITS = [
|
||||
"import resource,sys",
|
||||
"M=256*1024*1024",
|
||||
"resource.setrlimit(resource.RLIMIT_AS,(M,M))",
|
||||
`resource.setrlimit(resource.RLIMIT_CPU,(${RUN_TIMEOUT_S},${RUN_TIMEOUT_S}))`,
|
||||
"resource.setrlimit(resource.RLIMIT_FSIZE,(1<<20,1<<20))",
|
||||
"resource.setrlimit(resource.RLIMIT_NPROC,(16,16))",
|
||||
"src=sys.stdin.read()",
|
||||
"exec(compile(src,'solution','exec'),{'__name__':'__main__'})",
|
||||
].join("\n");
|
||||
|
||||
function run(program: string): Promise<SandboxResult> {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn("python3", ["-I", "-c", LIMITS], {
|
||||
cwd: "/tmp",
|
||||
env: { PATH: "/usr/local/bin:/usr/bin:/bin", PYTHONDONTWRITEBYTECODE: "1", LANG: "C.UTF-8" } as unknown as NodeJS.ProcessEnv,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
let output = "";
|
||||
const add = (b: Buffer) => {
|
||||
output = (output + b.toString("utf8")).slice(-MAX_OUTPUT);
|
||||
};
|
||||
child.stdout.on("data", add);
|
||||
child.stderr.on("data", add);
|
||||
let timedOut = false;
|
||||
const timer = setTimeout(() => {
|
||||
timedOut = true;
|
||||
child.kill("SIGKILL");
|
||||
}, RUN_TIMEOUT_S * 1000);
|
||||
child.on("error", (err) => {
|
||||
clearTimeout(timer);
|
||||
resolve({ exitCode: null, timedOut: false, output: `could not start python3: ${err.message}` });
|
||||
});
|
||||
child.on("close", (code) => {
|
||||
clearTimeout(timer);
|
||||
resolve({ exitCode: code, timedOut, output });
|
||||
});
|
||||
child.stdin.end(program);
|
||||
});
|
||||
}
|
||||
|
||||
async function tick() {
|
||||
for (const name of await readdir(dir)) {
|
||||
const id = name.endsWith(".py") ? name.slice(0, -3) : "";
|
||||
if (!isJobId(id)) continue;
|
||||
const path = join(dir, programFile(id));
|
||||
const program = await readFile(path, "utf8").catch(() => null);
|
||||
await rm(path, { force: true });
|
||||
if (program == null) continue;
|
||||
const result = await run(program);
|
||||
const tmp = join(dir, `${id}.tmp`);
|
||||
await writeFile(tmp, JSON.stringify(result));
|
||||
await rename(tmp, join(dir, resultFile(id)));
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`kaname sandbox: watching ${dir}`);
|
||||
const alive = () => writeFile(join(dir, ALIVE_FILE), String(Date.now())).catch((err) => console.error(`can't write ${dir}: ${err.message}`));
|
||||
await alive();
|
||||
setInterval(alive, ALIVE_MS);
|
||||
for (;;) {
|
||||
await tick().catch((err) => console.error(err));
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
}
|
||||
}
|
||||
|
||||
void main();
|
||||
@@ -0,0 +1,20 @@
|
||||
// The exchange folder between the worker and the code sandbox (a separate container without network,
|
||||
// see compose.yaml). The worker writes <id>.py; the sandbox runs it and writes <id>.json, then
|
||||
// deletes the program. Files appear by rename, so neither side reads a half-written file.
|
||||
|
||||
export const ALIVE_FILE = ".alive";
|
||||
/** The sandbox touches ALIVE_FILE this often; the worker treats it as gone after ALIVE_STALE_MS. */
|
||||
export const ALIVE_MS = 2_000;
|
||||
export const ALIVE_STALE_MS = 10_000;
|
||||
export const RUN_TIMEOUT_S = 15;
|
||||
|
||||
export type SandboxResult = {
|
||||
exitCode: number | null;
|
||||
timedOut: boolean;
|
||||
/** stdout and stderr together, the last few KB. */
|
||||
output: string;
|
||||
};
|
||||
|
||||
export const programFile = (id: string) => `${id}.py`;
|
||||
export const resultFile = (id: string) => `${id}.json`;
|
||||
export const isJobId = (id: string) => /^[0-9a-z]{8,40}$/.test(id);
|
||||
Reference in new issue
Block a user