Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

trajectory_group_batches leaves started rollouts running after close, error or cancellation

未关闭
#1,140 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@salma2vec 已经在做这个了。

开始于 2026年10月22日。

  • #1141 来自 @salma2vec —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Read src/art/batches.py and the assumptions in test_batches_completion_bursts.py. Reproduce the iterator-close case with the supplied asyncio example, then examine cleanup when the generator exits, including error and cancellation paths. Done means started tasks are cancelled and awaited, completed task exceptions are retrieved, and batching, ordering, exception-budget behavior, and ownership of unstarted coroutines remain as described; an open linked pull request already addresses this issue.

由索引模型根据 Issue 内容生成。

描述

art.trajectory_group_batches starts rollouts as asyncio tasks, but it never cancels or awaits them when it stops early. Three ordinary exits leave started rollouts running with no owner:

  • the training loop closes the iterator (break out of async for, or aclose()),
  • a rollout raises past max_batch_exceptions,
  • the task consuming the iterator is cancelled.

The orphaned rollouts keep calling the inference server and stepping environments after the training loop has stopped. In a long-lived event loop (a notebook or a server), nothing cleans them up until they finish on their own.

Reproduced on main at 5f0c1fb, Python 3.12. No model or service needed:

import asyncio
import art

async def main():
    entered, release = asyncio.Event(), asyncio.Event()
    effects = []

    async def slow_rollout():
        entered.set()
        await release.wait()
        effects.append("finished after iterator close")
        return art.TrajectoryGroup([art.Trajectory(reward=1)])

    async def first_rollout():
        await entered.wait()
        return art.TrajectoryGroup([art.Trajectory(reward=0)])

    batches = art.trajectory_group_batches(
        [first_rollout(), slow_rollout()],
        batch_size=1, max_concurrent_batches=2, pbar_desc=None,
    )
    await anext(batches)
    await batches.aclose()
    release.set()
    await asyncio.sleep(0.1)
    print(effects)

asyncio.run(main())

Output: ['finished after iterator close']. Expected: []. After aclose() returns, the second rollout should already be cancelled.

There is a related leak on the error path. When several tasks finish in the same asyncio.wait, task.result() raises on the first failure. The other failed tasks in done are never read, so asyncio logs Task exception was never retrieved for each.

Cause: src/art/batches.py keeps the started tasks in pending and has no try/finally around the loop.

Expected fix: on any exit, cancel and await the tasks the generator started, and retrieve the exceptions of tasks that already finished. Coroutines that were never started stay owned by the caller, as test_batches_completion_bursts.py already assumes. Batching, ordering and exception-budget semantics stay the same. #969 changes the exception budget, not cleanup, so it doesn't overlap.

主要语言
Python
星标
10.8k
派生
1k
平均合并
12 小时 33 分钟
30 天内合并 PR
126

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

OpenPipe/ART 的其他 Issue

查看 OpenPipe/ART 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。