Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Worker: an optional size-only file check, so a first start needn't read every model file

Adarsh2979e1f3f37d
diff --git a/bin/lib/worker/inventory.mjs b/bin/lib/worker/inventory.mjs
index bc0eb7e3..7149682b 100644
--- a/bin/lib/worker/inventory.mjs
+++ b/bin/lib/worker/inventory.mjs
@@ -211,6 +211,9 @@ export async function modelFiles(modelDirs, index, cacheFile, pins = filePins(),
if (!st.isFile()) return null;
if (st.size !== f.sizeBytes) return { ok: false };
const key = `${p}|${st.size}|${st.mtimeMs}`;
+ // worker.json `fileCheck: "size"`: a file of the exact size counts as the pinned one until its hash is known (a
+ // hash already in the cache still decides), so a first start doesn't read hundreds of GB. Nothing is cached for it.
+ if (o.fileCheck === "size" && cache[key] === undefined) return { ok: true, size: st.size, sha: want };
const sha = cache[key] ?? (cache[key] = await sha256File(p));
return { ok: sha === want, size: st.size, sha };
};
diff --git a/bin/lib/worker/run.mjs b/bin/lib/worker/run.mjs
index cde179d5..0ee10c4e 100644
--- a/bin/lib/worker/run.mjs
+++ b/bin/lib/worker/run.mjs
@@ -356,7 +356,7 @@ async function work(saved, deps, owner) {
async function scan() {
packs = packFolders(cfg.comfyDir, index);
- inv = { files: await modelFiles(cfg.modelDirs ?? [], index, path.join(cfg.workDir, "hash-cache.json"), deps.pins, { comfyDir: cfg.comfyDir }), nodePacks: packs.map(({ name, commit }) => ({ name, commit })), media: inv.media };
+ inv = { files: await modelFiles(cfg.modelDirs ?? [], index, path.join(cfg.workDir, "hash-cache.json"), deps.pins, { comfyDir: cfg.comfyDir, fileCheck: cfg.fileCheck }), nodePacks: packs.map(({ name, commit }) => ({ name, commit })), media: inv.media };
invHash = inventoryHash(inv);
}
// One look at a time; the next beat carries a changed hash, and the studio then asks for the list.
diff --git a/tests/worker-environment.test.ts b/tests/worker-environment.test.ts
index 9ddc91db..5327cef7 100644
--- a/tests/worker-environment.test.ts
+++ b/tests/worker-environment.test.ts
@@ -71,6 +71,29 @@ describe("the worker's model files", () => {
expect(Object.keys(JSON.parse(fs.readFileSync(cache, "utf8")))).toHaveLength(3);
});
+ it('with fileCheck "size", takes a file of the exact size without reading it, and a cached hash still decides', async () => {
+ const models = tempDir("fuobe-worker-models-size-");
+ fs.mkdirSync(path.join(models, "loras"));
+ fs.writeFileSync(path.join(models, "loras", "big.safetensors"), "hello");
+ fs.writeFileSync(path.join(models, "loras", "short.safetensors"), "hi");
+ fs.writeFileSync(path.join(models, "loras", "known.safetensors"), "jello");
+ const index = {
+ files: {
+ a: { folder: "loras", file: "big.safetensors", sizeBytes: 5 },
+ b: { folder: "loras", file: "short.safetensors", sizeBytes: 5 },
+ c: { folder: "loras", file: "known.safetensors", sizeBytes: 5 },
+ },
+ };
+ const pins = { "loras/big.safetensors": sha("hello"), "loras/short.safetensors": sha("hello"), "loras/known.safetensors": sha("hello") };
+ const cache = path.join(models, "hash-cache.json");
+ // the swapped file's real hash is already known: it still doesn't count
+ await modelFiles([models], { files: { c: index.files.c } }, cache, pins);
+ const found = await modelFiles([models], index, cache, pins, { fileCheck: "size" });
+ expect(found).toEqual([{ folder: "loras", name: "big.safetensors", size: 5, sha256: sha("hello") }]);
+ // nothing new is cached for a file taken by its size
+ expect(Object.keys(JSON.parse(fs.readFileSync(cache, "utf8")))).toHaveLength(1);
+ });
+
it("counts only the copy ComfyUI finds first: a wrong copy in an earlier folder isn't made up for by a good one later", async () => {
const a = tempDir("fuobe-worker-models-a-");
const b = tempDir("fuobe-worker-models-b-");