@@ -252,10 +252,16 @@ func (m *languageModel) Stream(ctx context.Context, call fantasy.Call) (fantasy.
255− if err := scanner.Err(); err != nil &&
255+ if err := scanner.Err(); err != nil {
256− !errors.Is(err, context.Canceled) &&
257− !errors.Is(err, context.DeadlineExceeded) {
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.
259+ _ = yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
263+ if err := ctx.Err(); err != nil && !sawFinish {
258− yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
264+ _ = yield(fantasy.StreamPart{Type: fantasy.StreamPartTypeError, Error: err})
261 // flush any pending data
267 // flush any pending data