Primary finding
OpenAI streaming: abort does not cancel the reader/stream, risking wasted tokens and network work
- src/providers/openai.ts:63-69
- src/providers/openai.ts:101-103
On abort, the loop breaks but the ReadableStream isn’t canceled, and the underlying fetch may continue server-side generation until completion if the AbortSignal wasn’t already triggered in time. This can continue accruing token charges and network usage. Explicitly canceling the reader (and/or aborting the fetch) stops consumption promptly.
Recommendation
When options.signal?.aborted is detected, call reader.cancel(). Also ensure the same AbortSignal actually aborts the fetch after the response starts; if not, wrap fetch with your own AbortController and abort it on user signal and on early return. Example: if (options.signal?.aborted) { await reader.cancel().catch(()=>{}); break; } and in finally also guard-cancel if aborted.