Skip to content

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.

fix(workflow): preserve loop linkage and queue feedback

JPPhoto5012fe7df811
diff --git a/invokeai/frontend/web/src/features/nodes/store/util/reactFlowUtil.ts b/invokeai/frontend/web/src/features/nodes/store/util/reactFlowUtil.ts
index 3eaece154f..1e1fdd1dc6 100644
--- a/invokeai/frontend/web/src/features/nodes/store/util/reactFlowUtil.ts
+++ b/invokeai/frontend/web/src/features/nodes/store/util/reactFlowUtil.ts
@@ -24,7 +24,7 @@ export const connectionToEdge = (connection: Connection): AnyEdge => {
const { source, sourceHandle, target, targetHandle } = connection;
assert(source && sourceHandle && target && targetHandle, 'Invalid connection');
return {
- type: 'default',
+ type: sourceHandle === 'loop_linkage' && targetHandle === 'loop_linkage' ? 'loop_linkage' : 'default',
source,
sourceHandle,
target,
diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.test.ts b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.test.ts
index e62df37a30..f8b71ab193 100644
--- a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.test.ts
+++ b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.test.ts
@@ -399,6 +399,7 @@ describe('buildNodesGraph', () => {
expect(graph.edges).toContainEqual(
expect.objectContaining({
+ type: 'loop_linkage',
destination: { field: 'loop_linkage', node_id: target.id },
source: { field: 'loop_linkage', node_id: source.id },
})
diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts
index 47e4d779c2..315850fcf2 100644
--- a/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts
+++ b/invokeai/frontend/web/src/features/nodes/util/graph/buildNodesGraph.ts
@@ -126,7 +126,7 @@ export const buildNodesGraph = (state: RootState, templates: Templates): Require
// skip out the "dummy" edges between collapsed nodes
const flattenedEdges = edges
- .filter((edge) => edge.type === 'default')
+ .filter((edge) => edge.type === 'default' || edge.type === 'loop_linkage')
.flatMap((edge) => {
const targetNode = nodes.find((node) => node.id === edge.target);
if (!targetNode || !isInvocationNode(targetNode) || !isExecutableNode(targetNode)) {
@@ -185,6 +185,7 @@ export const buildNodesGraph = (state: RootState, templates: Templates): Require
// Format the edges and add to the edges array
edgesAccumulator.push({
+ ...(edge.type === 'loop_linkage' ? { type: 'loop_linkage' as const } : {}),
source: {
node_id: source,
field: sourceHandle,
diff --git a/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts b/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts
index a55e13e094..7f355f852e 100644
--- a/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts
+++ b/invokeai/frontend/web/src/features/nodes/util/workflow/graphToWorkflow.ts
@@ -122,7 +122,7 @@ export const graphToWorkflow = (graph: NonNullableGraph, autoLayout = true): Wor
forEach(graph.edges, (edge) => {
workflow.edges.push({
id: uuidv4(), // we don't have edge IDs in the graph
- type: 'default',
+ type: edge.type === 'loop_linkage' ? 'loop_linkage' : 'default',
source: edge.source.node_id,
sourceHandle: edge.source.field,
target: edge.destination.node_id,
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx
index 0edab66446..4c0b69b705 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx
@@ -440,10 +440,9 @@ describe('CallSavedWorkflowSyncRuntime with an unreachable child workflow', () =
/**
* One invalidation refreshes one shared cache entry, so it costs one request
* however many nodes name that workflow. Selecting the workflow through the
- * picker arms a per-node retry, and a node that then skips its fetch (the
- * entry is already warm) keeps that authorization. An invalidation whose
- * refetch then fails lets every such node spend its stale authorization, one
- * doomed request each.
+ * picker arms a per-node retry. A cache invalidation supersedes those stale
+ * node authorizations with one shared retry, so one invalidation costs one
+ * request even when several nodes name the workflow.
*/
it('refetches an invalidated workflow once for nodes that selected it through the picker', async () => {
const SHARED_WORKFLOW_ID = 'shared-workflow';
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
index 3783a703d8..f7a8e439e3 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx
@@ -162,6 +162,13 @@ export const CallSavedWorkflowSyncRuntime = () => {
const authorizeWorkflowRetry = (workflowId: string) => {
retryableDetailWorkflowQueries.current.set(workflowId, ++nextRetryToken.current);
};
+ const revokeNodeRetries = (workflowId?: string) => {
+ for (const [nodeId, authorization] of retryableDetailWorkflowIds.current) {
+ if (workflowId === undefined || authorization.workflowId === workflowId) {
+ retryableDetailWorkflowIds.current.delete(nodeId);
+ }
+ }
+ };
const reconcile = () => {
const templatesSnapshot = getInvocationTemplatesSnapshot();
@@ -171,6 +178,7 @@ export const CallSavedWorkflowSyncRuntime = () => {
const document = projectPort.getSnapshot().projectGraph;
const currentNodeIds = new Set(document.nodes.map((node) => node.id));
+ const scheduledDetailFetches = new Set<string>();
pruneStaleCallSavedWorkflowNodeState(retryableDetailWorkflowIds.current, currentNodeIds);
pruneStaleCallSavedWorkflowNodeState(previousDetailStatuses.current, currentNodeIds);
@@ -249,6 +257,11 @@ export const CallSavedWorkflowSyncRuntime = () => {
retryErrors: retryWasAuthorized,
})
) {
+ if (scheduledDetailFetches.has(workflowId)) {
+ continue;
+ }
+ scheduledDetailFetches.add(workflowId);
+
const hasExistingDetail = query?.state.data !== undefined && query.state.data !== null;
if (!hasExistingDetail) {
@@ -375,6 +388,7 @@ export const CallSavedWorkflowSyncRuntime = () => {
});
const unsubscribeLibrary = onWorkflowLibraryCacheInvalidated((workflowId) => {
if (workflowId) {
+ revokeNodeRetries(workflowId);
authorizeWorkflowRetry(workflowId);
void queryClient.invalidateQueries({
exact: true,
@@ -382,6 +396,7 @@ export const CallSavedWorkflowSyncRuntime = () => {
refetchType: 'none',
});
} else {
+ revokeNodeRetries();
for (const query of queryClient.getQueryCache().findAll({ queryKey: ['workflow', 'call-saved', 'detail'] })) {
if (isSavedWorkflowDetailQueryKey(query.queryKey)) {
authorizeWorkflowRetry(query.queryKey[3]);
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index 531d130284..03e19a154f 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -580,7 +580,7 @@ const addNotification = (state: WorkbenchState, notification: WorkbenchNotificat
return { ...state, notifications: [notification, ...state.notifications].slice(0, NOTIFICATION_LIMIT) };
};
-/** Adds the "Invocation queued" notice iff the reduction actually grew that project's queue. */
+/** Adds queue feedback iff the reduction actually grew that project's queue. */
const withEnqueueNotification = (
state: WorkbenchState,
nextState: WorkbenchState,
@@ -595,26 +595,27 @@ const withEnqueueNotification = (
const queueItem = after.queue.items[0];
- if (
+ const metadataOmitted =
queueItem?.snapshot.sourceId === 'workflow' &&
queueItem.snapshot.backendSubmission.kind === 'workflow' &&
- !queueItem.snapshot.backendSubmission.workflow
- ) {
- return addNotification(
- nextState,
- createNotification({
- kind: 'info',
- message: 'Workflow metadata was omitted because the workflow contains multiple workflow_return nodes.',
- messageKey: 'workflowLibrary.workflowMetadataOmittedBody',
- projectId: after.id,
- title: 'Workflow metadata omitted',
- titleKey: 'workflowLibrary.workflowMetadataOmitted',
- })
- );
- }
+ !queueItem.snapshot.backendSubmission.workflow;
+
+ const withMetadataNotice = metadataOmitted
+ ? addNotification(
+ nextState,
+ createNotification({
+ kind: 'info',
+ message: 'Workflow metadata was omitted because the workflow contains multiple workflow_return nodes.',
+ messageKey: 'workflowLibrary.workflowMetadataOmittedBody',
+ projectId: after.id,
+ title: 'Workflow metadata omitted',
+ titleKey: 'workflowLibrary.workflowMetadataOmitted',
+ })
+ )
+ : nextState;
return addNotification(
- nextState,
+ withMetadataNotice,
createNotification({
category: 'enqueue',
kind: 'success',