diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 3ac998b..87c7cf4 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -360,6 +360,21 @@ curl -X POST http://{self.api_host}:{self.api_port}/api/projects/{project_id}/ta raise AgentBusyError(agent_id) await self.counter.acquire(agent_id) + # ── v2.7.2: session state 检查(防外部占用)── + if use_main_session: + session_state = self._check_session_state(agent_id) + if session_state.get("lock_pid_alive"): + # main session 被 webchat/Control UI/cron 占用 + 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("status") == "processing": + logger.info("Spawn skipped: %s main session processing", agent_id) + raise AgentBusyError(f"{agent_id}: session processing") + if session_state.get("recent_compact"): + logger.info("Spawn skipped: %s compacting", agent_id) + raise AgentBusyError(f"{agent_id}: compacting") + # Session 策略:main > reuse > new if use_main_session: session_id = None