Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Cancel only downstream generations

Bitti54e5f5623a63
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 0c78016..25b12bb 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -7,7 +7,7 @@ Changes since 0.3.2.
- **Image generators:** MOSS Image, Fibo 2.0 Base/Edit Turbo, and Krea 2 Turbo/Raw, with model-specific guidance, negative prompts and editing controls.
- **Music:** YuE2 and MiniMax Music3 generation, folders, drafts, continuous playback and timeline audio. Export WAV, MP3, FLAC, AAC/M4A or Opus/WebM/Ogg.
- **Album covers:** Generate artwork from a song’s context menu using a dedicated generator selected under Settings → Generators → Icons.
-- **Video library:** Organize Videos → Scenes → Shots, play scenes together, split songs into scenes, and share prompts and timed references. Videos can override project Look and resolution settings, and dependent scenes can be queued together.
+- **Video library:** Organize Videos → Scenes → Shots, play scenes together, split songs into scenes, and share prompts and timed references. Videos can override project Look and resolution settings, and dependent scenes can be queued together. Cancelling a generation also cancels its downstream dependents while preserving earlier generations.
- **Scene takes:** Keep up to four takes plus a draft, restore settings, choose the primary take, and upscale saved takes by 1.5×, 2× or 4×. Non-primary takes can be removed during generation.
- **Single Shot:** Continue with Context and Previous video anchors, optional generated endings, improved overlap joining and consistent Tone. Use Bridge for new connections instead of Long Shot.
- **Motions and agents:** Create editable JavaScript animations for the timeline or references. Agents can inspect media frames, generate music and sync Motions to audio.
diff --git a/src/lib/agentGeneration.ts b/src/lib/agentGeneration.ts
index 2eba489..fd9e14e 100644
--- a/src/lib/agentGeneration.ts
+++ b/src/lib/agentGeneration.ts
@@ -139,7 +139,7 @@ export async function generateAgentScene(queue: WorkQueue, session: ProjectSessi
const request = sceneGenerationRequest(job, config, session.record.folderPath, template.defaultSteps, template);
const [id] = queue.enqueue(session, [{ job, request, snapshot: sceneGenerationSnapshot(job, request) }], template);
if (!id) throw new Error("This scene is already queued.");
- // Stop cancels this run and its linked generation group. Encoding already in
+ // Stop cancels this run and its downstream dependents. Encoding already in
// progress is allowed to finish safely, but the stopped agent will not resume.
const cancel = () => { void queue.cancel(id).catch(() => undefined); };
signal.addEventListener("abort", cancel, { once: true });
diff --git a/src/lib/workQueue.test.ts b/src/lib/workQueue.test.ts
index 3aaa028..86a1679 100644
--- a/src/lib/workQueue.test.ts
+++ b/src/lib/workQueue.test.ts
@@ -502,25 +502,33 @@ it("rejects a queued final Long Shot continuation when a following anchor is add
expect(queue.getSnapshot().find((item) => item.id === ids[1])?.error).toContain("neighbors changed");
});
-it.each(["source", "child", "grandchild", "branch"])("cancelling %s cancels its queued dependency group without touching unrelated work", async (cancelScene) => {
+it.each([
+ ["source", ["source", "child", "grandchild", "branch"]],
+ ["child", ["child", "grandchild"]],
+ ["grandchild", ["grandchild"]],
+ ["branch", ["branch"]],
+])("cancelling %s cancels only it and its queued dependents", async (cancelScene, cancelledScenes) => {
const { queue, first, second } = setup();
queue.enqueue(second, [submission(second)]);
first.update((config) => ({ ...config, generationJobs: ["source", "child", "grandchild", "branch", "unrelated"].map((id) => ({ ...config.generationJobs[0], id })) }));
const enqueue = (id: string, previousSceneId?: string) => queue.enqueue(first, [{ ...submission(first),
- job: first.getSnapshot().config.generationJobs.find((job) => job.id === id)!, request: { ...submission(first).request, previousSceneId } }])[0];
+ job: first.getSnapshot().config.generationJobs.find((job) => job.id === id)!, request: { ...submission(first).request,
+ ...(id === "branch" ? { contextSceneId: previousSceneId } : { previousSceneId }) } }])[0];
const ids = [enqueue("source"), enqueue("child", "source"), enqueue("grandchild", "child"), enqueue("branch", "source")];
const unrelated = enqueue("unrelated");
await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
- // Editing the draft after submission must not change the captured group.
- first.update((config) => ({ ...config, generationJobs: [...config.generationJobs].reverse() }));
+ // Editing the draft after submission must not change captured dependencies.
+ first.update((config) => ({ ...config, generationJobs: [...config.generationJobs].reverse().map((job) => ({ ...job, previousSceneId: "unrelated" })) }));
await queue.cancel(queue.getSnapshot().find((item) => item.sceneId === cancelScene)!.id);
- expect(queue.getSnapshot().filter((item) => ids.includes(item.id)).map((item) => item.status)).toEqual(Array(4).fill("cancelled"));
+ for (const item of queue.getSnapshot().filter((item) => ids.includes(item.id))) {
+ expect(item.status).toBe(cancelledScenes.includes(item.sceneId) ? "cancelled" : "queued");
+ }
expect(queue.getSnapshot().find((item) => item.id === unrelated)?.status).toBe("queued");
expect(queue.getSnapshot()[0].status).toBe("generating");
expect(cancelSlopfabGeneration).not.toHaveBeenCalled();
});
-it("cancelling a dependent also stops its generating source", async () => {
+it.each(["source", "child"])("cancelling %s only stops the running source when it is selected", async (cancelScene) => {
const { queue, first } = setup();
const [sourceId] = queue.enqueue(first, [submission(first)]);
await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
@@ -528,15 +536,40 @@ it("cancelling a dependent also stops its generating source", async () => {
const child = { ...source.job, id: "child" };
first.update((config) => ({ ...config, generationJobs: [...config.generationJobs, child] }));
const [childId] = queue.enqueue(first, [{ ...source, job: child, request: { ...source.request, previousSceneId: source.job.id } }]);
- await queue.cancelScenes(first, [child.id]);
- expect(cancelSlopfabGeneration).toHaveBeenCalledWith(sourceId);
+ await queue.cancelScenes(first, [cancelScene === "source" ? source.job.id : child.id]);
expect(queue.getSnapshot().find((item) => item.id === childId)?.status).toBe("cancelled");
- emit("slopfab-job", { jobId: sourceId, state: "cancelled", detail: "Stopped" });
- await waitFor(() => expect(queue.getSnapshot().every((item) => item.status === "cancelled")).toBe(true));
+ expect(queue.getSnapshot().find((item) => item.id === sourceId)).toMatchObject({ status: "generating", cancelling: cancelScene === "source" });
+ if (cancelScene === "source") {
+ expect(cancelSlopfabGeneration).toHaveBeenCalledExactlyOnceWith(sourceId);
+ emit("slopfab-job", { jobId: sourceId, state: "cancelled", detail: "Stopped" });
+ await waitFor(() => expect(queue.getSnapshot().every((item) => item.status === "cancelled")).toBe(true));
+ } else {
+ expect(cancelSlopfabGeneration).not.toHaveBeenCalled();
+ await finish(queue, sourceId);
+ expect(first.getSnapshot().config.generationJobs[0].outputRelativePath).toBe("media/generated/result.mp4");
+ }
expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce();
});
-it("merges both Long Shot anchor groups when cancelling a bridge", async () => {
+it("finds downstream dependencies across a batch submitted in reverse order", async () => {
+ const { queue, first, second } = setup();
+ queue.enqueue(second, [submission(second)]);
+ first.update((config) => ({ ...config, generationJobs: ["source", "child", "grandchild"].map((id) => ({ ...config.generationJobs[0], id })) }));
+ const jobs = first.getSnapshot().config.generationJobs;
+ queue.enqueue(first, jobs.map((job, index) => ({ ...submission(first), job,
+ request: { ...submission(first).request, previousSceneId: jobs[index - 1]?.id } })).reverse());
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
+ await queue.cancelScenes(first, ["child"]);
+ expect(queue.getSnapshot().slice(1).map((item) => [item.sceneId, item.status])).toEqual([
+ ["grandchild", "cancelled"], ["child", "cancelled"], ["source", "queued"],
+ ]);
+});
+
+it.each([
+ ["bridge", ["queued", "queued", "cancelled"]],
+ ["left", ["cancelled", "queued", "cancelled"]],
+ ["right", ["queued", "cancelled", "cancelled"]],
+])("cancels Long Shot %s downstream without cancelling its other anchors", async (sceneId, statuses) => {
const { queue, first, second } = setup();
queue.enqueue(second, [submission(second)]);
first.update((config) => ({ ...config, generationJobs: ["left", "bridge", "right"].map((id) => ({ ...config.generationJobs[0], id, sceneType: "long-shot" as const })) }));
@@ -545,11 +578,12 @@ it("merges both Long Shot anchor groups when cancelling a bridge", async () => {
const job = config.generationJobs[index], request = sceneGenerationRequest(job, config, first.record.folderPath, 8);
queue.enqueue(first, [{ job, request, snapshot: sceneGenerationSnapshot(job, request) }]);
}
- await queue.cancelScenes(first, ["bridge"]);
- expect(queue.getSnapshot().slice(1).map((item) => item.status)).toEqual(["cancelled", "cancelled", "cancelled"]);
+ await waitFor(() => expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce());
+ await queue.cancelScenes(first, [sceneId]);
+ expect(queue.getSnapshot().slice(1).map((item) => item.status)).toEqual(statuses);
});
-it("cancels a source saving video safely when its queued dependent is cancelled", async () => {
+it.each(["source", "child"])("handles cancelling %s while the source video is being saved", async (cancelScene) => {
const { queue, first } = setup();
let encoded!: (saved: Awaited<ReturnType<typeof saveGeneratedScene>>) => void;
vi.mocked(saveGeneratedScene).mockImplementationOnce(() => new Promise((resolve) => { encoded = resolve; }));
@@ -560,11 +594,14 @@ it("cancels a source saving video safely when its queued dependent is cancelled"
emit("slopfab-job", { jobId: sourceId, state: "framesReady" });
await waitFor(() => expect(saveGeneratedScene).toHaveBeenCalledOnce());
const [childId] = queue.enqueue(first, [{ ...source, job: child, request: { ...source.request, previousSceneId: source.job.id } }]);
- await queue.cancel(childId);
- expect(queue.getSnapshot()[0]).toMatchObject({ status: "encoding", cancelling: true });
+ await queue.cancel(cancelScene === "source" ? sourceId : childId);
+ expect(queue.getSnapshot()[0]).toMatchObject({ status: "encoding", cancelling: cancelScene === "source" });
+ expect(queue.getSnapshot()[1].status).toBe("cancelled");
+ expect(cancelSlopfabGeneration).not.toHaveBeenCalled();
encoded({ relativePath: "media/result.mp4", bytes: 100, note: null });
- await waitFor(() => expect(queue.getSnapshot().every((item) => item.status === "cancelled")).toBe(true));
- expect(first.getSnapshot().config.generationJobs[0].outputRelativePath).toBeFalsy();
+ await waitFor(() => expect(queue.getSnapshot()[0].status).toBe(cancelScene === "source" ? "cancelled" : "completed"));
+ if (cancelScene === "source") expect(first.getSnapshot().config.generationJobs[0].outputRelativePath).toBeFalsy();
+ else expect(first.getSnapshot().config.generationJobs[0].outputRelativePath).toBe("media/result.mp4");
expect(enqueueSlopfabGeneration).toHaveBeenCalledOnce();
});
diff --git a/src/lib/workQueue.ts b/src/lib/workQueue.ts
index 035e9bf..3ea8e88 100644
--- a/src/lib/workQueue.ts
+++ b/src/lib/workQueue.ts
@@ -50,8 +50,8 @@ function imageGenerationSeed(seed: number): number {
return (high & 0x1fffff) * 0x100000000 + low;
}
export interface WorkItem {
- /** Exact video runs linked while their sources were still in flight. */
- generationGroupId?: string;
+ /** Exact source runs captured at submission, independent of later draft edits. */
+ sourceWorkIds?: string[];
imageAssetId?: string | null;
imageDraftId?: string;
kind?: "reference-icons" | "image" | "refmod" | "music" | "album-cover";
@@ -262,7 +262,7 @@ export class WorkQueue {
? sceneGenerationSnapshot(captured, request) : submission.snapshot;
this.work.set(id, { id, generatorName: submission.upscaleSource ? submission.upscaleSource.generatorName : chosen.name, session, sceneId: submission.job.id, sceneInput: structuredClone(submission.upscaleSource?.scene ?? sceneInput(captured)), upscaleSource: submission.upscaleSource && structuredClone(submission.upscaleSource), request, config, snapshot, cancelled: false, submitted: false, done, finish });
this.items = [...this.items, {
- id, generationGroupId: id, projectKey, folderPath: session.record.folderPath, projectName: config.name,
+ id, projectKey, folderPath: session.record.folderPath, projectName: config.name,
sceneId: submission.job.id, title: submission.job.title, submittedAt: new Date().toISOString(),
status: "queued", progress: 0, detail: submission.upscaleSource ? "Waiting to upscale" : "Waiting to generate", error: null, completionAt: null,
cancelling: false, needsSave: false,
@@ -271,19 +271,18 @@ export class WorkQueue {
this.updateScene(this.work.get(id)!, { status: "queued", stage: "queued", progress: 0, error: null,
...(!submission.upscaleSource ? { generationSnapshot: snapshot, generatorTemplateId: captured.generatorTemplateId, steps: captured.steps, seed: captured.seed } : {}) });
}
- // Link after the whole batch is present, including sources submitted in
- // earlier calls. Group IDs survive completed-work cleanup and draft edits.
+ // Capture directed dependencies after the whole batch is present, including
+ // sources submitted in earlier calls. Run IDs survive draft edits and keep
+ // cancellation from spreading to ancestors or another run of the same scene.
for (const id of ids) {
const work = this.work.get(id)!;
const job = work.config.generationJobs.find((job) => job.id === work.sceneId)!;
if (work.upscaleSource) continue;
const sources = new Set([work.request.previousSceneId, work.request.contextSceneId, work.request.latentBridge?.leftSceneId,
work.request.latentBridge?.rightSceneId, longShotPosition(job, sceneSiblings(job, work.config))?.previousBridge?.id]);
- const group = this.items.find((item) => item.id === id)!.generationGroupId!;
- const groups = new Set(this.items.filter((item) => item.projectKey === projectKey && !item.kind && isWorkActive(item)
- && sources.has(item.sceneId)).map((item) => item.generationGroupId));
- this.items = this.items.map((item) => item.projectKey === projectKey && item.generationGroupId && groups.has(item.generationGroupId)
- ? { ...item, generationGroupId: group } : item);
+ const sourceWorkIds = this.items.filter((item) => item.id !== id && item.projectKey === projectKey && !item.kind && isWorkActive(item)
+ && sources.has(item.sceneId)).map((item) => item.id);
+ this.items = this.items.map((item) => item.id === id ? { ...item, sourceWorkIds } : item);
}
this.publish();
if (this.items.some((item) => item.status === "queued" && item.kind !== "reference-icons")) this.icons.yieldToVideo();
@@ -693,9 +692,18 @@ export class WorkQueue {
if (this.icons.owns(id)) { await this.icons.cancel(); return; }
const item = this.items.find((candidate) => candidate.id === id);
if (!item || !isWorkActive(item)) return;
- const linked = this.items.filter((candidate) => candidate.id === id || (item.generationGroupId
- && candidate.projectKey === item.projectKey && candidate.generationGroupId === item.generationGroupId && isWorkActive(candidate)));
- await Promise.all(linked.map((candidate) => this.cancelOne(candidate.id)));
+ const active = this.items.filter((candidate) => candidate.projectKey === item.projectKey && isWorkActive(candidate));
+ const cancelledIds = new Set([id]);
+ // Follow only source -> dependent edges, including indirect descendants.
+ // Iterate to a fixed point so batch submission order does not matter.
+ let previousSize: number;
+ do {
+ previousSize = cancelledIds.size;
+ for (const candidate of active) {
+ if (candidate.sourceWorkIds?.some((sourceId) => cancelledIds.has(sourceId))) cancelledIds.add(candidate.id);
+ }
+ } while (cancelledIds.size !== previousSize);
+ await Promise.all([...cancelledIds].map((cancelledId) => this.cancelOne(cancelledId)));
}
private async cancelOne(id: string): Promise<void> {
const item = this.items.find((candidate) => candidate.id === id);