How to handle hanging connection conditions

so im developing the api that use response api gpt stream, all happy case works, now there is some edge cases figured out, for example while the response api running and its call function, the function is expecting the output but suddenly the client is close the connection and the process ended unexpectedly, on background the conversation is not finish because when call function gpt need output or result, on this case they dont get the results, and the conversation crash and cant send message anymore, the erorr is like this 400 No tool output found for function call call_pdo1ps5u2eKa1ynrzdOMtLp7." how to prevent this behavior? any advice?
i use nodejs sdk now

If you are using the “conversations” API, and it is left after a malfunction at the AI emitting a tool call which requires a matching ID be returned, either by the internal tool or by your function, you will need to recover from that.

For this specific case of receiving such an error message body as ‘no tool output’, and it being a tool call you cannot satisfy by running and returning a function call, a solution:

  • you could make a request to retrieve the full conversation item list, with all the “include” methods that are available on the listing endpoint. Then start stripping out the tail of message IDs with “delete”, up until the most recent is user role input, until it will run successfully without an open tool call request.
  • Another: load the sequence of user and assistant seen messages (without the internals of tools) to a new conversation, one where the list ends with the latest user input, and run it again.