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) <noreply@anthropic.com>
This commit is contained in:
majdyz
2026-04-10 13:34:01 +00:00
parent 389b2f4fb2
commit 4525869a75

View File

@@ -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,