fix(ai): Fix error propagation during setup #15379
Merged
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.
I found that in certain edge case situations, errors could end up not propagating up during the initial setup of a live session. While fixing said error, I realized that the setup process could actually be cleaned up a decent amount. While this could cause issues if the model ever sent messages out of order (ie; a message before setupComplete), this doesn't seem like something we should necessarily design around. Furthermore, separating the setup process into a more iterative async style approach not only makes things easier to read (and reason about), but also solves various edge case error propagation issues.
The change has been tested on a local device, and seems to be working perfectly; existing functionality works, and the errors that were previously not being propagated are now properly bubbling up.
The process has also been split into helper functions, to make things easier to read, and to allow me to add documentation for each.
#no-changelog