From 4525869a755ae8f459e8fc470ee29d911581d420 Mon Sep 17 00:00:00 2001 From: majdyz Date: Fri, 10 Apr 2026 13:34:01 +0000 Subject: [PATCH] fix(executor): wrap _handle_low_balance in to_thread to avoid blocking The post-execution low-balance check in on_node_execution called _handle_low_balance directly. _handle_low_balance does sync DB work, and on_node_execution is async, so the call blocked the event loop. Sentry caught it. Wrap in asyncio.to_thread. Co-Authored-By: Claude Opus 4.6 (1M context) --- autogpt_platform/backend/backend/executor/manager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.py index d9c2f71198..bb7f29a9a1 100644 --- a/autogpt_platform/backend/backend/executor/manager.py +++ b/autogpt_platform/backend/backend/executor/manager.py @@ -709,7 +709,11 @@ class ExecutionProcessor: ) if extra_cost > 0: execution_stats.extra_cost += extra_cost - self._handle_low_balance( + # Wrap in to_thread — _handle_low_balance does sync DB + # work and we're in an async method, so calling it + # directly would block the event loop. + await asyncio.to_thread( + self._handle_low_balance, db_client=get_db_client(), user_id=node_exec.user_id, current_balance=remaining_balance,