Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/canvas/generationActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ export function jobActivities(
documentId: string,
nodes: readonly CanvasNode[] = [],
): ActiveGeneration[] {
const displayed = new Map(nodes.map((node) => [node.id, node.data.backendAssetId]));
const byId = new Map(nodes.map((node) => [node.id, node]));
return jobs.flatMap((job) => {
// A regenerated node keeps its old media until the new result has loaded;
// stay busy until then rather than briefly revealing the old image.
// A node keeps its old media, or shows an empty frame, until the new result
// has loaded; stay busy until then. Locally edited text has content but no
// backend asset, and is not waiting for anything.
const node = byId.get(job.nodeId);
const shown = node?.data.backendAssetId;
const empty = Boolean(node && !node.data.src && !node.data.text);
const delivering = Boolean(
job.status === "succeeded" &&
job.deliveredAssetId &&
displayed.has(job.nodeId) &&
displayed.get(job.nodeId) !== job.deliveredAssetId,
(shown ? shown !== job.deliveredAssetId : empty),
);
const finishing = delivering || Boolean(
job.toolTask &&
Expand Down
13 changes: 12 additions & 1 deletion src/canvas/workspace/useWorkspaceRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export function useWorkspaceRuntime(): WorkspaceRuntime {
const setupChecked = useRef(false);
const theme = useTheme();
const serviceRuns = useRef(new Map<string, ServiceRun>());
// Jobs seen running in this session. Only their results can still be
// arriving; historical, undone or version-switched results are never pending.
const watchedJobs = useRef(new Set<string>());
for (const job of jobs)
if (!job.tool && job.status === "running") watchedJobs.current.add(job.id);
const generationByNode = useMemo(
() =>
generationActivities(
Expand All @@ -167,7 +172,13 @@ export function useWorkspaceRuntime(): WorkspaceRuntime {
),
),
...jobActivities(
jobs.filter((job) => !job.tool),
jobs
.filter((job) => !job.tool)
.map((job) =>
job.deliveredAssetId && !watchedJobs.current.has(job.id)
? { ...job, deliveredAssetId: undefined }
: job,
),
doc.id,
doc.nodes,
),
Expand Down
6 changes: 6 additions & 0 deletions tests/canvasPendingResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ test("a regenerated node stays busy until its delivered result is displayed", ()
const shown = { ...node, data: { ...node.data, backendAssetId: "new-asset" } };
assert.deepEqual(jobActivities([job], "doc", [shown]), []);
assert.deepEqual(jobActivities([job], "doc", []), []);
// Local text edits clear the backend asset; such a node is not waiting.
const edited = { ...node, data: { ...node.data, backendAssetId: undefined, text: "draft" } };
assert.deepEqual(jobActivities([job], "doc", [edited]), []);
// A first generation into an empty node waits instead of flashing an empty frame.
const fresh = { ...node, data: { ...node.data, backendAssetId: undefined, src: undefined, text: undefined } };
assert.equal(jobActivities([job], "doc", [fresh])[0]?.phase, "finishing");
// A succeeded job whose result is not the node's current content stays idle.
assert.deepEqual(jobActivities([{ ...job, deliveredAssetId: undefined }], "doc", [node]), []);
});
Loading