genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[JS] startFlowServer => Whenever flows fail; it doesn’t recover

Open huangjeff5 opened this issue 1 year ago • 3 comments

If you deploy a flow as a server via Cloud Functions, and the flow crashes, it doesn't seem to recover automatically. All future calls to the server don't seem to trigger the handler correctly.

huangjeff5 avatar Feb 21 '25 20:02 huangjeff5

Fail how, an exception? Do you have a way to reproduce this?

apascal07 avatar Feb 21 '25 20:02 apascal07

I can add some color here, since I brought this up with @huangjeff5. This is kind of a tough one to predictably reproduce, but the TLDR is that whenever there's an error in my flow server, it can't recover without restarting the server. Some examples I've run into include GenkitError: INVALID_ARGUMENT: Schema validation failed, JSON parsing errors when the response comes back in an unexpected format, which happens from time to time since it's hard to consistently and predictably return the correct format 100% of the time, and streaming errors.

I've been able to mitigate this in some capacity with try/catch blocks. For example, I have a flow that generates an image and returns the image URL, and I can just return a string and handle that client side in the event of an error. However, there are often times when I just want to send an error to the client without the server crashing.

There are some patterns to handle this in a regular express server, but it's not clear how to do this sort of thing in the flow server. In addition, if you simply throw an error like this

app.get('/', (req, res) => {
  throw new Error('BROKEN') // Express will catch this on its own.
})

express doesn't catch the error on its own in the flow server, and it crashes.

devchas avatar Feb 25 '25 19:02 devchas

Hi @devchas , does this happen to you using Cloud Functions?

lperezp avatar Mar 02 '25 07:03 lperezp