From 88a288ce4e4c4cb4614e6a6f4f6149c7bfbb7192 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Tue, 26 May 2026 11:48:30 +0800 Subject: [PATCH] auto-sync: 2026-05-26 11:48:30 --- src/daemon/spawner.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index df972bf..a27a401 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -198,6 +198,8 @@ class AgentSpawner: self._sessions: Dict[str, Dict[str, Any]] = {} # B2 compact 等待计数器 {task_id: count} self._compact_waits: Dict[str, int] = {} + # B1 假死计数器 {task_id: count} + self._stuck_counts: Dict[str, int] = {} @property def active_sessions(self) -> Dict[str, Dict[str, Any]]: @@ -937,6 +939,29 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ except Exception: return None + @staticmethod + def _revive_session(agent_id: str) -> bool: + """假死复活术:修改 sessions.json status 从 running 改为 idle""" + sessions_path = Path.home() / ".openclaw" / "agents" / agent_id / "sessions" / "sessions.json" + if not sessions_path.exists(): + return False + try: + with open(sessions_path) as f: + sessions = json.load(f) + main_key = f"agent:{agent_id}:main" + main_session = sessions.get(main_key, {}) + if main_session.get("status") != "running": + return False # 不是 running 状态,不需要复活 + main_session["status"] = "idle" + sessions[main_key] = main_session + with open(sessions_path, "w") as f: + json.dump(sessions, f, indent=2) + logger.info("Revived %s: sessions.json status changed running→idle", agent_id) + return True + except Exception: + logger.exception("Failed to revive %s", agent_id) + return False + @staticmethod def _check_session_state(agent_id: str) -> dict: """检查 sessions.json 和 lock 状态"""