feat(nodes,ui): fix soft locks on session/invocation retrieval #3910
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Have you discussed this change with the InvokeAI team?
Have you updated all relevant documentation?
Description
When a queue item is popped for processing, we need to retrieve its session from the DB. Pydantic serializes the graph at this stage.
It's possible for a graph to have been made invalid during the graph preparation stage (e.g. an ancestor node executes, and its output is not valid for its successor node's input field).
When this occurs, the session in the DB will fail validation, but we don't have a chance to find out until it is retrieved and parsed by pydantic.
This logic was previously not wrapped in any exception handling.
Just after retrieving a session, we retrieve the specific invocation to execute from the session. It's possible that this could also have some sort of error, though it should be impossible for it to be a pydantic validation error (that would have been caught during session validation). There was also no exception handling here.
When either of these processes fail, the processor gets soft-locked because the processor's cleanup logic is never run. (I didn't dig deeper into exactly what cleanup is not happening, because the fix is to just handle the exceptions.)
This PR adds exception handling to both the session retrieval and node retrieval and events for each:
session_retrieval_errorandinvocation_retrieval_error.These events are caught and displayed in the UI as toasts, along with the type of the python exception (e.g.
Validation Error). The events are also logged to the browser console.Related Tickets & Documents
Closes #3860 , #3412
QA Instructions, Screenshots, Recordings
Create an valid graph that will become invalid during execution. Here's an example:

This is valid before execution, but the
widthfield of theNoisenode will end up with an invalid value (0). Previously, this would soft-lock the app and you'd have to restart it.Now, with this graph, you will get an error toast, and the app will not get locked up.
Added/updated tests?
@Kyle0654 @brandonrising
It seems because the processor runs in its own thread,
pytestcannot catch exceptions raised in the processor.I added a test that does work, insofar as it does recreate the issue. But, because the exception occurs in a separate thread, the test doesn't see it. The result is that the test passes even without the fix.
So when running the test, we see the exception:
But
pytestdoesn't actually see it as an exception. Not sure how to fix this, it's a bit beyond me.[optional] Are there any post deployment tasks we need to perform?
nope don't think so