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: the feed shows "In line" while a run on the studio's GPUs is being made

Adarsh19f39ebdabc3
diff --git a/docs/billing-hook.md b/docs/billing-hook.md
index 66caa080..f951cfae 100644
--- a/docs/billing-hook.md
+++ b/docs/billing-hook.md
@@ -204,6 +204,6 @@ process saves a finished run's results.
|---|---|
| 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, and no answer in time | A press of Run waits while the reserve is tried again for up to 60 seconds (a restart of the service), 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. |
+| Set, and no answer in time | A press of Run waits while the reserve is tried again for up to 60 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/src/components/studio/feed.tsx b/src/components/studio/feed.tsx
index 8acb3512..396db37d 100644
--- a/src/components/studio/feed.tsx
+++ b/src/components/studio/feed.tsx
@@ -18,7 +18,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { OPERATION_LABELS, type Generation } from "@/lib/catalog/types";
-import { useCreateGeneration, useGenerationActions, useStatus } from "@/lib/api";
+import { useCreateGeneration, useGenerationActions, useMakingPoolRuns, useStatus } from "@/lib/api";
import { placeholdersOn } from "@/lib/demo-mode";
import { useSoulFinish } from "./soul-finish";
import { elapsed, formatCost, leftLabel, notePace, ratioValue, timeAgo, timeLeft } from "@/lib/format";
@@ -47,6 +47,26 @@ export function tileRatio(g: Generation): number {
return ratioValue(ar && ar !== "auto" ? ar : undefined, g.kind === "video" ? 16 / 9 : 1);
}
+/**
+ * A run on this studio's GPUs between Run and its answer (the run is being made: a moment, or longer while the billing
+ * service is tried again): "In line", as the run's own tile says once it is made. It shows only after a moment, so a
+ * quick answer goes straight to the run's tile.
+ */
+export function MakingTile({ ratio }: { ratio: number }) {
+ return (
+ <div
+ className="relative h-full max-w-full animate-pending-in overflow-hidden rounded-xl bg-muted"
+ style={{ aspectRatio: ratio, animationDelay: "800ms" }}
+ data-run-state="in-line"
+ >
+ <div className="skeleton-sweep absolute inset-0 animate-skeleton" />
+ <div className="absolute inset-x-0 bottom-0 p-3">
+ <p className="shimmer-text animate-shimmer-text text-[13px] font-medium">{POOL_WORDS.inLine}</p>
+ </div>
+ </div>
+ );
+}
+
export function PendingTile({ g, ratio }: { g: Generation; ratio: number }) {
const { cancel } = useGenerationActions();
// The clock runs between the job's reports (a fal queue or Higgsfield may report rarely).
@@ -463,6 +483,7 @@ export function Feed({
}) {
const [open, setOpen] = useState<{ id: string; index: number } | null>(null);
const create = useCreateGeneration();
+ const making = useMakingPoolRuns();
// Fuobe Soul results get their look's grade and overlay here, once.
useSoulFinish(items);
// Groups get stable callbacks that read the latest props through refs.
@@ -485,7 +506,16 @@ export function Feed({
}),
[openAt, hasReuse, aiTag],
);
- if (!items.length) return <>{empty}</>;
+ // Runs on this studio's GPUs being made now: newest first, above the runs already made.
+ const makingTiles = [...making].reverse().map((m, i) => {
+ const ar = m.request.params?.aspectRatio;
+ return (
+ <div key={`making-${m.at}-${i}`} className="h-56 max-w-full sm:h-64">
+ <MakingTile ratio={ratioValue(ar && ar !== "auto" ? ar : undefined, 1)} />
+ </div>
+ );
+ });
+ if (!items.length) return makingTiles.length ? <div className="flex flex-wrap gap-2">{makingTiles}</div> : <>{empty}</>;
// The feed is newest first: the next steps go under the first finished result.
const newest = items.find((g) => g.status === "succeeded")?.id;
const flat = items.flatMap((g) => (g.status === "succeeded" ? (isLayered(g) ? [{ g, i: 0 }] : shownOutputs(g).map((i) => ({ g, i }))) : []));
@@ -493,6 +523,7 @@ export function Feed({
return (
<FeedCtx.Provider value={api}>
<div className="space-y-9">
+ {makingTiles.length > 0 && <div className="flex flex-wrap gap-2">{makingTiles}</div>}
{items.map((g, i) => (
<GenerationGroup key={g.id} g={g} newest={g.id === newest} first={i === 0} />
))}
diff --git a/src/lib/api.ts b/src/lib/api.ts
index 74682e1d..03559ac3 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1,6 +1,6 @@
"use client";
-import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient, type QueryClient } from "@tanstack/react-query";
+import { keepPreviousData, useInfiniteQuery, useMutation, useMutationState, useQuery, useQueryClient, type QueryClient } from "@tanstack/react-query";
import { useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
import { toast } from "sonner";
import type { AssistThread, AssistThreadSummary, AssistThreadView } from "./assist";
@@ -517,9 +517,33 @@ export function useLibraryFacets(opts: { steps?: boolean } = {}) {
});
}
+/** The new runs being made (useCreateGeneration), as the mutation cache knows them. */
+export const CREATE_GENERATION_KEY = ["create-generation"] as const;
+
+/**
+ * Does this new run go to this studio's GPUs (hosted runs)? The composer names the place, or sends the price it showed
+ * for a run there. Other runs (an install's own GPU, a cloud key) say neither.
+ */
+export function goesToPool(req: GenerationRequest | undefined): boolean {
+ return !!req && (req.place === "pool" || "shown" in req);
+}
+
+/**
+ * The runs on this studio's GPUs being made now (Run pressed, no answer yet), with when Run was pressed. The feed shows
+ * each one as "In line" until the run is made, so a short wait before it starts never looks like nothing happened.
+ */
+export function useMakingPoolRuns(): { at: number; request: GenerationRequest }[] {
+ const pending = useMutationState({
+ filters: { mutationKey: CREATE_GENERATION_KEY, status: "pending" },
+ select: (m) => ({ at: m.state.submittedAt, request: m.state.variables as GenerationRequest | undefined }),
+ });
+ return pending.filter((p): p is { at: number; request: GenerationRequest } => goesToPool(p.request));
+}
+
export function useCreateGeneration() {
const qc = useQueryClient();
return useMutation({
+ mutationKey: CREATE_GENERATION_KEY,
mutationFn: async (req: GenerationRequest) => {
const res = await fetch("/api/generations", {
method: "POST",
diff --git a/tests/hosted-run-tiles.test.ts b/tests/hosted-run-tiles.test.ts
index 04f721db..26598fed 100644
--- a/tests/hosted-run-tiles.test.ts
+++ b/tests/hosted-run-tiles.test.ts
@@ -17,7 +17,8 @@ vi.mock("next/navigation", () => ({
}));
const { POOL_WORDS } = await import("@/lib/relay");
-const { PendingTile, FailedTile } = await import("@/components/studio/feed");
+const { PendingTile, FailedTile, Feed } = await import("@/components/studio/feed");
+const { CREATE_GENERATION_KEY, goesToPool } = await import("@/lib/api");
const { AiTag } = await import("@/components/studio/ai-tag");
const { TooltipProvider } = await import("@/components/ui/tooltip");
@@ -105,3 +106,37 @@ describe("a run's tile on this studio's GPUs", () => {
});
});
+
+describe("a run on this studio's GPUs between Run and its answer", () => {
+
+ /** A feed whose page pressed Run with these requests and has no answer yet (the run is still being made). */
+ const feedWhileMaking = (requests: object[], items: Generation[] = []) => {
+ const client = new QueryClient();
+ for (const r of requests) {
+ const m = client.getMutationCache().build(client, { mutationKey: CREATE_GENERATION_KEY, mutationFn: () => new Promise(() => {}) });
+ void m.execute(r);
+ }
+ return renderToStaticMarkup(
+ createElement(QueryClientProvider, { client }, createElement(TooltipProvider, null, createElement(Feed, { items, empty: createElement("p", null, "Nothing yet") }))),
+ );
+ };
+
+ it("shows In line while the run is made (a wait for the billing service included), with no other words", () => {
+ const html = feedWhileMaking([{ feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox", place: "pool", params: { aspectRatio: "16:9" } }]);
+ expect(html).toContain('data-run-state="in-line"');
+ expect(html).toContain(`>${POOL_WORDS.inLine}<`);
+ expect(html).not.toContain("Nothing yet");
+ expect(html).not.toMatch(/pause|error|billing|GPU/i);
+ });
+ it("a run that names no place but sends the price it showed goes there too, above the runs already made", () => {
+ const html = feedWhileMaking([{ feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox", shown: { amount: 0, priceVersion: "" } }], [gen({ place: "pool", status: "running", message: POOL_WORDS.working })]);
+ expect(html.indexOf('data-run-state="in-line"')).toBeGreaterThan(-1);
+ expect(html.indexOf('data-run-state="in-line"')).toBeLessThan(html.indexOf('data-run-state="working"'));
+ });
+ it("every other run being made shows nothing new", () => {
+ const html = feedWhileMaking([{ feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox" }, { feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox", place: "own" }]);
+ expect(html).not.toContain("data-run-state");
+ expect(html).toContain("Nothing yet");
+ expect(goesToPool(undefined)).toBe(false);
+ });
+});