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.

Workers: the catalog version counts only what can change a composed graph

Adarsh4861dce12f5e
diff --git a/bin/lib/worker/composer-files.mjs b/bin/lib/worker/composer-files.mjs
index 2c6b5dc0..095bba95 100644
--- a/bin/lib/worker/composer-files.mjs
+++ b/bin/lib/worker/composer-files.mjs
@@ -1,7 +1,7 @@
// The graph composer the worker builds in (docs/gpu-workers.md, "Job tickets"): the files of src/lib/ticket-compose.ts
-// and everything it imports, and the catalog version, one SHA-256 over those files and the catalog's workflows. The
-// studio computes the same version from its own copy (src/server/computer/catalog-version.ts), so a worker composes
-// a ticket only from the catalog the ticket was made for.
+// and everything it imports, and the catalog version, one SHA-256 over what of those files and the catalog's workflows
+// can change a composed graph. The studio computes the same version from its own copy
+// (src/server/computer/catalog-version.ts), so a worker composes a ticket only from the catalog the ticket was made for.
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
@@ -52,18 +52,68 @@ export function composerFiles(root) {
return [...seen].sort();
}
-/** A text file's SHA-256 with its line ends made plain (a Windows checkout's CRLF counts as LF). */
-const textSha = (file) => crypto.createHash("sha256").update(fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n")).digest("hex");
+/**
+ * The composer's files and catalog files the catalog version leaves out: they hold only what people read or see (tile
+ * covers and cards, the counts, prices and licence words the pages quote, the cloud models, Kinetic's motion groups,
+ * which graphs passed a real render), so a change to one never changes a composed graph. The worker still builds the
+ * composer's ones in (the composer imports them). The studio leaves out the same (src/server/computer/catalog-version.ts).
+ */
+export const VERSION_LEAVES_OUT = new Set([
+ "src/lib/catalog/cloud-models.generated.ts",
+ "src/lib/catalog/counts.ts",
+ "src/lib/catalog/promo.ts",
+ "src/lib/licences.ts",
+ "src/lib/motion/kinetic-groups.ts",
+ "src/lib/preset-cards.ts",
+ "src/lib/preset-peaks.generated.ts",
+ "src/lib/template-covers.generated.ts",
+ "src/lib/template-covers.ts",
+ "workflows/comfyui/gpu-tested.json",
+]);
+
+/**
+ * A file's text as the catalog version reads it: line ends made plain (a Windows checkout's CRLF counts as LF), and in
+ * a script without its comment lines, comment blocks, blank lines, each line's indent and a model's one-line description
+ * (a `tagline:` line, which only pages show): none of them changes a composed graph.
+ */
+export function versionText(name, text) {
+ const plain = text.replace(/\r\n/g, "\n");
+ if (!/\.[cm]?[jt]sx?$/.test(name)) return plain;
+ const out = [];
+ let inBlock = false;
+ for (const line of plain.split("\n")) {
+ let t = line.trim();
+ if (inBlock) {
+ const end = t.indexOf("*/");
+ if (end < 0) continue;
+ inBlock = false;
+ t = t.slice(end + 2).trim();
+ } else if (t.startsWith("/*")) {
+ const end = t.indexOf("*/", 2);
+ if (end < 0) {
+ inBlock = true;
+ continue;
+ }
+ t = t.slice(end + 2).trim();
+ }
+ if (!t || t.startsWith("//") || /^tagline: /.test(t)) continue;
+ out.push(t);
+ }
+ return out.join("\n");
+}
+
+const versionSha = (name, file) => crypto.createHash("sha256").update(versionText(name, fs.readFileSync(file, "utf8"))).digest("hex");
/**
- * The catalog version: one SHA-256 over each composer file's name and content, and each .json of the catalog's folder
- * (workflows/comfyui), with line ends made plain.
+ * The catalog version: one SHA-256 over what changes a composed graph: each composer file's name and code, and each
+ * .json of the catalog's folder (workflows/comfyui), but for VERSION_LEAVES_OUT (versionText says what of a file counts).
*/
export function catalogVersion(root, catalogDir = path.join(root, "workflows/comfyui")) {
const entries = composerFiles(root).map((rel) => [rel, path.join(root, rel)]);
for (const f of fs.readdirSync(catalogDir).filter((x) => x.endsWith(".json"))) entries.push([`workflows/comfyui/${f}`, path.join(catalogDir, f)]);
- entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
+ const kept = entries.filter(([name]) => !VERSION_LEAVES_OUT.has(name));
+ kept.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
const all = crypto.createHash("sha256");
- for (const [name, file] of entries) all.update(`${name}\u0000${textSha(file)}\n`);
+ for (const [name, file] of kept) all.update(`${name}\u0000${versionSha(name, file)}\n`);
return all.digest("hex");
}
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index 9ae08471..78ca22c1 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -415,9 +415,12 @@ graphs, and so do a person's own computer's jobs (Fuobe Connect and the browser)
- **Files the graph makes.** A few graphs read a small file that the composer makes (a palette swatch, a fade curve).
The worker makes it again, checks it against the SHA-256 in the ticket, and sends its own copy to its ComfyUI. It
never reads the studio's copy.
-- **The catalog version.** One SHA-256 over the composer's files and the catalog's workflows. The worker's build writes
- it (`dist/catalog-version.json`), and the studio computes the same from its own files (or reads
- `FUOBE_CATALOG_VERSION`). Each beat says the worker's version. A ticket goes only to a worker with the same version.
+- **The catalog version.** One SHA-256 over what can change a composed graph: the composer's code and the catalog's
+ workflows. Comments, a model's one-line description, tile covers and cards, the counts, prices and licence words the
+ pages quote, the cloud models and the record of real renders are left out, so an update that changes only what people
+ read or see keeps the version, and the workers keep taking accounts' runs. The worker's build writes it
+ (`dist/catalog-version.json`), and the studio computes the same from its own files (or reads `FUOBE_CATALOG_VERSION`).
+ Each beat says the worker's version. A ticket goes only to a worker with the same version.
A worker built from another catalog takes the owner's own jobs, and its state in Settings → Workers reads **Update
the worker** while accounts' runs may come to the install's GPUs. Update it (see "Install and update").
- **The PC is the ceiling.** `ceiling` in `worker.json` (setup asks for it) is the most the PC ever runs:
diff --git a/src/server/computer/catalog-version.ts b/src/server/computer/catalog-version.ts
index 72cd0d64..9bfd0e0d 100644
--- a/src/server/computer/catalog-version.ts
+++ b/src/server/computer/catalog-version.ts
@@ -4,8 +4,9 @@ import fs from "node:fs";
import path from "node:path";
/**
- * The catalog version the studio makes job tickets for (src/lib/job-ticket.ts): one SHA-256 over the graph composer's
- * files (src/lib/ticket-compose.ts and everything it imports) and the catalog's workflows, with line ends made plain.
+ * The catalog version the studio makes job tickets for (src/lib/job-ticket.ts): one SHA-256 over what can change a
+ * composed graph: the graph composer's files (src/lib/ticket-compose.ts and everything it imports) and the catalog's
+ * workflows, leaving out what people only read or see and every comment (VERSION_LEAVES_OUT, versionText).
* The worker program's build computes the same from its own checkout (bin/lib/worker/composer-files.mjs), so a worker
* built from another catalog says "update the worker" and takes no ticket. Read from this server's own files once.
*/
@@ -45,16 +46,67 @@ export function composerFiles(root = process.cwd()): string[] {
return [...seen].sort();
}
-const textSha = (file: string) => crypto.createHash("sha256").update(fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n")).digest("hex");
+const textSha = (name: string, file: string) => crypto.createHash("sha256").update(versionText(name, fs.readFileSync(file, "utf8"))).digest("hex");
+
+/**
+ * The composer's files and catalog files the catalog version leaves out: they hold only what people read or see (tile
+ * covers and cards, the counts, prices and licence words the pages quote, the cloud models, Kinetic's motion groups,
+ * which graphs passed a real render), so a change to one never changes a composed graph. The same list as the worker
+ * build's (bin/lib/worker/composer-files.mjs VERSION_LEAVES_OUT).
+ */
+export const VERSION_LEAVES_OUT: ReadonlySet<string> = new Set([
+ "src/lib/catalog/cloud-models.generated.ts",
+ "src/lib/catalog/counts.ts",
+ "src/lib/catalog/promo.ts",
+ "src/lib/licences.ts",
+ "src/lib/motion/kinetic-groups.ts",
+ "src/lib/preset-cards.ts",
+ "src/lib/preset-peaks.generated.ts",
+ "src/lib/template-covers.generated.ts",
+ "src/lib/template-covers.ts",
+ "workflows/comfyui/gpu-tested.json",
+]);
+
+/**
+ * A file's text as the catalog version reads it: line ends made plain, and in a script without its comment lines, comment
+ * blocks, blank lines, each line's indent and a model's one-line description (a `tagline:` line), as the worker build
+ * reads it (composer-files.mjs versionText).
+ */
+export function versionText(name: string, text: string): string {
+ const plain = text.replace(/\r\n/g, "\n");
+ if (!/\.[cm]?[jt]sx?$/.test(name)) return plain;
+ const out: string[] = [];
+ let inBlock = false;
+ for (const line of plain.split("\n")) {
+ let t = line.trim();
+ if (inBlock) {
+ const end = t.indexOf("*/");
+ if (end < 0) continue;
+ inBlock = false;
+ t = t.slice(end + 2).trim();
+ } else if (t.startsWith("/*")) {
+ const end = t.indexOf("*/", 2);
+ if (end < 0) {
+ inBlock = true;
+ continue;
+ }
+ t = t.slice(end + 2).trim();
+ }
+ if (!t || t.startsWith("//") || /^tagline: /.test(t)) continue;
+ out.push(t);
+ }
+ return out.join("\n");
+}
/** The catalog version of the files under `root` (null when they aren't there to read). */
export function computeCatalogVersion(root = process.cwd(), catalogDir = path.join(root, "workflows", "comfyui")): string | null {
try {
const entries: [string, string][] = composerFiles(root).map((rel) => [rel, path.join(root, rel)]);
for (const f of fs.readdirSync(catalogDir).filter((x) => x.endsWith(".json"))) entries.push([`workflows/comfyui/${f}`, path.join(catalogDir, f)]);
- entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
+ const kept = entries.filter(([name]) => !VERSION_LEAVES_OUT.has(name));
+ kept.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
const all = crypto.createHash("sha256");
- for (const [name, file] of entries) all.update(`${name}\u0000${textSha(file)}\n`);
+ for (const [name, file] of kept) all.update(`${name}\u0000${textSha(name, file)}\n`);
return all.digest("hex");
} catch {
return null;
diff --git a/tests/job-tickets.test.ts b/tests/job-tickets.test.ts
index 74bae0fa..506a2376 100644
--- a/tests/job-tickets.test.ts
+++ b/tests/job-tickets.test.ts
@@ -317,6 +317,52 @@ describe("the catalog version", () => {
expect(names.every((n: string) => n.startsWith("src/"))).toBe(true);
});
+ it("stays the same after a change people only read or see, and changes with the composer's code or a workflow", async () => {
+ const fsMod = await import("node:fs");
+ const os = await import("node:os");
+ const dir = fsMod.mkdtempSync(path.join(os.tmpdir(), "fuobe-catalog-narrow-"));
+ try {
+ // A copy of the composer's files and the catalog.
+ for (const rel of composerFiles(ROOT)) {
+ fsMod.mkdirSync(path.dirname(path.join(dir, rel)), { recursive: true });
+ fsMod.copyFileSync(path.join(ROOT, rel), path.join(dir, rel));
+ }
+ const lib = path.join(ROOT, "workflows/comfyui");
+ fsMod.mkdirSync(path.join(dir, "workflows/comfyui"), { recursive: true });
+ for (const f of fsMod.readdirSync(lib).filter((x) => x.endsWith(".json"))) fsMod.copyFileSync(path.join(lib, f), path.join(dir, "workflows/comfyui", f));
+ const both = () => {
+ const built = builtVersion(dir);
+ expect(computeCatalogVersion(dir)).toBe(built);
+ return built;
+ };
+ expect(both()).toBe(VERSION);
+ const change = (rel: string, edit: (text: string) => string) => {
+ const file = path.join(dir, rel);
+ const before = fsMod.readFileSync(file, "utf8");
+ const after = edit(before);
+ expect(after, rel).not.toBe(before);
+ fsMod.writeFileSync(file, after);
+ };
+ // What people only read or see: a comment, a blank line and an indent in the composer, a model's one-line
+ // description, a tile's cover, the cloud models, the record of real renders.
+ change("src/lib/comfy-compose.ts", (t) => t.replace("/**", "// A note for whoever reads this.\n\n/**\n * One more line of its comment.").replace(/\n {2}if \(/, "\n if ("));
+ change("src/lib/catalog/models.ts", (t) => t.replace(/tagline: "/, 'tagline: "Sharper. '));
+ change("src/lib/template-covers.generated.ts", (t) => t.replace("?v=", "?v=0"));
+ change("src/lib/catalog/cloud-models.generated.ts", (t) => t.replace('"name": "', '"name": "New '));
+ change("workflows/comfyui/gpu-tested.json", (t) => t.replace("{", '{\n "a-note": "seen",'));
+ expect(both()).toBe(VERSION);
+ // The composer's code: a new version.
+ change("src/lib/comfy-compose.ts", (t) => `${t}\nexport const PROBE = 1;\n`);
+ const code = both();
+ expect(code).not.toBe(VERSION);
+ // A model's route or setting (not its description): a new one again.
+ change("src/lib/catalog/models.ts", (t) => t.replace(/routes: \[comfy\("/, 'routes: [comfy("x'));
+ expect(both()).not.toBe(code);
+ } finally {
+ fsMod.rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
it("the composer as built into the worker composes the same graph as the studio's", async () => {
const { spawnSync } = await import("node:child_process");
const fsMod = await import("node:fs");