diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 14759e9..1b56f24 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -466,13 +466,19 @@ curl -X POST http://{self.api_host}:{self.api_port}/api/projects/{project_id}/ta logger.info("Session state check for %s: status=%s lock_pid=%s lock_pid_alive=%s recent_compact=%s", agent_id, session_state.get('status'), session_state.get('lock_pid'), session_state.get('lock_pid_alive'), session_state.get('recent_compact')) - if session_state.get("lock_pid_alive"): + if session_state.get("lock_pid_alive") and not session_state.get("lock_expired"): logger.info("Spawn skipped: %s main session locked by PID %d", agent_id, session_state.get("lock_pid")) raise AgentBusyError(f"{agent_id}: session locked by PID {session_state.get('lock_pid')}") + if session_state.get("lock_expired"): + logger.info("Session lock expired for %s, clearing stale lock", agent_id) if session_state.get("status") == "running": logger.info("Spawn skipped: %s main session processing", agent_id) raise AgentBusyError(f"{agent_id}: session processing") + # timeout/failed 状态:Gateway 会阻止新请求,需要先 reset + if session_state.get("status") in ("timeout", "failed"): + logger.info("Session %s detected for %s, attempting revive", session_state.get("status"), agent_id) + self._revive_session(agent_id) if session_state.get("recent_compact"): logger.info("Spawn skipped: %s compacting", agent_id) raise AgentBusyError(f"{agent_id}: compacting")