From 494fe516a035a74913d22250e9a6db6a51b6f684 Mon Sep 17 00:00:00 2001 From: princepride Date: Fri, 20 Nov 2026 16:50:43 +0000 Subject: [PATCH] [fix] canvas: keep a regenerated node busy until its new result shows When a regeneration succeeded, the busy overlay ended with the job while the canvas was still downloading the new media, so the previous image reappeared until the new one loaded (long for 2K images). A succeeded job now records the result asset its origin node has adopted, and the node stays in the finishing phase until the canvas displays that asset. Co-Authored-By: Claude Opus 5.5 --- src/backend/creationJobs.ts | 11 +++++++++- src/canvas/generationActivity.ts | 13 +++++++++++- src/canvas/generationHistory.ts | 5 +++++ src/canvas/workspace/useWorkspaceRuntime.ts | 3 ++- tests/canvasPendingResults.test.ts | 23 +++++++++++++++++++++ tests/creationJobs.test.ts | 20 ++++++++++++++++++ 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/backend/creationJobs.ts b/src/backend/creationJobs.ts index bf7d53fba..59e4619ca 100644 --- a/src/backend/creationJobs.ts +++ b/src/backend/creationJobs.ts @@ -1,4 +1,4 @@ -import { creationClient } from "./creationClient.ts"; +import { creationClient, currentAsset } from "./creationClient.ts"; import type { Asset, ProjectSnapshot } from "../contracts/generated.ts"; import type { GenerationJob } from "../canvas/generationHistory.ts"; import { @@ -38,6 +38,14 @@ export function creationJobs( item.binding.role === "material" && item.binding.objectRef.assetId === asset.id, ); + const origin = snapshot.canvasItems.find((item) => item.id === job.originItemId); + const delivered = + job.status === "succeeded" && + asset && + origin && + currentAsset(snapshot, origin)?.id === asset.id + ? asset.id + : undefined; const phase = generationPhase(job); const failureMessage = job.errorDetails ? generationFailureMessage(job.errorDetails) @@ -65,6 +73,7 @@ export function creationJobs( } : undefined, activityPhase: phase ?? undefined, + ...(delivered ? { deliveredAssetId: delivered } : {}), preview: preview ?? (asset ? { assetId: asset.id, state: "pending" } : undefined), diff --git a/src/canvas/generationActivity.ts b/src/canvas/generationActivity.ts index 2b2417f89..bb7ad8a66 100644 --- a/src/canvas/generationActivity.ts +++ b/src/canvas/generationActivity.ts @@ -1,14 +1,25 @@ import type { BackendTask } from "../backend/generation.ts"; import type { GenerationJob } from "./generationHistory.ts"; +import type { CanvasNode } from "./model.ts"; import { expectedDuration } from "./generationDurations.ts"; /** Display ownership may differ from the source retained by task/history APIs. */ export function jobActivities( jobs: readonly GenerationJob[], documentId: string, + nodes: readonly CanvasNode[] = [], ): ActiveGeneration[] { + const displayed = new Map(nodes.map((node) => [node.id, node.data.backendAssetId])); return jobs.flatMap((job) => { - const finishing = Boolean( + // A regenerated node keeps its old media until the new result has loaded; + // stay busy until then rather than briefly revealing the old image. + const delivering = Boolean( + job.status === "succeeded" && + job.deliveredAssetId && + displayed.has(job.nodeId) && + displayed.get(job.nodeId) !== job.deliveredAssetId, + ); + const finishing = delivering || Boolean( job.toolTask && job.status === "succeeded" && job.toolTask.placement === "pending", diff --git a/src/canvas/generationHistory.ts b/src/canvas/generationHistory.ts index 0064ed704..cae4831e4 100644 --- a/src/canvas/generationHistory.ts +++ b/src/canvas/generationHistory.ts @@ -62,6 +62,11 @@ export interface GenerationJob { settings: GenerationSettings; }; outputs?: ServiceResult[]; + /** + * A succeeded generation's result asset once the service has made it the + * origin node's current content; the canvas may still be loading it. + */ + deliveredAssetId?: string; /** Rebuildable unified history preview; independent of execution status. */ preview?: { assetId: string; state: "pending" | "ready" | "unavailable" }; /** The AI tool request behind a tool task, so a reopened canvas can follow it. */ diff --git a/src/canvas/workspace/useWorkspaceRuntime.ts b/src/canvas/workspace/useWorkspaceRuntime.ts index 74932fd23..154631205 100644 --- a/src/canvas/workspace/useWorkspaceRuntime.ts +++ b/src/canvas/workspace/useWorkspaceRuntime.ts @@ -169,6 +169,7 @@ export function useWorkspaceRuntime(): WorkspaceRuntime { ...jobActivities( jobs.filter((job) => !job.tool), doc.id, + doc.nodes, ), ...jobActivities( jobs.filter((job) => job.tool), @@ -177,7 +178,7 @@ export function useWorkspaceRuntime(): WorkspaceRuntime { ], doc.id, ), - [activeGenerations, doc.id, jobs], + [activeGenerations, doc.id, doc.nodes, jobs], ); const clipboard = useRef(null); const clipboardMedia = useRef(null); diff --git a/tests/canvasPendingResults.test.ts b/tests/canvasPendingResults.test.ts index c2cf501cc..0d790b5b5 100644 --- a/tests/canvasPendingResults.test.ts +++ b/tests/canvasPendingResults.test.ts @@ -403,3 +403,26 @@ test("history polling and reloads learn each successful duration sample only onc else Reflect.deleteProperty(globalThis, "localStorage"); } }); + +test("a regenerated node stays busy until its delivered result is displayed", () => { + const node = createNode("image"); + node.data.backendAssetId = "old-asset"; + const job = { + id: "job", + nodeId: node.id, + title: "regenerate", + status: "succeeded" as const, + time: "", + outputKind: "image" as const, + deliveredAssetId: "new-asset", + }; + const [activity] = jobActivities([job], "doc", [node]); + assert.equal(activity?.phase, "finishing"); + assert.equal(activity?.nodeId, node.id); + // Once the canvas shows the new asset, or the node is gone, nothing is pending. + const shown = { ...node, data: { ...node.data, backendAssetId: "new-asset" } }; + assert.deepEqual(jobActivities([job], "doc", [shown]), []); + assert.deepEqual(jobActivities([job], "doc", []), []); + // A succeeded job whose result is not the node's current content stays idle. + assert.deepEqual(jobActivities([{ ...job, deliveredAssetId: undefined }], "doc", [node]), []); +}); diff --git a/tests/creationJobs.test.ts b/tests/creationJobs.test.ts index b9b19fd4c..ec8db13af 100644 --- a/tests/creationJobs.test.ts +++ b/tests/creationJobs.test.ts @@ -207,3 +207,23 @@ test("video history shows measured duration separately before the preview loads" const [withoutResult] = creationJobs({ ...completed, results: [] }); assert.deepEqual(withoutResult?.videoDuration, { requestedSeconds: 4, resultSeconds: undefined }); }); + +test("a succeeded job names the result its origin node now shows", () => { + const { snapshot } = fixture(); + const job = { ...snapshot.jobs[0]!, originItemId: "00000000-0000-0000-0000-000000000033" }; + const delivered = (value: ProjectSnapshot) => + creationJobs({ ...value, jobs: [job] })[0]!.deliveredAssetId; + assert.equal(delivered(snapshot), "00000000-0000-0000-0000-00000000000f"); + // Another current result, or a running job, has nothing delivered yet. + assert.equal( + delivered({ + ...snapshot, + generationSpecs: snapshot.generationSpecs.map((spec) => ({ ...spec, currentResultId: null })), + }), + undefined, + ); + assert.equal( + creationJobs({ ...snapshot, jobs: [{ ...job, status: "running" as const }] })[0]!.deliveredAssetId, + undefined, + ); +});