fix(run): isolate command dispatch exceptions from detection loop

Any exception in _dispatch_command (status, ss, etc.) was leaking out of the
asyncio.QueueEmpty try/except, crashing _detection_loop and cancelling the
poller — making the bot permanently unresponsive for the rest of the session.

Separate the queue-empty check from the dispatch into two try blocks.
Dispatch errors now log to audit + print to terminal + send a Telegram warn.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-17 11:29:42 +00:00
parent 0f7dd5dc84
commit 3b40aed939

View File

@@ -846,9 +846,15 @@ async def run_live_async(cfg, duration_s=None, capture_stub: bool = False) -> No
while True:
try:
cmd = cmd_queue.get_nowait()
await _dispatch_command(cmd)
except asyncio.QueueEmpty:
break
try:
await _dispatch_command(cmd)
except Exception as _cmd_exc:
_msg = f"/{cmd.action}: {_cmd_exc}"
audit.log({"ts": time.time(), "event": "command_error", "action": cmd.action, "error": str(_cmd_exc)})
print(f"ERR command_dispatch {_msg}", flush=True)
notifier.send(Alert(kind="warn", title=f"Eroare comandă /{cmd.action}", body=str(_cmd_exc)))
await asyncio.sleep(cfg.loop_interval_s)