[Bug] TaskTracker _runs zombie entries inflate running_task_count, disagree with /api/chats
Summary
The QwenPaw dashboard reports "2 running tasks", but the chat list API returns only 1 chat with status="running". The aggregate counter (task_tracker.get_global_status()) and the per-chat counter (tracker.get_status(chat_id)) appear to use different scopes, so the dashboard count can disagree with the per-chat view. This affects dashboard display and third-party plugins that rely on the aggregate status.
Environment
| Field | Value |
|---|---|
| QwenPaw version | 2.2.1 |
| OS | macOS (arm64) |
| Runtime | asyncio; qwenpaw.app.task_tracker.TaskTracker |
| Session age | ~4 days continuous uptime |
Observed Behavior
1. Dashboard shows 2 running tasks (local observation).
2. /api/chats?archived=false returns only 1 running chat:
17 chats total, 1 with status="running"
id=b3d07558-a0ae-4578-a01a-2cf305b03c2e
name="Mini CPM desk pet linked QwenPaw plugin design"
status=running
updated=2026-09-26T10:53:09Z3. Memory subsystem ruled out:
{"worker": {"status": "idle", "queue_pending": 0, "tasks_running": 0}}4. All 10 agents report startup_status="running".
Code Analysis
Aggregate counter - task_tracker.get_global_status()
qwenpaw/app/task_tracker.py:
# Line 58
self._runs: dict[str, _RunState] = {}
# Lines 85-87
running_count = sum(
1 for state in self._runs.values() if not state.task.done()
)
status = "running" if running_count > 0 else "idle"Counts every entry in _runs, regardless of whether its run_key maps to a live chat.
Per-chat counter - used by listChats
qwenpaw/app/chats/api.py (about line 317):
status = await tracker.get_status(spec.id)task_tracker.get_status():
async def get_status(self, run_key: str) -> Literal["idle", "running"]:
async with self._lock:
state = self._runs.get(run_key)
if state is None or state.task.done():
return "idle"
return "running"Entry lifecycle - potential zombie path
# 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
async 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:
- Entry written before producer starts (line 281 to 342): if the producer fails to start in that window, the placeholder
Future()(neverdone()) remains in_runsand is counted byget_global_status()forever. - Cleanup is gated by a weakref (line 283 / 337): if
tracker_ref()cannot reach the tracker at cleanup time,_runs.popis skipped. get_global_status()does not validate entry liveness - it only checkstask.done(), so stale entries are counted indefinitely.
Hypothesis
The discrepancy is most likely a scope mismatch: get_global_status() counts all _runs entries (including sub-agent runs, cron-triggered runs, or runs belonging to deleted/archived chats), while listChats only reports status for live chat ids. A secondary possibility is that a placeholder Future() survives in _runs when the producer fails between lines 281 and 342.
Impact
| Area | Effect |
|---|---|
| Dashboard | Shows a running-task count that does not match the chat list |
| Agent status API | GET /api/agents/{id} reports startup_status="running" even without a visible active chat |
| Third-party plugins | Plugins reading task_tracker status may display "working" state for sessions the chat view considers idle |
Questions
- Is counting all
_runsentries inget_global_status()intentional, or should it be restricted to live chat ids? - Is there a supported way to inspect
_runscontents (debug endpoint / log line)? - Should
get_global_status()filter out entries whosetaskis a placeholderFuturethat was never replaced? - Could
_runs.popcleanup be made unconditional (independent of the tracker being reachable via weakref)?
Source: agentscope-ai/QwenPaw