Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(rnd): Fix broken server execution update due to split prisma connection to different loops (#7620)

Zamil Majdydfa855f53321
diff --git a/rnd/autogpt_server/autogpt_server/executor/manager.py b/rnd/autogpt_server/autogpt_server/executor/manager.py
index 50334fb9fe..630ad88877 100644
--- a/rnd/autogpt_server/autogpt_server/executor/manager.py
+++ b/rnd/autogpt_server/autogpt_server/executor/manager.py
@@ -17,6 +17,7 @@ from autogpt_server.data.execution import (
create_graph_execution,
merge_execution_input,
parse_execution_output,
+ update_execution_status,
upsert_execution_input,
upsert_execution_output,
)
@@ -60,7 +61,8 @@ def execute_node(
return loop.run_until_complete(f)
def update_execution(status: ExecutionStatus):
- api_client.update_execution_status(node_exec_id, status)
+ exec_update = wait(update_execution_status(node_exec_id, status))
+ api_client.send_execution_update(exec_update.model_dump())
node = wait(get_node(node_id))
if not node:
@@ -128,7 +130,8 @@ def _enqueue_next_nodes(
return loop.run_until_complete(f)
def execution_update(node_exec_id: str, status: ExecutionStatus):
- api_client.update_execution_status(node_exec_id, status)
+ exec_update = wait(update_execution_status(node_exec_id, status))
+ api_client.send_execution_update(exec_update.model_dump())
def register_next_execution(node_link: Link) -> NodeExecution | None:
next_output_name = node_link.source_name
@@ -387,9 +390,10 @@ class ExecutionManager(AppService):
data=node_exec.input_data,
)
)
- self.agent_server_client.update_execution_status(
- node_exec.node_exec_id, ExecutionStatus.QUEUED
+ exec_update = self.run_and_wait(
+ update_execution_status(node_exec.node_exec_id, ExecutionStatus.QUEUED)
)
+ self.agent_server_client.send_execution_update(exec_update.model_dump())
graph_exec = GraphExecution(
graph_exec_id=graph_exec_id,
diff --git a/rnd/autogpt_server/autogpt_server/server/server.py b/rnd/autogpt_server/autogpt_server/server/server.py
index e53ed7dbc8..016a8f144d 100644
--- a/rnd/autogpt_server/autogpt_server/server/server.py
+++ b/rnd/autogpt_server/autogpt_server/server/server.py
@@ -23,10 +23,8 @@ from autogpt_server.data import graph as graph_db
from autogpt_server.data.block import BlockInput, CompletedBlockOutput
from autogpt_server.data.execution import (
ExecutionResult,
- ExecutionStatus,
get_execution_results,
list_executions,
- update_execution_status,
)
from autogpt_server.executor import ExecutionManager, ExecutionScheduler
from autogpt_server.server.conn_manager import ConnectionManager
@@ -599,9 +597,9 @@ class AgentServer(AppService):
return execution_scheduler.get_execution_schedules(graph_id) # type: ignore
@expose
- def update_execution_status(self, exec_id: str, status: ExecutionStatus):
- exec_result = self.run_and_wait(update_execution_status(exec_id, status))
- self.run_and_wait(self.event_queue.put(exec_result))
+ def send_execution_update(self, execution_result_dict: dict[Any, Any]):
+ execution_result = ExecutionResult(**execution_result_dict)
+ self.run_and_wait(self.event_queue.put(execution_result))
@expose
def acquire_lock(self, key: Any):
diff --git a/rnd/autogpt_server/autogpt_server/util/service.py b/rnd/autogpt_server/autogpt_server/util/service.py
index ff55135a6a..5719a8e542 100644
--- a/rnd/autogpt_server/autogpt_server/util/service.py
+++ b/rnd/autogpt_server/autogpt_server/util/service.py
@@ -51,11 +51,11 @@ class AppService(AppProcess):
while True:
time.sleep(10)
- def run_async(self, coro: Coroutine[T, Any, T]):
+ def __run_async(self, coro: Coroutine[T, Any, T]):
return asyncio.run_coroutine_threadsafe(coro, self.shared_event_loop)
def run_and_wait(self, coro: Coroutine[T, Any, T]) -> T:
- future = self.run_async(coro)
+ future = self.__run_async(coro)
return future.result()
def run(self):
@@ -85,7 +85,6 @@ class AppService(AppProcess):
daemon.requestLoop()
def __start_async_loop(self):
- # asyncio.set_event_loop(self.shared_event_loop)
self.shared_event_loop.run_forever()