@@ -252,10 +252,16 @@ func (m *languageModel) Stream(ctx context.Context, call fantasy.Call) (fantasy.
252252 continue
253253 }
254254 }
255− if err := scanner.Err(); err != nil &&
256− !errors.Is(err, context.Canceled) &&
257− !errors.Is(err, context.DeadlineExceeded) {
258− yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
255+ if err := scanner.Err(); err != nil {
256+ if sawFinish && (errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)) {
257+ // If we already saw an explicit finish event, treat cancellation as a no-op.
258+ } else {
259+ _ = yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
260+ return
261+ }
262+ }
263+ if err := ctx.Err(); err != nil && !sawFinish {
264+ _ = yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
259265 return
260266 }
261267 // flush any pending data