express route isn't receiving abort signal from useChat
Description
We're observing that when a client executes the stop function from the useChat hook it closes the request, but it doesn't actually communicate an abort signal to the server.
We can do something like this to abort, but we need a way to differentiate user-initiated aborts vs. the request closing for other reasons.
res.on('close', () => {
controller.abort();
});
If I look at the raw request that Express is receiving, it doesn't appear to have the signal populated.
Not sure if the stopping streams documentation is still accurate for v5.
https://ai-sdk.dev/docs/advanced/stopping-streams
AI SDK Version
- ai: 5.0.39
- express: 5.1.0
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
I encountered the same problem, the stop on useChat is not working
Identify issue type
{
"evidence": [
"Reporter says calling `stop` from `useChat` closes the request but does not communicate an abort signal to the Express server route.",
"They state the raw Express request does not appear to have the signal populated and question whether the v5 stopping-streams documentation is accurate.",
"A commenter reports the same problem: “the stop on useChat is not working.”"
],
"rationale": "The issue describes a concrete current-behavior failure where `useChat` stop/abort handling is not observable by the server as expected, potentially contradicting documented stopping-stream behavior.",
"type": "bug",
"confidence": "medium"
}
Bug Reproduction
Issue report appears invalid.
Target branch: main
- The report assumes a client-side
AbortSignalshould appear asreq.signalon an Express request, but Express uses Node.jshttp.IncomingMessage, not the WebRequestAPI. - The AI SDK stopping-streams example forwards
req.signalfrom a Web APIRequest; it does not document that property for Express requests. useChat.stop()aborts the Fetch request, which communicates transport termination to Express rather than transmitting anAbortSignalobject or its user-initiated reason.- Distinguishing an explicit stop from a tab close or network disconnect requires an application-level cancellation message or endpoint.
Relevant Documentation
- https://ai-sdk.dev/docs/advanced/stopping-streams
- https://ai-sdk.dev/docs/ai-sdk-ui/chatbot
- https://expressjs.com/en/5x/guide/overriding-express-api/
- https://nodejs.org/api/http.html
- https://fetch.spec.whatwg.org/
Invalid. Closing as not planned.