Fallback to sync invocation if streaming fails#135
Fallback to sync invocation if streaming fails#135hubertzub-db wants to merge 5 commits intodatabricks:mainfrom
Conversation
d922582 to
cd37de4
Compare
| * Reads all chunks from a UI message stream, forwarding non-error parts to the | ||
| * writer. Returns whether the stream encountered any errors. | ||
| */ | ||
| async function drainStreamToWriter( |
There was a problem hiding this comment.
note: unfortunately we have to merge the streams manually, otherwise we won't have enough control to transparently switch over to fallback :/
cd37de4 to
b4de3b8
Compare
| * Reads all chunks from a UI message stream, forwarding non-error parts to the | ||
| * writer. Returns whether the stream encountered any errors. | ||
| */ | ||
| async function drainStreamToWriter( |
There was a problem hiding this comment.
ah sorry i think i wasn't clear, but we only want to try the non-streaming path if the streaming path never starts -- for errors that are within the stream itself, we do not want to falback right? this could result in duplicate content
There was a problem hiding this comment.
ex. when there is a network disconnect, we shouldn't be retrying the synchronous path, we should be trying to resume the stream.
pr looking at how the stream resumption works for context: #121
we could maybe? look at whether or not any content was emitted (ex. there was never a SSE w/ content in it?)
There was a problem hiding this comment.
ah sorry i think i wasn't clear, but we only want to try the non-streaming path if the streaming path never starts
If the streaming never starts because agent's streaming handler crashes at the beginning, then the chunk.value.type in middleware's drainStreamToWriter loop will have be set to error. That's due to agent framework/aisdk detecting a chunked stream even if the agent's stream function was never registered. In other words, even if agent<->middleware streaming completely fails at the very start, then the stream is still detected and passes initial messages (handshakes etc).
There was a problem hiding this comment.
hmm since that's not trivial, maybe let's discuss this offline
bbqiu
left a comment
There was a problem hiding this comment.
thank you for working on this! i wasn't clear in specifying what type of fallback we wanted, but if it's possible to only fallback when the stream doesn't start in the first place, that would be very helpful
also, once we make the change, if we could write a playwright integration test for this, that would be super helpful
370f32b to
5b66ad9
Compare
5b66ad9 to
f262d66
Compare
|
@bbqiu I've
|
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
Signed-off-by: Hubert Zub <hubert.zub@databricks.com>
9b9b671 to
940cdb3
Compare
Summary
writer.merge()approach with a manualdrainStreamToWriterhelper that reads chunks individually, detects errors, and triggers the fallback path when needed.Demo/test (simulated error in agent's
stream_handler)stream-fallback.mov
Regression test (streaming still works)
stream-regression.mov
Demo of complete failure (both
stream_handlerandinvoke_handlerin agent are failing)stream-complete-failure.mov
Test plan
data-errormessage