From 812312c6a08a8c454c308f5499b8816b7bf375d8 Mon Sep 17 00:00:00 2001 From: Lyndz Williams Date: Thu, 9 Jul 2026 16:18:36 +0100 Subject: [PATCH] fix: keep docker ps off the discord.py event loop in status_cog StatusCog.status() is a discord.py command coroutine and it called subprocess.run(["docker","ps"], timeout=10) directly. On the bot's event loop that stalls the gateway heartbeat and every other command for the duration. Wrap it in asyncio.to_thread. FileNotFoundError, TimeoutExpired and the generic handler below all still catch, since to_thread re-raises in the awaiting coroutine. Verified inside the running broski-bot container (discord.py 2.4.0) by loading the module and driving StatusCog.status.callback with a fake context, against the pre-fix code as a control: control fixed 2s blocking subprocess 1999.9ms 1.7ms real call, no docker CLI same embed same embed The real call still returns "Docker CLI not found", proving the exception path survives the thread hop. Scope, stated plainly: this cog is NOT loaded. cogs.status_cog is absent from the COGS list in cogs/bot.py and nothing imports it. The image also ships no docker CLI, so even if it were loaded the subprocess would fail fast rather than block. This fix is correctness insurance for whenever someone wires the cog up -- it is not repairing a live fault. Co-Authored-By: Claude Opus 4.8 --- agents/broski-bot/cogs/status_cog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agents/broski-bot/cogs/status_cog.py b/agents/broski-bot/cogs/status_cog.py index 9e408168..9b4134d5 100644 --- a/agents/broski-bot/cogs/status_cog.py +++ b/agents/broski-bot/cogs/status_cog.py @@ -10,6 +10,7 @@ - 4 spaces indent """ +import asyncio import discord from discord.ext import commands import subprocess @@ -36,7 +37,10 @@ async def status(self, ctx): ) try: - result = subprocess.run( + # subprocess.run blocks for up to 10s. On discord.py's loop that + # stalls the gateway heartbeat and every other command with it. + result = await asyncio.to_thread( + subprocess.run, [ "docker", "ps", "--format",