Delete, verify/deep verify, repair and update checks
- Delete any model (incl. failed ones); the worker removes the repo's files (keeps foreign files and empty-folder cleanup), then the rows. - Verify (existence, size, hf metadata) and deep verify (SHA-256 / git blob SHA-1 against the Hub) with missing/mismatch/extra report. - Repair = download of the selection; broken files are deleted first because hf skips files whose metadata matches without checking them. - Hub check resolves the tracked revision and stores which selected files a newer commit changes/adds/removes; Update pins it (old commit kept in model_revisions), downloads, then removes dropped files. - Worker runs verify/delete jobs next to downloads (2 local slots). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c2c239bf16
commit
7864a492c9
37 files changed
+2365
-191
No files matched your search
+30
-1
@@ -1,10 +1,12 @@
|
||||
import { type ChildProcess, spawn } from "node:child_process";
|
||||
import { mkdir, statfs } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import {
|
||||
type JobErrorCode,
|
||||
type JobState,
|
||||
type ModelFileState,
|
||||
jobFiles,
|
||||
jobs,
|
||||
modelFiles,
|
||||
@@ -17,12 +19,15 @@ import {
|
||||
bytesOnDisk,
|
||||
type ExpectedFile,
|
||||
listIncomplete,
|
||||
fileSize,
|
||||
modelDir,
|
||||
removeLocalFile,
|
||||
removeStaleIncomplete,
|
||||
} from "./hf-layout";
|
||||
import { JobLog } from "./job-log";
|
||||
import { log } from "./log";
|
||||
import { settleModelStatus } from "./model-status";
|
||||
import type { Runner } from "./runner";
|
||||
import { SpeedMeter } from "./speed";
|
||||
|
||||
const SAMPLE_MS = 1_000;
|
||||
@@ -45,6 +50,8 @@ type FileRow = {
|
||||
doneBytes: number;
|
||||
lfsSha256: string | null;
|
||||
blobOid: string | null;
|
||||
/** Last known state of the file (deep verify may have found a hash mismatch). */
|
||||
state: ModelFileState;
|
||||
};
|
||||
|
||||
type Outcome =
|
||||
@@ -52,7 +59,7 @@ type Outcome =
|
||||
| { state: "cancelled" | "interrupted"; message: string }
|
||||
| { state: "failed"; code: JobErrorCode; message: string; exitCode?: number | null };
|
||||
|
||||
export class DownloadRunner {
|
||||
export class DownloadRunner implements Runner {
|
||||
private child?: ChildProcess;
|
||||
private stopReason?: "cancelled" | "interrupted";
|
||||
private killTimer?: NodeJS.Timeout;
|
||||
@@ -74,6 +81,10 @@ export class DownloadRunner {
|
||||
return this.model.id;
|
||||
}
|
||||
|
||||
get kind() {
|
||||
return this.job.kind;
|
||||
}
|
||||
|
||||
/** User cancel: stop hf, keep completed files. */
|
||||
cancel() {
|
||||
this.stop("cancelled");
|
||||
@@ -144,6 +155,18 @@ export class DownloadRunner {
|
||||
this.jobLog.system(`Removed ${stale.count} partial file(s) from an earlier run (${formatBytes(stale.bytes)}).`);
|
||||
}
|
||||
|
||||
// hf skips a file whose metadata matches without looking at its content or size, so broken
|
||||
// files (wrong size, or a hash mismatch found by deep verify) have to go first.
|
||||
const broken: string[] = [];
|
||||
for (const f of this.files) {
|
||||
const size = await fileSize(join(dir, f.path));
|
||||
const wrong = size != null && (size !== f.expectedBytes || f.state === "hash_mismatch");
|
||||
if (wrong && (await removeLocalFile(dir, f.path))) broken.push(f.path);
|
||||
}
|
||||
if (broken.length > 0) {
|
||||
this.jobLog.system(`Deleted ${broken.length} broken file(s) so hf downloads them again: ${broken.slice(0, 5).join(", ")}${broken.length > 5 ? ", …" : ""}`);
|
||||
}
|
||||
|
||||
const initial = await this.sample(dir, expected);
|
||||
const remaining = expected.reduce((s, f, i) => s + (initial[i].complete ? 0 : f.size), 0);
|
||||
const doneCount = initial.filter((p) => p.complete).length;
|
||||
@@ -199,6 +222,12 @@ export class DownloadRunner {
|
||||
.join(", ")}${bad.length > 5 ? ", …" : ""}`,
|
||||
};
|
||||
}
|
||||
|
||||
// Update: files the new revision no longer has (or that are no longer selected).
|
||||
const remove = (this.job.result?.removePaths ?? []).filter((p) => !this.files.some((f) => f.path === p));
|
||||
let removed = 0;
|
||||
for (const path of remove) if (await removeLocalFile(dir, path)) removed++;
|
||||
if (removed > 0) this.jobLog.system(`Deleted ${removed} file(s) that are no longer part of the selection: ${remove.slice(0, 5).join(", ")}`);
|
||||
return { state: "completed" };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user