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: only a worker's progress report may carry a live preview

Adarsh5969f143308e
diff --git a/src/app/api/gpu/computer/tasks/[id]/report/route.ts b/src/app/api/gpu/computer/tasks/[id]/report/route.ts
index 83e30bfc..41a32020 100644
--- a/src/app/api/gpu/computer/tasks/[id]/report/route.ts
+++ b/src/app/api/gpu/computer/tasks/[id]/report/route.ts
@@ -11,8 +11,10 @@ const EVENTS = new Set(["sent", "refused", "queued", "running", "finished", "pas
/** Reports read at once: one person's, and across the server (each holds its body in memory while it is read). */
const AT_ONCE = { person: 2, all: 16 };
-/** A report over this size counts against a lower limit a minute (a progress report with a preview stays under it). */
-const LARGE_BYTES = 128 * 1024;
+/** A report over this size counts against a lower limit a minute. */
+const LARGE_BYTES = 64 * 1024;
+/** A worker's: its progress report with a live preview stays under it. */
+const LARGE_BYTES_WORKER = 128 * 1024;
/** The most a progress report with a worker's live preview may weigh (its preview is kept only up to 64 KB). */
const RUNNING_BYTES = 256 * 1024;
@@ -83,14 +85,19 @@ export async function POST(request: Request, ctx: RouteContext<"/api/gpu/compute
const { id } = await ctx.params;
const lease = request.headers.get("x-fuobe-lease");
let cap: number;
+ let largeAt = LARGE_BYTES;
+ let worker = false;
try {
- cap = capFor(leased(principal, id, lease));
+ const held = leased(principal, id, lease);
+ cap = capFor(held);
+ worker = !!held.pools;
+ if (worker) largeAt = LARGE_BYTES_WORKER;
} catch (e) {
return relayAnswer(e);
}
const declared = Number(request.headers.get("content-length") ?? NaN);
if (Number.isFinite(declared) && declared > cap) return no(413, "That report is too large");
- if (cap > LARGE_BYTES && !(declared <= LARGE_BYTES)) {
+ if (cap > largeAt && !(declared <= largeAt)) {
const big = rateOf(callerKey(request, principal), "report-large", 30);
if (big) return big;
}
@@ -111,7 +118,7 @@ export async function POST(request: Request, ctx: RouteContext<"/api/gpu/compute
const event = body && typeof body === "object" ? eventOf(body) : null;
if (!event) return no(400, "Not a report");
// A progress report is a few KB, unless it carries a worker's live preview.
- const withPreview = event.event === "running" && typeof body?.preview === "string";
+ const withPreview = worker && event.event === "running" && typeof body?.preview === "string";
if (!LARGE_EVENTS.has(event.event) && raw!.length > (withPreview ? RUNNING_BYTES : RELAY_LIMITS.smallReportBytes)) return no(413, "That report is too large");
// Where the job is now (it may have moved while the body arrived).
const t = leased(principal, id, lease);
diff --git a/tests/computer-security.test.ts b/tests/computer-security.test.ts
index 81db25b0..5ea7bb44 100644
--- a/tests/computer-security.test.ts
+++ b/tests/computer-security.test.ts
@@ -375,6 +375,19 @@ describe("reports", () => {
expect((await report({ event: "sent", promptId: c.promptId })).status).toBe(409);
});
+ it("a tab's progress report stays a few KB: a picture with it is refused and nothing is kept", async () => {
+ waitingTask(`acct:${a}`);
+ const c = await claimed("a");
+ const report = (body: Record<string, unknown>) => call("a", "POST", `/api/gpu/computer/tasks/${c.id}/report`, { headers: { "x-fuobe-lease": c.lease }, body: { ...body } });
+ expect((await report({ event: "sent", promptId: c.promptId })).status).toBe(200);
+ const jpeg = Buffer.alloc(30 * 1024, 7);
+ jpeg.set([0xff, 0xd8, 0xff]);
+ expect((await report({ event: "running", value: 1, max: 4, preview: jpeg.toString("base64") })).status).toBe(413);
+ expect(tasks.taskPreview(c.id)).toBeNull();
+ expect((await report({ event: "running", value: 2, max: 4 })).status).toBe(200);
+ expect(tasks.taskProgress(c.id)).toMatchObject({ value: 2, max: 4 });
+ });
+
it("a finished entry over 8 MB is refused", async () => {
waitingTask(`acct:${a}`);
const c = await claimed("a");