Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamUI unhandledRejection: Error: .update(): UI stream is already closed. #3007

Open
ifreeman6 opened this issue Sep 14, 2024 · 9 comments
Labels
ai/rsc bug Something isn't working

Comments

@ifreeman6
Copy link

Description

The StreamUI calling tool reports an error, but the normal output components:

Error: .update(): UI stream is already closed.
at assertStream (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12394:19)
at Object.update (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12412:13)
at handleRender (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12830:21)
at G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12870:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
⨯ unhandledRejection: Error: .update(): UI stream is already closed.
at assertStream (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12394:19)
at Object.update (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12412:13)
at handleRender (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12830:21)
at G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12870:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
⨯ unhandledRejection: Error: .update(): UI stream is already closed.
at assertStream (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12394:19)
at Object.update (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12412:13)
at handleRender (G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c..js:12830:21)
at G:\ai-project\ai-chatbot.next\server\chunks\ssr_39f80c.
.js:12870:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Code example

No response

Additional context

No response

@lgrammel lgrammel added bug Something isn't working ai/rsc labels Sep 16, 2024
@sylviangth
Copy link

Hi @lgrammel Any solution for this issue? My app has been encountering this issue quite frequently lately which made many paid customers frustrated/churned. This issue started occurring several weeks ago already. I couldn't find any workaround fix on my own. This is very urgent. Please help.

@lgrammel
Copy link
Collaborator

This happens when close() has been called on a streamableUI already, e.g. when you have parallel tool calls. streamUI uses this internally, so the cause can be parallel tool calls by the AI.

First try to turn off parallel tool calls (especially w/ openai - see OpenAI provider https://sdk.vercel.ai/providers/ai-sdk-providers/openai ). If that is not sufficient, you can use streamText with your own createStreamableUI instance to have more control, or switch to AI SDK UI.

@sylviangth
Copy link

sylviangth commented Sep 17, 2024

This happens when close() has been called on a streamableUI already, e.g. when you have parallel tool calls. streamUI uses this internally, so the cause can be parallel tool calls by the AI.

First try to turn off parallel tool calls (especially w/ openai - see OpenAI provider https://sdk.vercel.ai/providers/ai-sdk-providers/openai ). If that is not sufficient, you can use streamText with your own createStreamableUI instance to have more control, or switch to AI SDK UI.

@lgrammel How can I turn off parallelToolCalls with createOpenAI? I tried this but it says 'parallelToolCalls' does not exist in type 'OpenAICompletionSettings'

Is there anyway to disable it from the streamUI() function itself?

image

@lgrammel
Copy link
Collaborator

It is available when you use chat models (completion models don't support tool calls to begin with): https://sdk.vercel.ai/providers/ai-sdk-providers/openai#chat-models

@ifreeman6
Copy link
Author

This happens when close() has been called on a streamableUI already, e.g. when you have parallel tool calls. streamUI uses this internally, so the cause can be parallel tool calls by the AI.

First try to turn off parallel tool calls (especially w/ openai - see OpenAI provider https://sdk.vercel.ai/providers/ai-sdk-providers/openai ). If that is not sufficient, you can use streamText with your own createStreamableUI instance to have more control, or switch to AI SDK UI.

It's not okey when I turn off the "parallelToolCalls" config, the error occurs as before.

const openai = createOpenAI({
  baseURL: process.env.OPENAI_API_BASE,
  apiKey: process.env.OPENAI_API_KEY,
})
let openaiApiModel = process.env.OPENAI_API_MODEL || 'gpt-4o'
let model = openai.chat(openaiApiModel, {
  parallelToolCalls: false
})

@lgrammel
Copy link
Collaborator

please try my other suggestions in that case, and also check out this comment: #2810 (comment)

You are seeing this error because you are trying to update an already closed rsc stream (streamableUI).

@ifreeman6
Copy link
Author

I think this is a bug. Please fix it in the next version.

@ifreeman6
Copy link
Author

When i upgrade the latest version of ai, the bug still exists.

@aaron5670
Copy link

Same issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/rsc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants