Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Cancelling a collected stream throws noSnapshots instead of CancellationError

オープン 初心者向け
#361 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@akbashev がすでに取り組んでいます。

2026年10月22日 から。

  • #362 @akbashev による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
87/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
swift

調査の方向性

LanguageModelSession.swiftを読み、ResponseStream.collect()の最後の行でResponseStreamError.noSnapshotsがスローされる箇所を確認します。そのスローの前にキャンセルチェックを追加し、関連するキャンセルまたはストリーム収集のテストを実行します。最初のスナップショットより前に収集をキャンセルするとCancellationErrorがスローされ、キャンセルされていない空のストリームでは引き続きnoSnapshotsが報告されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Swift
スター
959
フォーク
99
平均マージ
1日 6時間
マージ済み PR(30日)
59

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

huggingface/AnyLanguageModel のほかの issue

huggingface/AnyLanguageModel の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。