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.

Hosted runs: a price check reads the size of the viewer's own files only

Adarsh45d686bb98dc
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index b01fbe54..d26e567c 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -365,8 +365,9 @@ export async function moderateRun(
): Promise<{ ok: true; checkOutputs: boolean } | { ok: false; refusal: Refusal }> {
if (!moderationConfigured()) return { ok: true, checkOutputs: false };
const kind = planned ? outputKind(planned.op, planned.model) : (browser?.kind ?? "image");
+ // Read as the account (an input's size from its own files only).
const run = planned
- ? { ...runFacts(req, planned, kind), place: place === "pool" ? ("pool" as const) : planned.route.provider === "comfyui" ? ("own-gpu" as const) : ("own-key" as const) }
+ ? { ...runAsTenant({ kind: "account", id: account.id }, () => runFacts(req, planned, kind)), place: place === "pool" ? ("pool" as const) : planned.route.provider === "comfyui" ? ("own-gpu" as const) : ("own-key" as const) }
: null;
const a = await checkRun({
requestId: nanoid(16),
@@ -402,7 +403,7 @@ export async function reservePool(
const a = await reserve({
requestId: nanoid(16),
account: accountFacts(account),
- run: { ...runFacts(req, planned, kind), ...(steps?.length && { steps }) },
+ run: { ...runOnPool(account.id, () => runFacts(req, planned, kind)), ...(steps?.length && { steps }) },
queue: queueFacts(account.id, planned.route.endpoint),
shown: shown ?? { amount: 0, priceVersion: "" },
});
@@ -478,8 +479,9 @@ export async function poolQuote(
if (hasGpu && wish !== "pool") return null;
return { planned, quote: notOfferedQuote(gateWords(gate.reason, !account)), line: line(queueFacts(account?.id ?? null, planned.route.endpoint)) };
}
- // Priced once for every step of a chain that uses this install's GPUs.
- const facts = { ...runFacts(req, planned, outputKind(planned.op, planned.model)), ...(gate.steps && { steps: pricedSteps(gate.steps) }) };
+ // Priced once for every step of a chain that uses this install's GPUs. Its facts are read as the viewer (an input's
+ // size from its own files only: another's file reads as none, and says nothing of whether it exists).
+ const facts = { ...runOnPool(account?.id ?? null, () => runFacts(req, planned, outputKind(planned.op, planned.model))), ...(gate.steps && { steps: pricedSteps(gate.steps) }) };
const queue = queueFacts(account?.id ?? null, planned.route.endpoint);
let q = await billingQuote(account ? accountFacts(account) : null, facts, queue);
// The policy's limits on this account's runs here, as the run would meet them (pool-limits.ts): said before Run.
diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.ts
index 15ad6758..c98756dd 100644
--- a/tests/pool-limits.test.ts
+++ b/tests/pool-limits.test.ts
@@ -557,6 +557,35 @@ describe("a run's price facts", () => {
expect(hosted.requestMegapixels({ ...IMAGE, params: { extra: { width: 1280, height: 720 } } } as never, "image", IMAGE.modelId, endpoint)).toBe(0.92);
});
+ it("a price check reads the size of the viewer's own files only: another account's file, or a guest's look at one, says nothing of it", async () => {
+ withBilling({ limits: { activeRuns: 0, waiting: 0, runsPerHour: 0 } });
+ const a = account();
+ const b = account();
+ const sharp = (await import("sharp")).default;
+ const big = await sharp({ create: { width: 2000, height: 1500, channels: 3, background: "#864" } })
+ .png()
+ .toBuffer();
+ const uploadsRoute = await import("@/app/api/uploads/route");
+ const up = await uploadsRoute.POST(
+ new Request(`http://${HOST}/api/uploads`, { method: "POST", headers: { ...SITE_HEADERS, cookie: a.cookie, "content-type": "image/png", "x-file-name": "mine.png", "content-length": String(big.length) }, body: new Uint8Array(big) }),
+ );
+ expect(up.status).toBe(201);
+ const { url } = (await up.json()) as { url: string };
+ const upscale = { feature: "image", modelId: "oss-seedvr2-image", op: "upscale-image", inputs: { images: [url] } };
+ const quoted = () => (fake.calls_of("/v1/quote").at(-1)!.body as { run: { megapixels: number | null } }).run.megapixels;
+ // Its owner's price check: the size its run makes.
+ await preview(upscale, a.cookie);
+ expect(quoted()).toBe(12.48);
+ // Another account's, and a guest's: as if there were no such file.
+ const before = fake.calls_of("/v1/quote").length;
+ await preview(upscale, b.cookie);
+ expect(fake.calls_of("/v1/quote").length).toBe(before + 1);
+ expect(quoted()).toBeNull();
+ await preview(upscale, "");
+ expect(fake.calls_of("/v1/quote").length).toBe(before + 2);
+ expect(quoted()).toBeNull();
+ });
+
it("under the policy's cap on outputs, the price check and the run plan, price and make the same run", async () => {
withBilling({ limits: { activeRuns: 0, waiting: 0, runsPerHour: 0, outputsPerRun: 1 } });
const a = account();