Cancelling a collected stream throws noSnapshots instead of CancellationError
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
huggingface/AnyLanguageModel のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
huggingface/AnyLanguageModel#360 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
huggingface/AnyLanguageModel#359 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
huggingface/AnyLanguageModel#328 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
huggingface/AnyLanguageModel#327 ·
メンテナーはふだん 1 日以内に返信
-
OpenAI Chat Completions: tool rounds drop the model's reasoning対応中かも @gtokman が 2 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
huggingface/AnyLanguageModel#326 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
huggingface/AnyLanguageModel の issue をすべて見る
似ている issue
-
host-ios R2 blocker Stability
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
paritytech/trinity-user-agents#1661 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
logto-io/logto#9837 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area: ios S3: minor
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
manaflow-ai/cmux#24404 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信