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(backend): Filter Redis messages by user ID (#9697)
Reinier van der Leer9077323b8914
diff --git a/autogpt_platform/backend/backend/blocks/agent.py b/autogpt_platform/backend/backend/blocks/agent.pyindex 30e8743a6d..f278d039a2 100644--- a/autogpt_platform/backend/backend/blocks/agent.py+++ b/autogpt_platform/backend/backend/blocks/agent.py@@ -88,7 +88,9 @@ class AgentExecutorBlock(Block):logger.info(f"Starting execution of {log_id}")for event in event_bus.listen(- graph_id=graph_exec.graph_id, graph_exec_id=graph_exec.graph_exec_id+ user_id=graph_exec.user_id,+ graph_id=graph_exec.graph_id,+ graph_exec_id=graph_exec.graph_exec_id,):logger.info(f"Execution {log_id} produced input {event.input_data} output {event.output_data}"diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex 397187d5f5..e4db2c94f7 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -579,13 +579,13 @@ class RedisExecutionEventBus(RedisEventBus[ExecutionResult]):return config.execution_event_bus_namedef publish(self, res: ExecutionResult):- self.publish_event(res, f"{res.graph_id}/{res.graph_exec_id}")+ self.publish_event(res, f"{res.user_id}/{res.graph_id}/{res.graph_exec_id}")def listen(- self, graph_id: str = "*", graph_exec_id: str = "*"+ self, user_id: str, graph_id: str = "*", graph_exec_id: str = "*") -> Generator[ExecutionResult, None, None]:- for execution_result in self.listen_events(f"{graph_id}/{graph_exec_id}"):- yield execution_result+ for event in self.listen_events(f"{user_id}/{graph_id}/{graph_exec_id}"):+ yield eventclass AsyncRedisExecutionEventBus(AsyncRedisEventBus[ExecutionResult]):@@ -596,10 +596,12 @@ class AsyncRedisExecutionEventBus(AsyncRedisEventBus[ExecutionResult]):return config.execution_event_bus_nameasync def publish(self, res: ExecutionResult):- await self.publish_event(res, f"{res.graph_id}/{res.graph_exec_id}")+ await self.publish_event(+ res, f"{res.user_id}/{res.graph_id}/{res.graph_exec_id}"+ )async def listen(- self, graph_id: str = "*", graph_exec_id: str = "*"+ self, user_id: str, graph_id: str = "*", graph_exec_id: str = "*") -> AsyncGenerator[ExecutionResult, None]:- async for execution_result in self.listen_events(f"{graph_id}/{graph_exec_id}"):- yield execution_result+ async for event in self.listen_events(f"{user_id}/{graph_id}/{graph_exec_id}"):+ yield eventdiff --git a/autogpt_platform/backend/backend/server/ws_api.py b/autogpt_platform/backend/backend/server/ws_api.pyindex d826ee8364..2bb3af7a2c 100644--- a/autogpt_platform/backend/backend/server/ws_api.py+++ b/autogpt_platform/backend/backend/server/ws_api.py@@ -51,7 +51,7 @@ async def event_broadcaster(manager: ConnectionManager):try:redis.connect()event_queue = AsyncRedisExecutionEventBus()- async for event in event_queue.listen():+ async for event in event_queue.listen("*"):await manager.send_execution_result(event)except Exception as e:logger.exception(f"Event broadcaster error: {e}")