#7991·QwenPaw

[错误] TaskTracker _runs 孤立项会导致 running_task_count 增加,与 /api/chats 不一致

作者: yylxdzz创建于 2026年9月26日更新于 2026年9月30日

Line 276

run = _RunState( task=asyncio.Future(), # placeholder, replaced below …

Line 281 - entry inserted BEFORE the producer task is created

self._runs[run_key] = run

Line 283

tracker_ref = weakref.ref(self) async def _producer() -> None: try: async for sse in stream_fn(payload): … finally: tracker = tracker_ref() if tracker is not None: # conditional cleanup with tracker.lock: tracker._runs.pop(run_key, None) # lines 337-341

Line 342 - the producer task is created AFTER the entry was written

run.task = asyncio.create_task(_producer())

Key observations:

  1. Entry written before producer starts (lines 281 to 342): if the producer fails to start in that window, the placeholder Future() (never done()) remains in _runs and is counted by get_global_status() forever.
  2. Cleanup is gated by a weakref (lines 283 / 337): if

内容来源: agentscope-ai/QwenPaw