Chat.makeRequest's finally builds the onFinish argument as:
message: this.activeResponse!.state.message, // packages/ai/src/ui/chat.ts (main: 760)
...
finishReason: this.activeResponse?.state.finishReason,
this.activeResponse can be undefined when that finally runs (e.g. a trigger: 'resume-stream' request that overlaps another makeRequest such that the single shared this.activeResponse was already cleared), so the non-null assertion throws:
Cannot read properties of undefined (reading 'state')
at Chat.makeRequest (packages/ai/src/ui/chat.ts:760)
at async AbstractChat.resumeStream (packages/ai/src/ui/chat.ts:465)
The very next line already guards finishReason with ?., so the ! on message looks like an oversight.
It's caught (the finally wraps onFinish in a try/catch → console.error), so it's non-fatal — but it trips dev error overlays. It surfaces via @cloudflare/ai-chat, which drives client-tool continuations through resumeStream → makeRequest, so it fires on every client-tool continuation. Reproduces on 6.0.19x; not on 6.0.1.
Suggested fix:
- message: this.activeResponse!.state.message,
+ message: this.activeResponse?.state.message,
Happy to PR if useful.
Chat.makeRequest'sfinallybuilds theonFinishargument as:this.activeResponsecan beundefinedwhen thatfinallyruns (e.g. atrigger: 'resume-stream'request that overlaps anothermakeRequestsuch that the single sharedthis.activeResponsewas already cleared), so the non-null assertion throws:The very next line already guards
finishReasonwith?., so the!onmessagelooks like an oversight.It's caught (the
finallywrapsonFinishin a try/catch →console.error), so it's non-fatal — but it trips dev error overlays. It surfaces via@cloudflare/ai-chat, which drives client-tool continuations throughresumeStream → makeRequest, so it fires on every client-tool continuation. Reproduces on6.0.19x; not on6.0.1.Suggested fix:
Happy to PR if useful.