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:
@@ -10,6 +10,7 @@ from utils.autonomous_engine import autonomous_engine
|
||||
from server_manager import server_manager
|
||||
import globals
|
||||
from utils.logger import get_logger
|
||||
from utils.task_tracker import create_tracked_task
|
||||
|
||||
logger = get_logger('autonomous')
|
||||
|
||||
@@ -166,10 +167,10 @@ def on_message_event(message):
|
||||
|
||||
# Check if we should act (async, non-blocking)
|
||||
if not message.author.bot: # Only check for human messages
|
||||
asyncio.create_task(_check_and_act(guild_id))
|
||||
create_tracked_task(_check_and_act(guild_id), task_name="autonomous_check_act")
|
||||
|
||||
# Also check if we should react to this specific message
|
||||
asyncio.create_task(_check_and_react(guild_id, message))
|
||||
create_tracked_task(_check_and_react(guild_id, message), task_name="autonomous_check_react")
|
||||
|
||||
|
||||
async def _check_and_react(guild_id: int, message):
|
||||
|
||||
Reference in New Issue
Block a user