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: stopping a run marks a step that just stopped with it as stopped, not failed

Adarshfc3a6f041fbf
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 74fd6d7c..3fa88b4d 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -5341,6 +5341,11 @@ async function persistOutput(o: RichOutput, generationId: string, pre?: { linked
export async function cancelGeneration(id: string): Promise<void> {
const r = db().prepare("SELECT * FROM generations WHERE id = ?").get(id) as Row | undefined;
+ if (r && stoppedJustAfterItsInput(r)) {
+ const now = Date.now();
+ db().prepare("UPDATE generations SET status = 'canceled', error = NULL, message = NULL, updated_at = ? WHERE id = ? AND status = 'failed' AND external_id IS NULL").run(now, id);
+ return;
+ }
if (!r || (r.status !== "queued" && r.status !== "running")) return;
// Its outputs are in and the 3D finish runs: the provider's job is over. Stop the finish before anything
// awaits, so it can't mark the job done in between.
@@ -5377,6 +5382,19 @@ export async function cancelGeneration(id: string): Promise<void> {
dropUnused(depIds(r.depends_on));
}
+/**
+ * A waiting step that was marked failed a moment ago only because the step it waited for was stopped: a person's Stop
+ * on a whole run reaches its steps one by one, and the sweep can fail the later step in between. Stopping it then makes
+ * it stopped, as the person asked, instead of failed. A step that ran, or failed on its own, stays as it is.
+ */
+function stoppedJustAfterItsInput(r: Row): boolean {
+ if (r.status !== "failed" || r.external_id || !r.depends_on || !WAITED_ON_FAILURE.has(r.error ?? "")) return false;
+ if (Date.now() - (r.completed_at ?? 0) > 10 * 60_000) return false;
+ const ids = depIds(r.depends_on);
+ const status = db().prepare("SELECT status FROM generations WHERE id = ?");
+ return ids.length > 0 && ids.every((d) => (status.get(d) as { status: string } | undefined)?.status === "canceled");
+}
+
/**
* End a run as canceled, only while it still goes (queued or running: a run held for its output check too). A run that
* was saved, failed or canceled since the cancel looked at it stays as it is, with its result and its report. A save
diff --git a/tests/chain-fanout.test.ts b/tests/chain-fanout.test.ts
index 91bff526..1429198c 100644
--- a/tests/chain-fanout.test.ts
+++ b/tests/chain-fanout.test.ts
@@ -208,6 +208,23 @@ describe("fan-out and fan-in in createPipeline", () => {
for (const w of waiting) expect(await settle(w.id, 20_000)).toMatchObject({ status: "failed", error: "An earlier step didn't finish" });
});
+ it("a person's Stop on a run makes a step already failed by the stop before it stopped, not failed", async () => {
+ const hold = held();
+ const next = gens.createGenerations({ feature: "t", modelId: "nano-banana-2", op: "edit", prompt: "Ink" }, { dependsOn: hold.id })[0];
+ // The Stop reaches the first step; the sweep fails the waiting one before the Stop reaches it too.
+ db().prepare("UPDATE generations SET status = 'canceled', completed_at = ? WHERE id = ?").run(Date.now(), hold.id);
+ expect(await settle(next.id, 20_000)).toMatchObject({ status: "failed", error: "An earlier step didn't finish" });
+ await gens.cancelGeneration(next.id);
+ expect(row(next.id)).toMatchObject({ status: "canceled", error: null });
+ // A step that failed because its input failed stays failed.
+ const other = held();
+ const after = gens.createGenerations({ feature: "t", modelId: "nano-banana-2", op: "edit", prompt: "Ink" }, { dependsOn: other.id })[0];
+ other.fail();
+ expect(await settle(after.id, 20_000)).toMatchObject({ status: "failed" });
+ await gens.cancelGeneration(after.id);
+ expect(row(after.id)).toMatchObject({ status: "failed", error: "An earlier step didn't finish" });
+ });
+
it("chains a pipeline's steps onto generations made before (a retry's kept steps)", () => {
const hold = held();
expect(() => createPipeline([{ key: "x", request: { feature: "t", modelId: "nano-banana-2", op: "edit", prompt: "Ink" }, after: "nope" }], { existing: { hold: hold.id } })).toThrow(/waits for “nope”, which isn't in the pipeline/);