auto-sync: 2026-05-26 11:48:30
This commit is contained in:
@@ -198,6 +198,8 @@ class AgentSpawner:
|
|||||||
self._sessions: Dict[str, Dict[str, Any]] = {}
|
self._sessions: Dict[str, Dict[str, Any]] = {}
|
||||||
# B2 compact 等待计数器 {task_id: count}
|
# B2 compact 等待计数器 {task_id: count}
|
||||||
self._compact_waits: Dict[str, int] = {}
|
self._compact_waits: Dict[str, int] = {}
|
||||||
|
# B1 假死计数器 {task_id: count}
|
||||||
|
self._stuck_counts: Dict[str, int] = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def active_sessions(self) -> Dict[str, Dict[str, Any]]:
|
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:
|
except Exception:
|
||||||
return None
|
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
|
@staticmethod
|
||||||
def _check_session_state(agent_id: str) -> dict:
|
def _check_session_state(agent_id: str) -> dict:
|
||||||
"""检查 sessions.json 和 lock 状态"""
|
"""检查 sessions.json 和 lock 状态"""
|
||||||
|
|||||||
Reference in New Issue
Block a user