fix(tasks): replace fire-and-forget asyncio.create_task with create_tracked_task

Add utils/task_tracker.py with create_tracked_task() that wraps background
tasks with error logging, cancellation handling, and reference tracking.

Replace all 17 fire-and-forget asyncio.create_task() calls across 7 files:
- bot/bot.py (5 interjection checks)
- bot/utils/autonomous.py (2 check-and-act/react tasks)
- bot/utils/bipolar_mode.py (3 argument tasks)
- bot/commands/uno.py (1 game loop task)
- bot/utils/voice_receiver.py (3 STT/interruption callbacks)
- bot/utils/persona_dialogue.py (4 dialogue turn/interjection tasks)

Previously-tracked tasks (voice_audio.py, voice_manager.py) were left as-is
since they already store task references for cancellation.

Closes #1
This commit is contained in:
2026-02-18 12:01:08 +02:00
parent cf55b15745
commit 7b7abcfc68
7 changed files with 104 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ import json
import logging
from typing import Optional, Dict, Any
from utils.logger import get_logger
from utils.task_tracker import create_tracked_task
logger = get_logger('uno')
@@ -64,7 +65,7 @@ async def join_uno_game(message: discord.Message, room_code: str):
await message.channel.send(f"✅ Joined room **{room_code}**! Waiting for Player 1 to start the game... 🎮")
# Start the game loop
asyncio.create_task(player.play_game())
create_tracked_task(player.play_game(), task_name=f"uno_game_{room_code}")
else:
await message.channel.send(f"❌ Couldn't join room **{room_code}**. Make sure the room exists and has space!")