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.

Runs waiting for the billing service show in the admin log; a run started after sign-up says it is on its way

Adarsh17ae8114605d
diff --git a/docs/admin-api.md b/docs/admin-api.md
index a257ebfd..4ca9ef9c 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -130,9 +130,11 @@ the values before and after), `token.create`, `token.revoke`,
every 10 minutes); reads of accounts' content by a token or the owner: `runs.content` (one row per reader and account
every 10 minutes, the account as its target) and `file.view` (one row per reader and file every hour); refusals
`scope.denied` and `rate.limited`; and the studio's own alerts `worker.alert` (actor `system`: a worker's token used
-from a new country, a new network, or two networks at once; [gpu-workers.md](gpu-workers.md#the-protocol)). The
-owner's other reads in the browser aren't logged. Rows go after a year. `actor` can be `system`, and the `actor` filter
-takes it.
+from a new country, a new network, or two networks at once; [gpu-workers.md](gpu-workers.md#the-protocol)) and
+`runs.waiting` (actor `system`, at most once every 5 minutes: runs on this install's GPUs that have waited longer than
+5 minutes for the billing or moderation service to answer, as counts only: `waiting`, `billing`, `moderation`,
+`oldestMin`). The owner's other reads in the browser aren't logged. Rows go after a year. `actor` can be `system`, and
+the `actor` filter takes it.
A row is written once the change is made. If the server can't write it (a full disk, say), the change still stands and
the server's own log notes the missing row.
diff --git a/docs/billing-hook.md b/docs/billing-hook.md
index 25604b10..6a1954f3 100644
--- a/docs/billing-hook.md
+++ b/docs/billing-hook.md
@@ -318,7 +318,7 @@ seconds. A stop that comes after the result was saved leaves the run saved, so i
|---|---|
| No `FUOBE_BILLING_URL` | No call. Runs on this install's GPUs are closed, or free and allowed with `FUOBE_HOSTED_FREE=1`. |
| Set, and it answers | As above. |
-| Set, no answer in time, and the policy has `limits.held` | The reserve is tried for up to 5 seconds. Then the run is made all the same and its tile shows "In line" at its place, with no card and no toast; it reserves under its press's own request id (so the service makes one hold for it) once the service answers (tried again after 1 s, doubling to 30 s, and at once after the service answers any call), and enters at its press-time place. A refusal then ends the run in one plain sentence. Before Run, the price slot shows the last price the service gave for that run (kept 10 minutes), else nothing, and Run stays on. While the service answers `paused`, its words are the line before Run and a press waits the same way. A moderation service that doesn't answer at a studio's press is handled the same way: the run is checked before it enters the line. Runs waiting longer than 5 minutes are said in the server log. |
+| Set, no answer in time, and the policy has `limits.held` | The reserve is tried for up to 5 seconds. Then the run is made all the same and its tile shows "In line" at its place, with no card and no toast; it reserves under its press's own request id (so the service makes one hold for it) once the service answers (tried again after 1 s, doubling to 30 s, and at once after the service answers any call), and enters at its press-time place. A refusal then ends the run in one plain sentence. Before Run, the price slot shows the last price the service gave for that run (kept 10 minutes), else nothing, and Run stays on. While the service answers `paused`, its words are the line before Run and a press waits the same way. A moderation service that doesn't answer at a studio's press is handled the same way: the run is checked before it enters the line. Runs waiting longer than 5 minutes are said in the server log and, at most once every 5 minutes, in the admin log (`runs.waiting`, counts only). |
| Set, and no answer in time (no `limits.held`) | A press of Run waits while the reserve is tried again for up to 40 seconds (a restart of the service), and the feed shows the run as "In line" meanwhile. Then the run is made with its place in line. Past that, the run is refused (503, "Try again in a moment.") and nothing is made. The last policy stands for 10 minutes (above). Before Run, the price slot says "Ready in a moment" and Run is off; the price check asks again by itself, and Run comes back on with its answer. Runs on the account's own GPU or key go on. Reports wait in the outbox and are sent when it is back. Runs that already have a hold keep running. |
The service's address and its errors are written to the server's log only. A browser never sees them.
diff --git a/docs/public-signup.md b/docs/public-signup.md
index 17a72b50..e4411e4c 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -735,8 +735,9 @@ With it on:
processes at once. Cancel works on a held run like on any other. A deleted account's holds go with it. Only a press
past the cap on runs waiting is turned down: "You have 10 runs on the way. Add more when one is done." The owner
reads the held runs by why they wait (counts only) in Settings → Workers ("Waiting to enter the line: 3 (oldest 12
- min)") and in `GET /api/admin/queue` and `/api/admin/workers` (`held`). Runs waiting for the billing service longer
- than 5 minutes are said in the server log. With a policy that has no `limits.held` (an older service), every limit
+ min)") and in `GET /api/admin/queue` and `/api/admin/workers` (`held`). Runs waiting longer than 5 minutes for the
+ billing or moderation service to answer are said in the server log and, at most once every 5 minutes, in the admin
+ log (`runs.waiting`, counts only). With a policy that has no `limits.held` (an older service), every limit
refuses as before.
- The account's usual limits apply: outputs per run and its space. Its runs at once (4) and per hour (60) count its
runs on its own GPU or key and its light work (a join, a trim) only: its other runs on this install's GPUs meet the
diff --git a/src/components/admin-tokens.tsx b/src/components/admin-tokens.tsx
index 70297c51..c0ff0aef 100644
--- a/src/components/admin-tokens.tsx
+++ b/src/components/admin-tokens.tsx
@@ -75,6 +75,7 @@ const ACTION_WORDS: Record<string, string> = {
"worker.revoke": "Revoked a worker",
"worker.revoke_all": "Revoked every worker",
"worker.alert": "A worker's token was used from somewhere new",
+ "runs.waiting": "Runs waited over 5 minutes for the billing or moderation service",
"queue.settings": "Changed the queue's settings",
"settings.comfy_where": "Changed where ComfyUI runs",
"runs.content": "Read an account's prompts and results",
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index f6f55d83..f0232e7a 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -30,7 +30,7 @@ import { controlSetup, keyOnlySetup } from "@/lib/own-setup-controls";
import { ownSetupDetail, ownSetupLabel, ownSetupShort } from "@/lib/own-setup";
import { OwnSetupChip, useOwnSetupPress, useOwnSetupViewer } from "@/components/own-setup";
import { HoldFilesCtx } from "@/lib/held-files";
-import { pendingStep } from "@/lib/guest-draft";
+import { PENDING_WORDS, pendingStep } from "@/lib/guest-draft";
import { useGuestDraft } from "./guest-draft";
import { ExactOrbitControls } from "@/components/exact-orbit-controls";
import { useFlyAround } from "@/components/fly-around-run";
@@ -911,8 +911,9 @@ export function Composer({ docked }: { docked: boolean }) {
// `skip` is true only from the guided fix's "Run anyway" (a click handler passes its event here). `withKey`: this run
// only, on the cloud version that action names and the account's key (hosted runs on; see onRunWithKey). `once`: a
- // place for this run only (hosted runs: "Run on Our GPUs", or the account's GPU for what only it runs).
- const submit = (skip?: unknown, withKey?: TroubleAction, once?: "own" | "pool"): void => {
+ // place for this run only (hosted runs: "Run on Our GPUs", or the account's GPU for what only it runs). `signedUp`: the
+ // run a guest pressed, started by itself back from sign-up (its note says so once the run is made).
+ const submit = (skip?: unknown, withKey?: TroubleAction, once?: "own" | "pool", signedUp?: boolean): void => {
const skipGpu = skip === true;
setKeyChoice(false);
if (exact) {
@@ -988,8 +989,12 @@ export function Composer({ docked }: { docked: boolean }) {
const onKey = withKey ? onCloudKey(withVoiceFirst, withKey) : withVoiceFirst;
const body = { ...onKey, ...hosted, ...(skipGpu && { gpuCheck: "skip" }) } as typeof sent.request;
create.mutate(body, {
- // Accepted: nothing to try again (a card opened later never starts this run a second time).
- onSuccess: () => dropGpuRetry(),
+ // Accepted: nothing to try again (a card opened later never starts this run a second time). Back from sign-up, the
+ // line says the run is on its way (hosted runs: its tile shows "In line" too).
+ onSuccess: () => {
+ dropGpuRetry();
+ if (signedUp && viewerInfo?.hosted) setPriceNote(PENDING_WORDS.made);
+ },
// Stopped by the GPU pre-flight, or refused with its own card: the guided fix or the card is open already, so no error toast on top.
onError: (e) => void ((e as { gpuSetup?: boolean }).gpuSetup || toastError(e)),
});
@@ -1218,10 +1223,10 @@ export function Composer({ docked }: { docked: boolean }) {
const next = pendingStep({ settled: !settling && priceSettled, blocked: !!blocker, pool: poolPrice, shown: pendingRun.shown, quote: hostedQuote, lost: keptLost, same: pendingRun.same });
if (next === "wait") return;
clearPending();
- if (next === "start") submitRef.current();
- else if (next === "lost") setPriceNote("Add your file again, then press Generate.");
- else if (next === "ask") setPriceNote("Your draft is back. Press Generate to start.");
- else if (next === "note" && hostedQuote) setPriceNote(`The price is now ${hostedQuote.text}. Press Generate to start.`);
+ if (next === "start") submitRef.current(undefined, undefined, undefined, true);
+ else if (next === "lost") setPriceNote(PENDING_WORDS.lost);
+ else if (next === "ask") setPriceNote(PENDING_WORDS.ask);
+ else if (next === "note" && hostedQuote) setPriceNote(PENDING_WORDS.note(hostedQuote.text));
}, [pendingRun, clearPending, settling, priceSettled, blocker, poolPrice, hostedQuote, keptLost]);
const blockedSlot = blocker?.slot;
useEffect(() => {
diff --git a/src/lib/guest-draft.ts b/src/lib/guest-draft.ts
index 7e7b4c23..f9d59cb4 100644
--- a/src/lib/guest-draft.ts
+++ b/src/lib/guest-draft.ts
@@ -192,6 +192,17 @@ export function restoredPrompt(link: string, saved: string, pressed: boolean): s
return pressed ? saved : link || saved;
}
+/**
+ * The line under the toolbar once back from sign-up, by what the run the guest pressed did (pendingStep): `made` only
+ * once its run was really made; the others while Run waits for a click.
+ */
+export const PENDING_WORDS = {
+ made: "You're in. Your run is on its way.",
+ lost: "Add your file again, then press Generate.",
+ ask: "Your draft is back. Press Generate to start.",
+ note: (price: string) => `The price is now ${price}. Press Generate to start.`,
+};
+
/**
* What the run a guest pressed does once back as an account:
* - lost: one of its kept files didn't come back (gone from the browser, or its upload refused): it never starts without
diff --git a/src/server/pool-release.ts b/src/server/pool-release.ts
index c1d944b4..453eb042 100644
--- a/src/server/pool-release.ts
+++ b/src/server/pool-release.ts
@@ -37,17 +37,41 @@ export const holdBackoffMs = (tries: number): number => Math.min(30_000, 1000 *
/** After how long runs waiting for the billing service are said in the owner's log (the service can't say so itself). */
export const SERVICE_WAIT_SAID_MS = 5 * 60_000;
+/** The admin log's action for runs that wait for the billing or moderation service to answer (actor "system"). */
+export const SERVICE_WAIT_ACTION = "runs.waiting";
+
declare global {
var __fuobeHoldServiceSaid: number | undefined;
}
-/** The owner's log, at most every SERVICE_WAIT_SAID_MS: how many runs wait for the billing service (counts only). */
+/**
+ * The owner's logs, at most every SERVICE_WAIT_SAID_MS: how many runs have waited longer than that for the billing or
+ * moderation service to answer (counts only: no prompt, no account). The server log says it from each app process; the
+ * admin log keeps one row (SERVICE_WAIT_ACTION) for all of them. A run waiting for a time (free generations that renew)
+ * counts from that time, and one waiting because the service said runs are paused (the owner's own switch) doesn't count.
+ */
function sayServiceWait(heads: HoldRow[], now: number): void {
- const long = heads.filter((h) => (!h.reserved || !h.checked) && now - h.pressed_at > SERVICE_WAIT_SAID_MS);
+ const since = (h: HoldRow) => Math.max(h.pressed_at, h.start_at ?? 0);
+ const long = heads.filter((h) => (!h.reserved || !h.checked) && !h.paused && now - since(h) > SERVICE_WAIT_SAID_MS);
if (!long.length || now - (globalThis.__fuobeHoldServiceSaid ?? 0) < SERVICE_WAIT_SAID_MS) return;
globalThis.__fuobeHoldServiceSaid = now;
- const oldest = Math.round((now - Math.min(...long.map((h) => h.pressed_at))) / 60_000);
- console.warn(`[fuobe] runs waiting for the billing service: ${long.length} (oldest ${oldest} min)`);
+ const oldest = Math.round((now - Math.min(...long.map(since))) / 60_000);
+ const billing = long.filter((h) => !h.reserved).length;
+ const moderation = long.filter((h) => !h.checked).length;
+ console.warn(`[fuobe] runs waiting for the billing or moderation service: ${long.length} (oldest ${oldest} min)`);
+ try {
+ const d = db();
+ const said = d.prepare("SELECT 1 FROM admin_audit WHERE action = ? AND at > ? LIMIT 1").get(SERVICE_WAIT_ACTION, now - SERVICE_WAIT_SAID_MS);
+ if (!said) {
+ d.prepare("INSERT INTO admin_audit (at, actor, token_id, token_name, action, target, detail_json, status) VALUES (?, 'system', NULL, NULL, ?, NULL, ?, 200)").run(
+ now,
+ SERVICE_WAIT_ACTION,
+ JSON.stringify({ waiting: long.length, billing, moderation, oldestMin: oldest }),
+ );
+ }
+ } catch (e) {
+ console.warn(`[fuobe] Couldn't write the admin log: ${(e as Error).message}`);
+ }
}
/**
diff --git a/tests/hosted-guest-draft.test.ts b/tests/hosted-guest-draft.test.ts
index e76748c2..82703e0e 100644
--- a/tests/hosted-guest-draft.test.ts
+++ b/tests/hosted-guest-draft.test.ts
@@ -141,6 +141,16 @@ describe("the run a guest pressed", () => {
expect(step({ shown: null, quote: { allowed: true, amount: 0, text: "" } })).toBe("none");
});
+ it("says in plain words what happened to it: on its way once made, or what Run waits for", () => {
+ expect(draftLib.PENDING_WORDS.made).toBe("You're in. Your run is on its way.");
+ expect(draftLib.PENDING_WORDS.lost).toBe("Add your file again, then press Generate.");
+ expect(draftLib.PENDING_WORDS.ask).toBe("Your draft is back. Press Generate to start.");
+ expect(draftLib.PENDING_WORDS.note("Free")).toBe("The price is now Free. Press Generate to start.");
+ // The composer says "on its way" only from the made run's answer, never at the start step itself.
+ const composer = fs.readFileSync(path.join(process.cwd(), "src/components/studio/composer.tsx"), "utf8");
+ expect(composer).toMatch(/onSuccess: \(\) => \{[^}]*signedUp && viewerInfo\?\.hosted\) setPriceNote\(PENDING_WORDS\.made\)/);
+ });
+
it("never starts without a kept file that didn't come back, even in a slot the run could do without", () => {
// When every run costs the same ("Free") and a reference photo or start frame is optional, only the lost file
// stops it, and the person is asked to add it again.
diff --git a/tests/pool-holds.test.ts b/tests/pool-holds.test.ts
index 259ada04..5288a2c2 100644
--- a/tests/pool-holds.test.ts
+++ b/tests/pool-holds.test.ts
@@ -434,6 +434,45 @@ describe("service blips (H3)", () => {
}
});
+ it("the owner's admin log says when runs have waited over 5 minutes for the service (counts only, one row for every app process); a wait for a time or a pause doesn't count", async () => {
+ const was = { ...billing.RESERVE_INLINE };
+ try {
+ billing.RESERVE_INLINE.ms = 100;
+ db().prepare("DELETE FROM admin_audit WHERE action = ?").run(release.SERVICE_WAIT_ACTION);
+ const said = () => db().prepare("SELECT actor, target, detail_json FROM admin_audit WHERE action = ?").all(release.SERVICE_WAIT_ACTION) as { actor: string; target: string | null; detail_json: string }[];
+ const a = account();
+ await check(a.cookie);
+ fake.down = "error";
+ const r = await press(a.cookie);
+ expect(r.body.held).toEqual({ reason: "service" });
+ const run = heldOf(idOf(r))!.run_id;
+ // Pressed six minutes ago, but waiting for a time (free generations that renew in an hour): not a quiet service.
+ db().prepare("UPDATE pool_holds SET pressed_at = ?, start_at = ? WHERE run_id = ?").run(Date.now() - 6 * 60_000, Date.now() + 60 * 60_000, run);
+ globalThis.__fuobeHoldServiceSaid = undefined;
+ await release.releaseHeldRuns();
+ expect(said()).toEqual([]);
+ // Waiting because the service said runs are paused (the owner's own switch): not counted either.
+ db().prepare("UPDATE pool_holds SET start_at = NULL, paused = 1 WHERE run_id = ?").run(run);
+ await release.releaseHeldRuns();
+ expect(said()).toEqual([]);
+ // Six minutes with no answer from the billing service: one row, counts only.
+ db().prepare("UPDATE pool_holds SET paused = 0, next_at = NULL WHERE run_id = ?").run(run);
+ await release.releaseHeldRuns();
+ const rows = said();
+ expect(rows).toHaveLength(1);
+ expect(rows[0]).toMatchObject({ actor: "system", target: null });
+ expect(JSON.parse(rows[0].detail_json)).toEqual({ waiting: 1, billing: 1, moderation: 0, oldestMin: 6 });
+ expect(rows[0].detail_json).not.toContain(a.id);
+ expect(rows[0].detail_json).not.toContain(IMAGE.prompt);
+ // A second app process says it in its own server log, but the admin log keeps the one row.
+ globalThis.__fuobeHoldServiceSaid = undefined;
+ await release.releaseHeldRuns();
+ expect(said()).toHaveLength(1);
+ } finally {
+ Object.assign(billing.RESERVE_INLINE, was);
+ }
+ });
+
it("H3p: while the service says runs here are paused, a press is taken and waits ('starts when a GPU is free')", async () => {
fake.refuse = { code: "paused", text: "Runs on our GPUs are paused for now. Your own GPU or key still works." };
const a = account();