Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): retain previews while saved workflows wait
JPPhoto0f3300a91e3a
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime.test.tsindex b11ec40a85..3addb74dd8 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts@@ -7,6 +7,7 @@ import type {} from '@features/queue/core/types';import type { BackendConnectionStatus } from '@platform/transport/types';+import { activeProgressTargetStore } from '@features/queue/data/activeProgressTargetStore';import { buildQueueItemOrigin } from '@features/queue/data/events';import { ApiError } from '@platform/transport/http';import { describe, expect, it, vi } from 'vitest';@@ -1936,6 +1937,58 @@ describe('queue runtime', () => {runtime.dispose();});+ it.each([+ { hasWorkflowCall: true, name: 'saved-workflow call', node: { id: 'call', type: 'call_saved_workflow' } },+ { hasWorkflowCall: false, name: 'ordinary workflow', node: { id: 'denoise', type: 'denoise' } },+ ])('recovery routes waiting preview correctly for $name', async ({ hasWorkflowCall, node }) => {+ const queueItem = createPendingQueueItem();+ queueItem.snapshot.backendSubmission = {+ batchCount: 1,+ graph: {+ edges: [],+ id: 'backend-graph',+ nodes: { [node.id]: node },+ },+ kind: 'workflow',+ };+ queueItem.snapshot.sourceId = 'workflow';+ queueItem.backendItemIds = [88];+ queueItem.status = 'running';+ const project = { id: 'project-1', queue: { items: [queueItem] } };+ const getItem = vi.fn().mockResolvedValue({+ id: 88,+ origin: buildQueueItemOrigin(queueItem.id, project.id),+ status: 'waiting',+ });+ const readProgressPreviews = vi.fn().mockResolvedValue([]);+ const backend = createTestBackend({ getItem, readProgressPreviews });+ const runtime = createQueueRuntime({+ ...runtimeServices,+ backend,+ history: {+ commands: createTestCommands(),+ getSnapshot: () => ({ connectionStatus: 'connected', isHydrated: true, projects: [project] }),+ subscribe: vi.fn(() => vi.fn()),+ },+ });+ activeProgressTargetStore.clear();+ const clear = vi.spyOn(activeProgressTargetStore, 'clear');++ try {+ runtime.start();+ await vi.waitFor(() => expect(readProgressPreviews).toHaveBeenCalled());++ if (hasWorkflowCall) {+ expect(clear).not.toHaveBeenCalledWith({ itemIndex: 1, queueItemId: queueItem.id });+ } else {+ expect(clear).toHaveBeenCalledWith({ itemIndex: 1, queueItemId: queueItem.id });+ }+ } finally {+ await runtime.dispose();+ clear.mockRestore();+ }+ });+it('retains a running journal row when its project tab closes', async () => {const queueItem = { ...createPendingQueueItem(), backendItemIds: [88], status: 'running' as const };const projects: Array<{ id: string; queue: { items: QueueItem[] } }> = [diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.ts b/invokeai/frontend/webv2/src/features/queue/runtime.tsindex 1c73044a4e..fd6f48af0d 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.ts@@ -121,6 +121,27 @@ const getQueueItemCompiledGraph = (queueItem: QueueItem): unknown => {return submission && typeof submission === 'object' && 'graph' in submission ? submission.graph : undefined;};+const queueItemHasWorkflowCall = (queueItem: QueueItem): boolean => {+ const submission = (queueItem.snapshot as Partial<QueueItem['snapshot']>).backendSubmission;+ if (!submission || typeof submission !== 'object' || !('kind' in submission) || submission.kind !== 'workflow') {+ return false;+ }++ const graph = getQueueItemCompiledGraph(queueItem);+ if (!graph || typeof graph !== 'object' || Array.isArray(graph) || !('nodes' in graph)) {+ return false;+ }++ const nodes = graph.nodes;+ if (!nodes || typeof nodes !== 'object' || Array.isArray(nodes)) {+ return false;+ }++ return Object.values(nodes).some(+ (node) => node !== null && typeof node === 'object' && 'type' in node && node.type === 'call_saved_workflow'+ );+};+/** Recover legacy random-toggle submissions with their original seed expansion rules. */const readSubmissionSeedStep = (submission: { seedStep?: unknown; shouldRandomizeSeed?: unknown }) =>isQueueSeedStep(submission.seedStep)@@ -1558,6 +1579,7 @@ export const createQueueRuntime = ({const inputs: ReconcileInput[] = ownedItems.map(({ project, queueItem }) => ({backendBatchId: queueItem.backendBatchId,backendItemIds: queueItem.backendItemIds,+ hasWorkflowCall: queueItemHasWorkflowCall(queueItem),id: queueItem.id,projectId: project.id,status: queueItem.status === 'running' ? 'running' : 'pending',diff --git a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.tsindex 123c192115..e57d685038 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts@@ -305,6 +305,14 @@ const createHarness = (options: { galleryRefreshCoalesceMs?: number } = {}): Har};};+const savedWorkflowCallRequest = (): QueueEnqueueWorkflowRequest => ({+ ...workflowRequest,+ graph: {+ ...workflowRequest.graph,+ nodes: { 'call-node': { id: 'call-node', type: 'call_saved_workflow' } },+ },+});+describe('queueCoordinator', () => {let harness: Harness;@@ -844,6 +852,7 @@ describe('queueCoordinator', () => {});harness.socket.fire('invocation_progress', frame(2, 'data:image/png;base64,second'));+ harness.socket.fire('invocation_progress', frame(2, 'data:image/png;base64,duplicate-second'));harness.socket.fire('invocation_progress', frame(1, 'data:image/png;base64,first'));harness.socket.fire('invocation_progress', frame(3, 'data:image/png;base64,third'));// A new session on the same item starts over.@@ -854,6 +863,8 @@ describe('queueCoordinator', () => {'data:image/png;base64,third','data:image/png;base64,retry',]);+ expect(harness.activeProgressTarget.set).toHaveBeenCalledTimes(3);+ expect(harness.nodeExecution.progress).toHaveBeenCalledTimes(3);});it('keeps the completed progress image until backend item result routing finishes', async () => {@@ -1099,6 +1110,622 @@ describe('queueCoordinator', () => {);});+ it('routes sequential child and grandchild preview frames to the same root slot', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ const target = { itemIndex: 1, queueItemId: 'workflow-root' };+ const frame = (itemId: number, parentItemId: number, revision: number, dataURL: string) => ({+ ...createStatusEvent({ item_id: itemId, status: 'in_progress' }),+ image: { dataURL, height: 32, width: 64 },+ invocation_source_id: 'shared-child-node',+ message: 'Child sampling',+ parent_item_id: parentItemId,+ percentage: revision / 4,+ revision,+ root_item_id: 1,+ session_id: `child-session-${itemId}`,+ workflow_call_parent_source_id: 'call-node',+ });++ harness.socket.fire('invocation_progress', frame(2, 1, 1, 'data:image/png;base64,child-first'));+ harness.socket.fire('invocation_progress', frame(2, 1, 2, 'data:image/png;base64,child-second'));+ harness.socket.fire('invocation_progress', frame(3, 2, 1, 'data:image/png;base64,grandchild'));++ expect(harness.activeProgressTarget.set.mock.calls.map(([activeTarget]) => activeTarget)).toEqual([+ target,+ target,+ target,+ ]);+ expect(+ harness.progressImage.set.mock.calls.map(([image, imageTarget]) => ({ image, target: imageTarget }))+ ).toEqual([+ {+ image: { dataUrl: 'data:image/png;base64,child-first', height: 32, width: 64 },+ target,+ },+ {+ image: { dataUrl: 'data:image/png;base64,child-second', height: 32, width: 64 },+ target,+ },+ {+ image: { dataUrl: 'data:image/png;base64,grandchild', height: 32, width: 64 },+ target,+ },+ ]);+ });++ it('keeps identical child node ids isolated across concurrent roots', async () => {+ harness.api.enqueueWorkflow+ .mockResolvedValueOnce({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 })+ .mockResolvedValueOnce({ batchId: 'batch-2', enqueued: 1, itemIds: [2], requested: 1 });+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('root-one', savedWorkflowCallRequest());+ await harness.coordinator.submitWorkflow('root-two', savedWorkflowCallRequest());+ const targetOne = { itemIndex: 1, queueItemId: 'root-one' };+ const targetTwo = { itemIndex: 1, queueItemId: 'root-two' };+ const frame = (itemId: number, rootItemId: number, label: string) => ({+ ...createStatusEvent({ item_id: itemId, status: 'in_progress' }),+ image: { dataURL: `data:image/png;base64,${label}`, height: 32, width: 64 },+ invocation_source_id: 'shared-child-node',+ message: 'Child sampling',+ parent_item_id: rootItemId,+ percentage: 0.5,+ revision: 1,+ root_item_id: rootItemId,+ session_id: `child-session-${rootItemId}`,+ workflow_call_parent_source_id: 'same-call-node',+ });++ harness.socket.fire('invocation_progress', frame(11, 1, 'root-one-frame'));+ harness.socket.fire('invocation_progress', frame(12, 2, 'root-two-frame'));++ expect(harness.progressImage.set.mock.calls.map(([image, target]) => ({ image, target }))).toEqual([+ {+ image: { dataUrl: 'data:image/png;base64,root-one-frame', height: 32, width: 64 },+ target: targetOne,+ },+ {+ image: { dataUrl: 'data:image/png;base64,root-two-frame', height: 32, width: 64 },+ target: targetTwo,+ },+ ]);+ });++ it.each(['socket status', 'visibility sweep'] as const)(+ 'keeps a child preview eligible when parent waiting arrives through %s',+ async (delivery) => {+ const listeners = new Map<string, () => void>();+ vi.stubGlobal('document', {+ addEventListener: (type: string, listener: () => void) => listeners.set(type, listener),+ removeEventListener: (type: string) => listeners.delete(type),+ visibilityState: 'visible',+ });++ try {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);+ const target = { itemIndex: 1, queueItemId: 'local-1' };+ const childFrame = (revision: number, dataURL: string) => ({+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL, height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ harness.socket.fire('invocation_progress', childFrame(1, 'data:image/png;base64,first'));++ if (delivery === 'socket status') {+ harness.socket.fire(+ 'queue_item_status_changed',+ createStatusEvent({ item_id: 1, status: 'waiting', status_sequence: 2 })+ );+ } else {+ const waitingRead = deferred<QueueBackendItem>();+ harness.api.getItem.mockReturnValueOnce(waitingRead.promise);+ listeners.get('visibilitychange')?.();+ expect(harness.api.getItem).toHaveBeenCalledWith(1);+ waitingRead.resolve(createQueueBackendItem({ id: 1, status: 'waiting' }));+ await Promise.resolve();+ }++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);++ harness.socket.fire('invocation_progress', childFrame(2, 'data:image/png;base64,second'));++ expect(harness.activeProgressTarget.set).toHaveBeenLastCalledWith(target);+ expect(harness.progressImage.set.mock.calls.map(([image]) => (image as { dataUrl: string }).dataUrl)).toEqual([+ 'data:image/png;base64,first',+ 'data:image/png;base64,second',+ ]);+ } finally {+ vi.unstubAllGlobals();+ }+ }+ );++ it('keeps the last root frame while waiting before the first child frame', async () => {+ harness.coordinator.connect();+ const request = {+ ...workflowRequest,+ graph: {+ ...workflowRequest.graph,+ nodes: { 'call-node': { id: 'call-node', type: 'call_saved_workflow' } },+ },+ };+ await harness.coordinator.submitWorkflow('local-1', request);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,root', height: 32, width: 64 },+ invocation_source_id: 'call-node',+ message: 'Calling workflow',+ percentage: 0.4,+ revision: 1,+ session_id: 'root-session',+ });+ harness.socket.fire(+ 'queue_item_status_changed',+ createStatusEvent({ item_id: 1, status: 'waiting', status_sequence: 2 })+ );++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ expect(harness.activeProgressTarget.set).toHaveBeenLastCalledWith(target);+ expect(harness.progressImage.set).toHaveBeenLastCalledWith(+ { dataUrl: 'data:image/png;base64,child', height: 32, width: 64 },+ target+ );+ });++ it('keeps the root preview eligible through child completion and parent resume', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status: 'waiting' }));+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 2, status: 'completed' }));+ harness.socket.fire(+ 'queue_item_status_changed',+ createStatusEvent({ item_id: 1, status: 'pending', status_sequence: 2 })+ );+ harness.socket.fire(+ 'queue_item_status_changed',+ createStatusEvent({ item_id: 1, status: 'in_progress', status_sequence: 3 })+ );++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);+ expect(harness.activeProgressTarget.set).toHaveBeenLastCalledWith(target);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);+ });++ it('recognizes a queued saved-workflow call before its first child event', async () => {+ const request = {+ ...workflowRequest,+ graph: {+ ...workflowRequest.graph,+ nodes: { call: { id: 'call', type: 'call_saved_workflow' } },+ },+ };+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', request);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,parent-frame', height: 32, width: 64 },+ invocation_source_id: 'call',+ message: 'Calling saved workflow',+ percentage: 0.5,+ });+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status: 'waiting' }));++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child-frame', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ root_item_id: 1,+ workflow_call_parent_source_id: 'call',+ });++ expect(harness.activeProgressTarget.set).toHaveBeenLastCalledWith(target);+ expect(harness.progressImage.set).toHaveBeenLastCalledWith(+ { dataUrl: 'data:image/png;base64,child-frame', height: 32, width: 64 },+ target+ );+ });++ it('preserves a recognized child route when reconciliation finds the parent waiting', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child-frame', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ root_item_id: 1,+ workflow_call_parent_source_id: 'call-node',+ });+ harness.activeProgressTarget.clear.mockClear();+ harness.api.getItem.mockResolvedValue(+ createQueueBackendItem({+ id: 1,+ origin: buildQueueItemOrigin('local-1', 'project-1'),+ status: 'waiting',+ })+ );++ await harness.coordinator.reconcile([+ { backendItemIds: [1], id: 'local-1', projectId: 'project-1', status: 'running' },+ ]);++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);+ });++ it('still clears a workflow preview while waiting when no child call is known', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,parent-frame', height: 32, width: 64 },+ invocation_source_id: 'ordinary-node',+ message: 'Running workflow',+ percentage: 0.5,+ });+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status: 'waiting' }));++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(target);+ expect(harness.progressImage.set).toHaveBeenCalledWith(+ { dataUrl: 'data:image/png;base64,parent-frame', height: 32, width: 64 },+ target+ );+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(target);+ });++ it('clears the root preview target when a saved-workflow run reaches terminal status', async () => {+ const request = {+ ...workflowRequest,+ graph: {+ ...workflowRequest.graph,+ nodes: { call: { id: 'call', type: 'call_saved_workflow' } },+ },+ };+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', request);+ const target = { itemIndex: 1, queueItemId: 'local-1' };++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,parent-frame', height: 32, width: 64 },+ invocation_source_id: 'call',+ message: 'Calling saved workflow',+ percentage: 0.5,+ });+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status: 'waiting' }));++ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(target);++ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status: 'completed' }));++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).toHaveBeenCalledWith(target);+ });++ it('ignores a child preview whose root is not tracked', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,unrelated', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 99,+ session_id: 'unrelated-child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ expect(harness.activeProgressTarget.set).not.toHaveBeenCalled();+ expect(harness.progressImage.set).not.toHaveBeenCalled();+ expect(harness.nodeExecution.progress).not.toHaveBeenCalled();+ });++ it('isolates a saved-workflow preview from status changes on another root', async () => {+ harness.api.enqueueGenerate.mockResolvedValue({+ batchId: 'batch-other',+ enqueued: 1,+ itemIds: [2],+ requested: 1,+ });+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ await harness.coordinator.submitGenerate('other-root', generateRequest);++ const workflowTarget = { itemIndex: 1, queueItemId: 'workflow-root' };+ const otherTarget = { itemIndex: 1, queueItemId: 'other-root' };+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,workflow-root', height: 32, width: 64 },+ invocation_source_id: 'call-node',+ message: 'Calling workflow',+ percentage: 0.4,+ revision: 1,+ session_id: 'root-session',+ });+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,other-root', height: 32, width: 64 },+ invocation_source_id: 'denoise',+ message: 'Denoising',+ percentage: 0.5,+ revision: 1,+ session_id: 'other-session',+ });++ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 2, status: 'waiting' }));++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(otherTarget);+ expect(harness.activeProgressTarget.clear).not.toHaveBeenCalledWith(workflowTarget);+ expect(harness.progressImage.clear).not.toHaveBeenCalledWith(workflowTarget);++ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,workflow-child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ expect(harness.progressImage.set).toHaveBeenLastCalledWith(+ { dataUrl: 'data:image/png;base64,workflow-child', height: 32, width: 64 },+ workflowTarget+ );+ });++ it('routes sibling child frames to their own batch slots when node ids match', async () => {+ harness.api.enqueueWorkflow.mockResolvedValue({+ batchId: 'batch-1',+ enqueued: 2,+ itemIds: [1, 2],+ requested: 2,+ });+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('local-1', {+ ...savedWorkflowCallRequest(),+ batchCount: 2,+ });++ const frame = (itemId: number, rootItemId: number, label: string) => ({+ ...createStatusEvent({ item_id: itemId, status: 'in_progress' }),+ image: { dataURL: `data:image/png;base64,${label}`, height: 32, width: 64 },+ invocation_source_id: 'same-child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: rootItemId,+ session_id: `child-session-${itemId}`,+ workflow_call_parent_source_id: 'call-node',+ });++ harness.socket.fire('invocation_progress', frame(11, 1, 'slot-one'));+ harness.socket.fire('invocation_progress', frame(12, 2, 'slot-two'));++ expect(harness.progressImage.set.mock.calls.map(([, target]) => target)).toEqual([+ { itemIndex: 1, queueItemId: 'local-1' },+ { itemIndex: 2, queueItemId: 'local-1' },+ ]);+ expect(harness.progressImage.set.mock.calls.map(([image]) => (image as { dataUrl: string }).dataUrl)).toEqual([+ 'data:image/png;base64,slot-one',+ 'data:image/png;base64,slot-two',+ ]);+ });++ it('does not borrow another root frame when this workflow root has no frame', async () => {+ harness.api.enqueueGenerate.mockResolvedValue({+ batchId: 'batch-other',+ enqueued: 1,+ itemIds: [2],+ requested: 1,+ });+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ await harness.coordinator.submitGenerate('other-root', generateRequest);++ const otherTarget = { itemIndex: 1, queueItemId: 'other-root' };+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 2, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,other-root-only', height: 32, width: 64 },+ invocation_source_id: 'denoise',+ message: 'Denoising',+ percentage: 0.5,+ revision: 1,+ session_id: 'other-session',+ });+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 1, status: 'in_progress' }),+ image: null,+ invocation_source_id: 'call-node',+ message: 'Calling workflow',+ percentage: 0.4,+ session_id: 'root-session',+ });+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: null,+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ expect(harness.progressImage.set.mock.calls).toEqual([+ [{ dataUrl: 'data:image/png;base64,other-root-only', height: 32, width: 64 }, otherTarget],+ ]);+ });++ it.each(['completed', 'failed', 'canceled'] as const)(+ 'retires a saved-workflow preview after root %s and ignores late child frames',+ async (status) => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ const target = { itemIndex: 1, queueItemId: 'workflow-root' };+ const childFrame = {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ };++ harness.socket.fire('invocation_progress', childFrame);+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 1, status }));++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).toHaveBeenCalledWith(target);+ const progressSetCount = harness.progressImage.set.mock.calls.length;+ const activeSetCount = harness.activeProgressTarget.set.mock.calls.length;+ const nodeProgressCount = harness.nodeExecution.progress.mock.calls.length;++ harness.socket.fire('invocation_progress', { ...childFrame, revision: 2 });++ expect(harness.progressImage.set).toHaveBeenCalledTimes(progressSetCount);+ expect(harness.activeProgressTarget.set).toHaveBeenCalledTimes(activeSetCount);+ expect(harness.nodeExecution.progress).toHaveBeenCalledTimes(nodeProgressCount);+ }+ );++ it('retires a saved-workflow preview on owner-scoped bulk cancellation', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ const target = { itemIndex: 1, queueItemId: 'workflow-root' };+ harness.socket.fire('invocation_progress', {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ });++ harness.socket.fire('queue_items_canceled', {+ canceled_item_ids: [1],+ canceled_item_ids_by_user: { 'user-1': [1] },+ queue_id: 'default',+ timestamp: 2,+ user_ids: ['user-1'],+ });++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).toHaveBeenCalledWith(target);+ });++ it('retires a detached workflow preview and ignores late child frames', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ const target = { itemIndex: 1, queueItemId: 'workflow-root' };+ const childFrame = {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ };+ harness.socket.fire('invocation_progress', childFrame);+ const progressSetCount = harness.progressImage.set.mock.calls.length;++ harness.coordinator.detachRun('workflow-root');++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith(target);+ expect(harness.progressImage.clear).toHaveBeenCalledWith(target);+ harness.socket.fire('invocation_progress', { ...childFrame, revision: 2 });+ expect(harness.progressImage.set).toHaveBeenCalledTimes(progressSetCount);+ });++ it('clears workflow preview state on disposal and ignores later events', async () => {+ harness.coordinator.connect();+ await harness.coordinator.submitWorkflow('workflow-root', savedWorkflowCallRequest());+ const childFrame = {+ ...createStatusEvent({ item_id: 3, status: 'in_progress' }),+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },+ invocation_source_id: 'child-node',+ message: 'Child sampling',+ percentage: 0.5,+ revision: 1,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ };+ harness.socket.fire('invocation_progress', childFrame);+ const progressSetCount = harness.progressImage.set.mock.calls.length;++ harness.coordinator.dispose();++ expect(harness.activeProgressTarget.clear).toHaveBeenCalledWith();+ expect(harness.progressImage.clear).toHaveBeenCalledWith();+ harness.socket.fire('invocation_progress', { ...childFrame, revision: 2 });+ expect(harness.progressImage.set).toHaveBeenCalledTimes(progressSetCount);+ });+it('allows a child preview revision again after the child reaches terminal status', async () => {harness.api.enqueueWorkflow.mockResolvedValue({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });harness.coordinator.connect();diff --git a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.tsindex c23bd59867..de9fe42a06 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts@@ -125,6 +125,8 @@ export interface ReconcileInput {status: 'pending' | 'running';backendItemIds?: number[];backendBatchId?: string;+ /** Persisted compiled graph contains a Call Saved Workflow node. */+ hasWorkflowCall?: boolean;}export type ReconcileOutcome =@@ -181,6 +183,7 @@ interface RunProgressState {interface WaitState {frameGates: Map<number, { revision: number | null; sessionId: string }>;+ hasWorkflowCall: boolean;localQueueItemId: string;settle: (outcome: TerminalOutcome) => void;}@@ -228,6 +231,19 @@ export const createQueueCoordinator = (const runs = new Map<string, RunState>();const runProgress = new Map<string, RunProgressState>();const waits = new Map<number, WaitState>();+ const markWorkflowCallRoot = (event: {+ item_id: number;+ root_item_id?: number | null;+ workflow_call_parent_source_id?: string | null;+ }): void => {+ const rootItemId = event.root_item_id;+ if (rootItemId !== null && rootItemId !== undefined && rootItemId !== event.item_id) {+ const wait = waits.get(rootItemId);+ if (wait && event.workflow_call_parent_source_id !== null && event.workflow_call_parent_source_id !== undefined) {+ wait.hasWorkflowCall = true;+ }+ }+ };const clearFrameGate = (itemId: number): void => {for (const wait of waits.values()) {if (wait.frameGates.delete(itemId)) {@@ -400,6 +416,7 @@ export const createQueueCoordinator = (}const backendItemId = getTrackedBackendItemId(nodeEvent.event);+ markWorkflowCallRoot(nodeEvent.event);const invocationSourceId = getNodeSourceId(nodeEvent.event);trackNodeForItem(backendItemId, invocationSourceId, nodeEvent.sequence);@@ -590,7 +607,7 @@ export const createQueueCoordinator = (const target = getProgressImageTarget(wait.localQueueItemId, queueItem.id);if (queueItem.status === 'in_progress') {activeProgressTarget.set(target);- } else if (queueItem.status === 'pending' || queueItem.status === 'waiting') {+ } else if ((queueItem.status === 'pending' || queueItem.status === 'waiting') && !wait.hasWorkflowCall) {activeProgressTarget.clear(target);}}@@ -602,7 +619,11 @@ export const createQueueCoordinator = (const isTrackedEvent = (event: { item_id: number; root_item_id?: number | null }): boolean =>waits.has(getTrackedBackendItemId(event));- const trackBackendItem = (localQueueItemId: string, backendItemId: number): Promise<TerminalOutcome> => {+ const trackBackendItem = (+ localQueueItemId: string,+ backendItemId: number,+ hasWorkflowCall: boolean+ ): Promise<TerminalOutcome> => {const bufferedOutcome = recentTerminalOutcomes.get(backendItemId);if (bufferedOutcome) {@@ -615,17 +636,25 @@ export const createQueueCoordinator = (}return new Promise<TerminalOutcome>((settle) => {- waits.set(backendItemId, { frameGates: new Map(), localQueueItemId, settle });+ waits.set(backendItemId, { frameGates: new Map(), hasWorkflowCall, localQueueItemId, settle });replayNodeEvents(backendItemId);replayProgressEvent(backendItemId);});};- const beginRun = (localQueueItemId: string, backendItemIds: number[], backendBatchId?: string): void => {+ const beginRun = (+ localQueueItemId: string,+ backendItemIds: number[],+ backendBatchId?: string,+ hasWorkflowCall = false+ ): void => {if (!isActive()) {throw new QueueItemCancelledError(localQueueItemId);}+ const hasRecognizedWorkflowCall =+ hasWorkflowCall || backendItemIds.some((backendItemId) => waits.get(backendItemId)?.hasWorkflowCall);+runProgress.set(localQueueItemId, {backendItemIds,cancelledBackendItemIds: new Set(),@@ -636,7 +665,9 @@ export const createQueueCoordinator = (runs.set(localQueueItemId, {backendBatchId,backendItemIds,- outcomePromises: backendItemIds.map((backendItemId) => trackBackendItem(localQueueItemId, backendItemId)),+ outcomePromises: backendItemIds.map((backendItemId) =>+ trackBackendItem(localQueueItemId, backendItemId, hasRecognizedWorkflowCall)+ ),});publishRunProgress(localQueueItemId);@@ -737,7 +768,7 @@ export const createQueueCoordinator = (// whatever frames follow belong to a new leg, and after a backend restart// their revisions start over.if (event.status === 'pending' || event.status === 'waiting') {- if (wait) {+ if (wait && !wait.hasWorkflowCall) {activeProgressTarget.clear(getProgressImageTarget(wait.localQueueItemId, event.item_id));}wait?.frameGates.clear();@@ -828,6 +859,8 @@ export const createQueueCoordinator = (return;}+ markWorkflowCallRoot(event);+if (event.image?.dataURL && isStaleFrame(event)) {return;}@@ -1060,7 +1093,7 @@ export const createQueueCoordinator = (const backendItemIds = foundBackendItems.map((backendItem) => backendItem.id);const backendBatchId = item.backendBatchId ?? foundBackendItems[0]?.batchId;- beginRun(item.id, backendItemIds, backendBatchId);+ beginRun(item.id, backendItemIds, backendBatchId, item.hasWorkflowCall);for (const backendItem of foundBackendItems) {settleFromQueueItem(backendItem);@@ -1092,13 +1125,14 @@ export const createQueueCoordinator = (const adoptEnqueueResult = (localQueueItemId: string,result: QueueEnqueueResult,- workKind: 'generation' | 'workflow'+ workKind: 'generation' | 'workflow',+ hasWorkflowCall = false): QueueEnqueueResult => {if (result.enqueued === 0) {throw new QueueEnqueueNotAcceptedError(workKind);}- beginRun(localQueueItemId, result.itemIds, result.batchId);+ beginRun(localQueueItemId, result.itemIds, result.batchId, hasWorkflowCall);return result;};@@ -1125,7 +1159,12 @@ export const createQueueCoordinator = (}return await withSubmissionInFlight(async () =>- adoptEnqueueResult(localQueueItemId, await backend.enqueueWorkflow(request), 'workflow')+ adoptEnqueueResult(+ localQueueItemId,+ await backend.enqueueWorkflow(request),+ 'workflow',+ Object.values(request.graph.nodes).some((node) => node.type === 'call_saved_workflow')+ ));};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsxindex ae5154a973..20e2ceefbe 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx@@ -1,11 +1,12 @@/* oxlint-disable react-perf/jsx-no-new-object-as-prop */import type { GalleryImage, GalleryImageItem, GalleryItemsPage, GalleryVideoItem } from '@features/gallery';-import type { QueueItem } from '@features/queue/contracts';+import type { InvocationProgressEvent, QueueItem, QueueItemStatusChangedEvent } from '@features/queue/contracts';import type { WidgetViewProps } from '@workbench/widgetContracts';import { ChakraProvider } from '@chakra-ui/react';import { DndContext, useSensor, useSensors, type DndContextProps } from '@dnd-kit/core';import { requestGalleryItemReveal } from '@features/gallery/contracts';+import { createQueueCoordinator, type QueueCoordinatorBackendPort } from '@features/queue/runtime/coordinator';import { QueryClient, QueryClientProvider, type InfiniteData } from '@tanstack/react-query';import { system } from '@theme/system';import { HoldToDragSensor, PrimaryMouseSensor } from '@workbench/shell/holdToDragSensor';@@ -1642,6 +1643,235 @@ describe('preview keyboard navigation boundary', () => {).toHaveLength(1);});+ it('keeps the same-root preview through child gaps and browser focus changes until the next denoising step', async () => {+ mocks.project.queue.items = [queueItem];+ mocks.project.settings.showProgressImagesInViewer = true;+ const visibilityStateDescriptor = Object.getOwnPropertyDescriptor(document, 'visibilityState');++ const listeners = new Map<string, Set<(payload: never) => void>>();+ const fire = (event: string, payload: unknown) => {+ for (const handler of listeners.get(event) ?? []) {+ handler(payload as never);+ }+ };+ const getItem = vi.fn(() => Promise.resolve({ id: 1, status: 'waiting' as const }));+ const backend = {+ enqueueWorkflow: () => Promise.resolve({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 }),+ getItem,+ on: (event: string, handler: (payload: never) => void) => {+ const handlers = listeners.get(event) ?? new Set();+ handlers.add(handler);+ listeners.set(event, handlers);+ return () => handlers.delete(handler);+ },+ onConnectionChange: () => () => {},+ } as unknown as QueueCoordinatorBackendPort;+ let activeTarget: { itemIndex: number; queueItemId: string } | null = null;+ const isActiveTarget = (target: { itemIndex: number; queueItemId: string }) =>+ activeTarget?.itemIndex === target.itemIndex && activeTarget.queueItemId === target.queueItemId;+ const coordinator = createQueueCoordinator(+ { onGalleryRefresh: () => {} },+ {+ activeProgressTarget: {+ clear: (target) => {+ if (!target || isActiveTarget(target)) {+ activeTarget = null;+ mocks.useActiveProgressTarget.mockReturnValue(null);+ mocks.runningProgressTargets = [];+ }+ },+ set: (target) => {+ activeTarget = target;+ mocks.useActiveProgressTarget.mockReturnValue(target);+ mocks.runningProgressTargets = [target];+ },+ waitForChild: (target: { itemIndex: number; queueItemId: string }) => {+ activeTarget = target;+ mocks.useActiveProgressTarget.mockReturnValue(target);+ mocks.runningProgressTargets = [target];+ },+ settle: () => {},+ } as NonNullable<Parameters<typeof createQueueCoordinator>[1]['activeProgressTarget']>,+ backend,+ modelLoads: { completed: () => {}, reset: () => {}, started: () => {} },+ nodeExecution: {+ clearAll: () => {},+ completed: () => {},+ failed: () => {},+ progress: () => {},+ settleRunning: () => {},+ started: () => {},+ },+ progress: { clear: () => {}, clearAll: () => {}, set: () => {} },+ progressImage: {+ bindSwapImages: () => {},+ clear: (target) => {+ if (!target || isActiveTarget(target)) {+ mocks.useProgressImage.mockReturnValue(null);+ mocks.slotProgressImage = null;+ }+ },+ clearHeld: () => {},+ hold: () => {},+ set: (image, target) => {+ const frame = target ? { ...image, target } : image;+ mocks.useProgressImage.mockReturnValue(frame);+ mocks.slotProgressImage = frame;+ },+ },+ sweepIntervalMs: 60_000,+ }+ );+ const target = { itemIndex: 1, queueItemId: 'queue-item-live' };+ const createProgressEvent = (overrides: Partial<InvocationProgressEvent>): InvocationProgressEvent => ({+ batch_id: 'batch-1',+ destination: 'gallery',+ image: null,+ invocation_source_id: 'call-node',+ item_id: 1,+ message: 'Calling saved workflow',+ origin: null,+ percentage: 0.4,+ queue_id: 'default',+ revision: 1,+ session_id: 'root-session',+ timestamp: 1,+ user_id: 'user-1',+ ...overrides,+ });+ const stageFrame = () =>+ host?.querySelector<HTMLImageElement>('img[src^="data:image/png"]:not([data-preview-filmstrip] img)');++ coordinator.connect();+ try {+ await coordinator.submitWorkflow('queue-item-live', {+ batchCount: 1,+ destination: 'gallery',+ graph: {+ edges: [],+ id: 'parent-workflow',+ nodes: { 'call-node': { id: 'call-node', type: 'call_saved_workflow' } },+ },+ projectId: 'project-1',+ sourceQueueItemId: 'queue-item-live',+ });+ await render();++ fire(+ 'invocation_progress',+ createProgressEvent({+ image: { dataURL: 'data:image/png;base64,root-step', height: 64, width: 64 },+ invocation_source_id: 'call-node',+ })+ );+ await rerender();+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,root-step');++ // The coordinator's waiting path consumes these fields from the status event.+ const waitingEvent: Pick<QueueItemStatusChangedEvent, 'item_id' | 'status' | 'status_sequence'> = {+ item_id: 1,+ status: 'waiting',+ status_sequence: 2,+ };+ fire('queue_item_status_changed', waitingEvent);+ await rerender();+ expect(mocks.useActiveProgressTarget()).toEqual(target);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,root-step');++ fire('queue_item_status_changed', waitingEvent);+ await rerender();+ expect(mocks.useActiveProgressTarget()).toEqual(target);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,root-step');++ fire(+ 'invocation_progress',+ createProgressEvent({+ image: null,+ invocation_source_id: 'child-node',+ item_id: 2,+ message: 'Child started without a frame',+ percentage: null,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ })+ );+ await rerender();+ expect(mocks.useActiveProgressTarget()).toEqual(target);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,root-step');++ fire(+ 'invocation_progress',+ createProgressEvent({+ image: { dataURL: 'data:image/png;base64,child-step', height: 64, width: 64 },+ invocation_source_id: 'child-node',+ item_id: 2,+ message: 'Child denoising',+ percentage: 0.6,+ root_item_id: 1,+ session_id: 'child-session',+ workflow_call_parent_source_id: 'call-node',+ })+ );+ await rerender();+ expect(mocks.useActiveProgressTarget()).toEqual(target);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,child-step');++ await act(async () => {+ window.dispatchEvent(new FocusEvent('blur'));+ window.dispatchEvent(new FocusEvent('focus'));+ await Promise.resolve();+ });+ await rerender();+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,child-step');++ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'hidden' });+ await act(async () => {+ document.dispatchEvent(new Event('visibilitychange'));+ await Promise.resolve();+ });+ await rerender();+ expect(getItem).not.toHaveBeenCalled();+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,child-step');++ Object.defineProperty(document, 'visibilityState', { configurable: true, value: 'visible' });+ await act(async () => {+ document.dispatchEvent(new Event('visibilitychange'));+ await Promise.resolve();+ await Promise.resolve();+ });+ await rerender();+ expect(getItem).toHaveBeenCalledTimes(1);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,child-step');++ // A nested child carries the same root ID, even though its parent is the first child item.+ fire(+ 'invocation_progress',+ createProgressEvent({+ image: { dataURL: 'data:image/png;base64,grandchild-step', height: 64, width: 64 },+ invocation_source_id: 'grandchild-node',+ item_id: 3,+ message: 'Nested child denoising',+ parent_item_id: 2,+ percentage: 0.7,+ root_item_id: 1,+ session_id: 'grandchild-session',+ workflow_call_parent_source_id: 'nested-call-node',+ })+ );+ await rerender();+ expect(mocks.useActiveProgressTarget()).toEqual(target);+ expect(stageFrame()?.getAttribute('src')).toBe('data:image/png;base64,grandchild-step');+ } finally {+ coordinator.dispose();+ if (visibilityStateDescriptor) {+ Object.defineProperty(document, 'visibilityState', visibilityStateDescriptor);+ } else {+ Reflect.deleteProperty(document, 'visibilityState');+ }+ }+ });+it("shows the followed slot's own frame even when the store-wide latest frame is gone", async () => {// Retain another live slot's frame when a neighboring batch releases its latest frame.mocks.project.queue.items = [queueItem];@@ -1655,6 +1885,25 @@ describe('preview keyboard navigation boundary', () => {expect(host?.querySelector<HTMLImageElement>('img[src="data:image/png;base64,video-step"]')).not.toBeNull();});+ it('keeps the selected gallery image when no root is followed and latest frame belongs to another root', async () => {+ mocks.project.queue.items = [queueItem];+ mocks.project.settings.showProgressImagesInViewer = false;+ mocks.useActiveProgressTarget.mockReturnValue({ itemIndex: 1, queueItemId: queueItem.id });+ mocks.useProgressImage.mockReturnValue({+ dataUrl: 'data:image/png;base64,other-root',+ height: 64,+ target: { itemIndex: 1, queueItemId: 'other-root' },+ width: 64,+ });++ await render();++ expect(host?.querySelector<HTMLImageElement>('img[src="data:image/png;base64,other-root"]')).toBeNull();+ expect([...host!.querySelectorAll('img')].map((image) => image.getAttribute('src'))).toContain(+ '/images/newest/full'+ );+ });+it('follows a running slot over a settling one so a concurrent session is never hidden', async () => {// Multi-GPU: slot 1 completed and is settling, slot 2 is still streaming.// The single-frame preview must show slot 2 live, not slot 1's static frame.