agent.generate() with structuredOutput.model throws "promise 'text' was not resolved or rejected
Description:
Seeing an error when using agent.generate() with structured output that includes a model field. The stream finishes before the "finish" chunk resolves the text promise, causing a rejection.
Error:
Code Sample:
Observations:
- Occurs when structuredOutput.model is set (processor mode)
- Does not occur when structuredOutput.model is omitted (direct mode)
- The stream's flush() method rejects pending promises before the "finish" chunk resolves them
- Using agent.stream() + consumeStream() + getFullOutput() works as a workaround
Environment:
- @mastra/core version: 0.24.6
- Node.js version: 22
Is this a known issue or am I missing something?
5 Replies
I've tried removing the model on structuredOutput too, still getting the same error
Hey @Navayuvan Subramanian ! I was able to run the code you pasted without running into any error. (
@mastra/core@0.24.6, node v22.21.1)
Is it still erroring out on your end?Yes, but for now I've downgraded to 0.21 and it got fixed.
Will check again.
š Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10857
š If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly.
š Thank you for helping us improve Mastra!
Hey @Navayuvan Subramanian I wasn't able to repro this exactly with the code you shared but I was able to see this error when there was a previous error in the stream. Did you see any other error message above this one?
For example if I called
agent.generate with toolChoice trying to call a tool that doesn't exist, the stream will end with an error like this
The error message Error: promise 'text' was not resolved or rejected when stream finished would be thrown from agent.generate since it was awaiting the text promise. This promise should've been rejected earlier in the loop with the first error though so now I'm looking into why that wasn't happening.