From 0df917e243992f2ada861b884b212488ae064bba Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Thu, 22 Jan 2026 17:33:52 -0500 Subject: [PATCH] fix(hitl): Expose check_approval through database manager client Fixed "Client is not connected to the query engine" error when check_approval is called from block execution context. The function is now accessed through the database manager async client (RPC), similar to other HITL methods like get_or_create_human_review. Changes: - Add check_approval to DatabaseManager and DatabaseManagerAsyncClient - Update HITLReviewHelper to call check_approval via database client - Remove direct import of check_approval in review.py --- .../backend/backend/blocks/helpers/review.py | 9 +++++++-- autogpt_platform/backend/backend/executor/database.py | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/helpers/review.py b/autogpt_platform/backend/backend/blocks/helpers/review.py index 11e0c68e06..3cdd70bfd2 100644 --- a/autogpt_platform/backend/backend/blocks/helpers/review.py +++ b/autogpt_platform/backend/backend/blocks/helpers/review.py @@ -10,7 +10,7 @@ from prisma.enums import ReviewStatus from pydantic import BaseModel from backend.data.execution import ExecutionStatus -from backend.data.human_review import ReviewResult, check_approval +from backend.data.human_review import ReviewResult from backend.executor.manager import async_update_node_execution_status from backend.util.clients import get_database_manager_async_client @@ -28,6 +28,11 @@ class ReviewDecision(BaseModel): class HITLReviewHelper: """Helper class for Human-In-The-Loop review operations.""" + @staticmethod + async def check_approval(**kwargs) -> Optional[ReviewResult]: + """Check if there's an existing approval for this node execution.""" + return await get_database_manager_async_client().check_approval(**kwargs) + @staticmethod async def get_or_create_human_review(**kwargs) -> Optional[ReviewResult]: """Create or retrieve a human review from the database.""" @@ -90,7 +95,7 @@ class HITLReviewHelper: # This function only handles checking for existing approvals. # Check if this node has already been approved (normal or auto-approval) - approval_result = await check_approval( + approval_result = await HITLReviewHelper.check_approval( node_exec_id=node_exec_id, graph_exec_id=graph_exec_id, node_id=node_id, diff --git a/autogpt_platform/backend/backend/executor/database.py b/autogpt_platform/backend/backend/executor/database.py index ac381bbd67..4bdf94c3fa 100644 --- a/autogpt_platform/backend/backend/executor/database.py +++ b/autogpt_platform/backend/backend/executor/database.py @@ -50,6 +50,7 @@ from backend.data.graph import ( validate_graph_execution_permissions, ) from backend.data.human_review import ( + check_approval, get_or_create_human_review, has_pending_reviews_for_graph_exec, update_review_processed_status, @@ -190,6 +191,7 @@ class DatabaseManager(AppService): get_user_notification_preference = _(get_user_notification_preference) # Human In The Loop + check_approval = _(check_approval) get_or_create_human_review = _(get_or_create_human_review) has_pending_reviews_for_graph_exec = _(has_pending_reviews_for_graph_exec) update_review_processed_status = _(update_review_processed_status) @@ -313,6 +315,7 @@ class DatabaseManagerAsyncClient(AppServiceClient): set_execution_kv_data = d.set_execution_kv_data # Human In The Loop + check_approval = d.check_approval get_or_create_human_review = d.get_or_create_human_review update_review_processed_status = d.update_review_processed_status