OllamaModelBackend: use TaskGroup for structured cancellation in generate_from_raw

オープン
#1,164 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
静か
技術スタック
ollama, python
領域
backend

調査の方向性

Start in OllamaModelBackend.generate_from_raw, where the asyncio.gather call from PR #1163 runs the parallel Ollama requests. The issue proposes replacing it with an asyncio.TaskGroup so that one failure cancels the remaining requests. Decide how callers that catch ConnectionError will handle the ExceptionGroup, then confirm that a failed request cancels the others.

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

説明

area/backends enhancement p2

Background

PR #1163 fixed generate_from_raw to propagate exceptions instead of silently swallowing them into empty ModelOutputThunk(value="") (issue #597). The fix uses asyncio.gather(*coroutines) (default return_exceptions=False).

Problem

With asyncio.gather(return_exceptions=False), when one coroutine raises, the other in-flight coroutines are not cancelled — they continue running on the event loop until completion, but their results are discarded. For N parallel Ollama HTTP requests, this means up to N−1 requests complete and their results are thrown away.

This is a pre-existing behaviour of asyncio.gather made visible by the fix in #1163. It was not introduced by that PR; under the old code all N tasks always ran to completion (whether they failed or not).

Desired behaviour

Python 3.12 (the project's minimum version) has asyncio.TaskGroup, which provides structured concurrency: if any task in the group raises, the remaining tasks are cancelled. This avoids wasted compute and network bandwidth.

async with asyncio.TaskGroup() as tg:
    tasks = [tg.create_task(co) for co in coroutines]
responses = [t.result() for t in tasks]

Caveats

  • TaskGroup raises ExceptionGroup (not the raw exception) on failure. Callers that do except ConnectionError would need to use except* or ExceptionGroup handling. This is a semantic change on top of the change in #1163.
  • Consider whether to unwrap single-exception groups to preserve the plain-exception API surface.

Related

  • Closes #597 (via #1163)
  • PR #1163 — introduced gather without return_exceptions
主要言語
Python
スター
1.8k
フォーク
161
平均マージ
4日 3時間
マージ済み PR(30日)
45

環境構築

はじめの一歩

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

generative-computing/mellea のほかの issue

generative-computing/mellea の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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