Skip to content

Commit ecfab29

Browse files
psychedelicioushipsterusername
authored andcommitted
fix(ui): workaround for out-of-order events
1 parent 10fd3e6 commit ecfab29

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApiModule.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ export class CanvasStateApiModule extends CanvasModuleBase {
235235
}): Promise<ImageDTO> => {
236236
const { graph, outputNodeId, destination, prepend, timeout, signal } = arg;
237237

238+
if (!graph.hasNode(outputNodeId)) {
239+
throw new Error(`Graph does not contain node with id: ${outputNodeId}`);
240+
}
241+
238242
/**
239243
* We will use the origin to handle events from the graph. Ideally we'd just use the queue item's id, but there's a
240244
* race condition:
@@ -281,6 +285,7 @@ export class CanvasStateApiModule extends CanvasModuleBase {
281285
if (event.origin !== origin) {
282286
return;
283287
}
288+
284289
// Ignore events that are not from the output node
285290
if (event.invocation_source_id !== outputNodeId) {
286291
return;
@@ -326,8 +331,19 @@ export class CanvasStateApiModule extends CanvasModuleBase {
326331
clearListeners();
327332

328333
if (event.status === 'completed') {
329-
// If we get a queue item completed event, that means we never got a completion event for the output node!
330-
reject(new Error('Queue item completed without output node completion event'));
334+
/**
335+
* The invocation_complete event should have been received before the queue item completed event, and the
336+
* event listeners are cleared in the invocation_complete handler. If we get here, it means we never got
337+
* the completion event for the output node! This should is a fail case.
338+
*
339+
* TODO(psyche): In the unexpected case where events are received out of order, this logic doesn't do what
340+
* we expect. If we got a queue item completed event before the output node completion event, we'd erroneously
341+
* triggers this error.
342+
*
343+
* For now, we'll just log a warning instead of rejecting the promise. This should be super rare anyways.
344+
*/
345+
this.log.warn('Queue item completed without output node completion event');
346+
// reject(new Error('Queue item completed without output node completion event'));
331347
} else if (event.status === 'failed') {
332348
// We expect the event to have error details, but technically it's possible that it doesn't
333349
const { error_type, error_message, error_traceback } = event;

0 commit comments

Comments
 (0)