OllamaModelBackend: use TaskGroup for structured cancellation in generate_from_raw
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 内容生成。
描述
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
TaskGroupraisesExceptionGroup(not the raw exception) on failure. Callers that doexcept ConnectionErrorwould need to useexcept*orExceptionGrouphandling. 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
gatherwithoutreturn_exceptions
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 161
- 平均合并
- 4 天 4 小时
- 30 天内合并 PR
- 47
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
generative-computing/mellea 的其他 Issue
-
bug(cli): intrinsic_uploader builds path_in_repo with os.path.join, producing backslashes on Windows未关闭
难度 1/5 1 小时以内 新手友好度 84/100
generative-computing/mellea#1870 ·
维护者通常 3 天内回复
-
难度 2/5 1 小时以内 新手友好度 82/100
generative-computing/mellea#1869 ·
维护者通常 3 天内回复
-
bug(backends): tool-call JSON nested under a non-first dict key is silently dropped by find_func未关闭
难度 2/5 1-3 小时 新手友好度 82/100
generative-computing/mellea#1867 ·
维护者通常 3 天内回复
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknown可能已有人在做 @mvanhorn 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
generative-computing/mellea#1864 · 2 条评论 ·
维护者通常 3 天内回复
-
bug: instruct() and react() replay tool-call turns without tool_calls可能已有人在做 @simonyang08 于 22 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
generative-computing/mellea#1784 · 1 条评论 ·
维护者通常 3 天内回复
查看 generative-computing/mellea 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
vllm-project/vllm#69791 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
BCStudentSoftwareDevTeam/cas#481 ·
维护者通常 7 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复