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
+7
-20
@@ -24,8 +24,8 @@ export class JobError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
/** Jobs that block another job for the same model; pending approval counts (it will run). */
|
||||
export const OPEN_STATES = ["pending_approval", "queued", ...ACTIVE_JOB_STATES] as const;
|
||||
/** Jobs that block another job for the same model. */
|
||||
export const OPEN_STATES = ["queued", ...ACTIVE_JOB_STATES] as const;
|
||||
const INSERT_CHUNK = 500;
|
||||
|
||||
/** True if the model has a queued or running job (only one job per model at a time). */
|
||||
@@ -37,19 +37,15 @@ export async function hasOpenJob(modelId: string): Promise<boolean> {
|
||||
return !!open;
|
||||
}
|
||||
|
||||
/** Who asked for a job through the API (token id + its name at the time). */
|
||||
export type RequestedBy = { tokenId: string; name: string };
|
||||
|
||||
/**
|
||||
* Queue a download of all selected files of a model at its pinned SHA. hf skips files that are
|
||||
* already complete, so this also serves as resume and repair. `removePaths`: files of an older
|
||||
* revision to delete once the download succeeded (updates). `pendingApproval`: the job waits in
|
||||
* "pending_approval" (the worker only picks up "queued") until someone approves it.
|
||||
* revision to delete once the download succeeded (updates).
|
||||
*/
|
||||
export async function queueDownload(
|
||||
modelId: string,
|
||||
purpose: JobPurpose = "initial",
|
||||
options: { removePaths?: string[]; pendingApproval?: boolean; requestedBy?: RequestedBy; previousRule?: JobResult["previousRule"] } = {},
|
||||
options: { removePaths?: string[] } = {},
|
||||
): Promise<{ jobId: string }> {
|
||||
const d = db();
|
||||
const model = await d.query.models.findFirst({ where: eq(models.id, modelId) });
|
||||
@@ -69,23 +65,19 @@ export async function queueDownload(
|
||||
const rows = files.map((f) => ({ jobId, modelFileId: f.id, path: f.path, expectedBytes: f.size }));
|
||||
const result: JobResult = {};
|
||||
if (options.removePaths?.length) result.removePaths = options.removePaths;
|
||||
if (options.previousRule) result.previousRule = options.previousRule;
|
||||
await d.batch([
|
||||
d.insert(jobs).values({
|
||||
id: jobId,
|
||||
modelId,
|
||||
kind: "download",
|
||||
purpose,
|
||||
state: options.pendingApproval ? "pending_approval" : "queued",
|
||||
state: "queued",
|
||||
targetSha: model.pinnedSha,
|
||||
totalBytes: files.reduce((s, f) => s + f.size, 0),
|
||||
result: Object.keys(result).length ? result : null,
|
||||
requestedByTokenId: options.requestedBy?.tokenId ?? null,
|
||||
requestedBy: options.requestedBy?.name ?? null,
|
||||
}),
|
||||
...chunk(rows, INSERT_CHUNK).map((c) => d.insert(jobFiles).values(c)),
|
||||
// A job waiting for approval doesn't download yet; the model keeps its status.
|
||||
...(options.pendingApproval ? [] : [d.update(models).set({ status: "downloading" }).where(eq(models.id, modelId))]),
|
||||
d.update(models).set({ status: "downloading" }).where(eq(models.id, modelId)),
|
||||
]);
|
||||
return { jobId };
|
||||
}
|
||||
@@ -122,8 +114,6 @@ export async function queueVerify(modelId: string, deep: boolean): Promise<{ job
|
||||
|
||||
/** Ask the worker to stop a job. Queued jobs are cancelled by the worker on its next tick. */
|
||||
export async function requestCancel(jobId: string): Promise<void> {
|
||||
const pending = await db().query.jobs.findFirst({ columns: { id: true }, where: and(eq(jobs.id, jobId), eq(jobs.state, "pending_approval")) });
|
||||
if (pending) throw new JobError("not_cancellable", "This download waits for approval. Approve or reject it instead.", 409);
|
||||
const res = await db()
|
||||
.update(jobs)
|
||||
.set({ cancelRequestedAt: new Date() })
|
||||
@@ -157,8 +147,6 @@ export type JobSnapshot = {
|
||||
errorMessage: string | null;
|
||||
result: JobResult | null;
|
||||
cancelRequested: boolean;
|
||||
/** Token name if the job was requested through the API. */
|
||||
requestedBy: string | null;
|
||||
createdAt: number;
|
||||
startedAt: number | null;
|
||||
finishedAt: number | null;
|
||||
@@ -191,13 +179,12 @@ const jobColumns = {
|
||||
errorMessage: jobs.errorMessage,
|
||||
result: jobs.result,
|
||||
cancelRequestedAt: jobs.cancelRequestedAt,
|
||||
requestedBy: jobs.requestedBy,
|
||||
createdAt: jobs.createdAt,
|
||||
startedAt: jobs.startedAt,
|
||||
finishedAt: jobs.finishedAt,
|
||||
};
|
||||
|
||||
type JobRow = Omit<typeof jobs.$inferSelect, "targetSha" | "updatedAt" | "requestedByTokenId"> & { repoId: string };
|
||||
type JobRow = Omit<typeof jobs.$inferSelect, "targetSha" | "updatedAt"> & { repoId: string };
|
||||
|
||||
function toSnapshot(r: JobRow): JobSnapshot {
|
||||
const { cancelRequestedAt, createdAt, startedAt, finishedAt, ...rest } = r;
|
||||
|
||||
Reference in new issue
Block a user