From 7c841b9424f307a25ce472e5fee4f98fd1dd47f8 Mon Sep 17 00:00:00 2001 From: zhaoxi Date: Mon, 27 Apr 2026 14:13:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=A5?= =?UTF-8?q?=E9=87=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 +++++++++++++++-- .../global_state_machine.py | 12 +++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 7936ca8..4796e34 100644 --- a/main.py +++ b/main.py @@ -35,8 +35,21 @@ async def start_system(): postgres_database = PostgresDatabase.options(name='postgres_database').remote() await postgres_database.init_db.remote() - # 3. 启动全局状态机 - GlobalStateMachine.options(name='global_state_machine').remote(postgres_database) + global_state_machine = GlobalStateMachine.options( + name='global_state_machine', + namespace='pretor', + lifetime='detached' + ).remote(postgres_database) + + print("正在等待 GlobalStateMachine 初始化并加载注册表...") + try: + # 强制执行初始化方法并阻塞等待结果。 + # 如果 __init__ 或 init_state_machine 中有任何报错,会立刻在这里抛出! + await global_state_machine.init_state_machine.remote() + print("GlobalStateMachine 初始化成功!") + except Exception as e: + print(f"\n[致命错误] GlobalStateMachine 启动失败!真实报错如下:\n{e}\n") + return # 4. 启动核心节点 supervisory_node = SupervisoryNode.options(name='supervisory_node').remote() diff --git a/pretor/core/global_state_machine/global_state_machine.py b/pretor/core/global_state_machine/global_state_machine.py index 90c0dab..2af8477 100644 --- a/pretor/core/global_state_machine/global_state_machine.py +++ b/pretor/core/global_state_machine/global_state_machine.py @@ -28,16 +28,22 @@ from pretor.core.global_state_machine.individual_manager import GlobalIndividual @ray.remote class GlobalStateMachine: def __init__(self, postgres_database: PostgresDatabase): - + import sys + print("GSM __init__ START", file=sys.stderr, flush=True) self.event_dict: Dict[str, PretorEvent] = {} - + print(" event_dict done", file=sys.stderr, flush=True) self._global_provider_manager = ProviderManager(postgres_database) + print(" provider_manager done", file=sys.stderr, flush=True) self._global_tool_manager = GlobalToolManager() + print(" tool_manager done", file=sys.stderr, flush=True) self._global_workflow_template_manager = WorkflowManager() + print(" workflow_template_manager done", file=sys.stderr, flush=True) self._global_skill_manager = GlobalSkillManager() + print(" skill_manager done", file=sys.stderr, flush=True) self._global_individual_manager = GlobalIndividualManager() - + print(" individual_manager done", file=sys.stderr, flush=True) self.postgres_database = postgres_database + print("GSM __init__ DONE", file=sys.stderr, flush=True) async def init_state_machine(self): await self._global_provider_manager.init_provider_register(self.postgres_database)