Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Cancelling a collected stream throws noSnapshots instead of CancellationError

Đang mở Phù hợp với người mới
#361 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@akbashev đang làm issue này rồi.

Từ ngày 22/10/2026.

  • #362 của @akbashev — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
87/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
swift
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Đọc LanguageModelSession.swift và kiểm tra dòng cuối của ResponseStream.collect(), nơi ResponseStreamError.noSnapshots được ném ra. Thêm kiểm tra hủy trước khi ném lỗi đó, rồi chạy các bài kiểm thử liên quan đến việc hủy hoặc thu thập stream. Hoàn tất khi việc hủy thu thập trước snapshot đầu tiên ném ra CancellationError, còn một stream rỗng không bị hủy vẫn báo noSnapshots.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Cancelling the task that collects a streamed response throws ResponseStreamError.noSnapshots instead of CancellationError, so a caller can't tell a cancelled response from one that produced nothing.

let task = Task { try await session.streamResponse(to: "Hi").collect() }
// …before the first snapshot arrives:
task.cancel()
try await task.value  // throws ResponseStreamError.noSnapshots

When the collecting task is cancelled, the stream's iterator ends without an error, as AsyncThrowingStream's does, so ResponseStream.collect() sees no snapshot and reaches throw ResponseStreamError.noSnapshots (LanguageModelSession.swift, the last line of collect()). The session's own streaming task already checks for cancellation before it does the same (// AsyncThrowingStream may end normally when its task is cancelled.), but collect() doesn't.

A try Task.checkCancellation() before that throw in collect() would make it throw CancellationError, as respond does when cancelled.

I hit it while testing #340 with a transport whose body stalls until it's cancelled; it's the same on main. Happy to open a PR if you'd like.

Ngôn ngữ chính
Swift
Star
959
Fork
99
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
59

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của huggingface/AnyLanguageModel

Tất cả issue của huggingface/AnyLanguageModel

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.