auto-sync: 2026-06-02 15:27:38
This commit is contained in:
@@ -181,8 +181,6 @@ class AgentSpawner:
|
||||
api_port: int = 8083,
|
||||
bootstrap_builder: Optional[Any] = None,
|
||||
gateway_timeout: float = 600.0,
|
||||
gateway_host: str = "127.0.0.1",
|
||||
gateway_port: int = 18789,
|
||||
max_retries: int = 3,
|
||||
max_monitor_timeouts: int = 3,
|
||||
counter: Optional[Any] = None,
|
||||
@@ -194,8 +192,6 @@ class AgentSpawner:
|
||||
dry_run: 测试模式,不实际 spawn
|
||||
api_host: API 地址(供 Agent 回写)
|
||||
api_port: API 端口(供 Agent 回写)
|
||||
gateway_host: Gateway 地址(供存活检查)
|
||||
gateway_port: Gateway 端口(供存活检查)
|
||||
"""
|
||||
self.db_path = db_path
|
||||
self.agent_timeout = agent_timeout
|
||||
@@ -204,8 +200,6 @@ class AgentSpawner:
|
||||
self.api_port = api_port
|
||||
self.bootstrap_builder = bootstrap_builder
|
||||
self.gateway_timeout = gateway_timeout
|
||||
self.gateway_host = gateway_host
|
||||
self.gateway_port = gateway_port
|
||||
self.max_retries = max_retries
|
||||
self.max_monitor_timeouts = max_monitor_timeouts
|
||||
# v2.7.2: counter 引用(spawn_full_agent 内部 acquire/release)
|
||||
@@ -474,16 +468,6 @@ curl -X POST http://{self.api_host}:{self.api_port}/api/projects/{project_id}/ta
|
||||
session_id = str(uuid.uuid4())
|
||||
_sid_key = session_id or "main" # counter 用的 key
|
||||
|
||||
# Phase -1: Gateway 存活检查(#08)
|
||||
# Gateway 不可达 → AgentBusyError(reason="gateway_down") → 任务留 pending
|
||||
# → ticker 30s 后自动重试。仅检查 main session spawn(subagent 走 API)。
|
||||
if use_main_session and not skip_counter:
|
||||
gw_alive = await self._probe_gateway()
|
||||
if not gw_alive:
|
||||
logger.warning("Phase -1: Gateway unreachable (%s:%d), deferring %s",
|
||||
self.gateway_host, self.gateway_port, agent_id)
|
||||
raise AgentBusyError(agent_id, reason="gateway_down")
|
||||
|
||||
# Phase 0: Pre-acquire 修复(无锁)
|
||||
# timeout/failed 状态先修复再 acquire。revive 只改 running→idle,幂等安全。
|
||||
# asyncio 协作式并发保证同一时刻只有一个协程在执行,revive 的 sessions.json
|
||||
@@ -1259,32 +1243,6 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_
|
||||
pass
|
||||
return result
|
||||
|
||||
async def _probe_gateway(self, timeout: float = 3.0) -> bool:
|
||||
"""TCP + WebSocket Upgrade 握手探测 Gateway 存活
|
||||
|
||||
#08: Phase -1 — 在 spawn 前探测 Gateway 进程是否可达。
|
||||
不可达 → AgentBusyError(reason="gateway_down") → 任务留 pending → ticker 30s 后重试。
|
||||
"""
|
||||
try:
|
||||
reader, writer = await asyncio.wait_for(
|
||||
asyncio.open_connection(self.gateway_host, self.gateway_port),
|
||||
timeout=timeout,
|
||||
)
|
||||
writer.write(
|
||||
b'GET /ws HTTP/1.1\r\n'
|
||||
b'Host: 127.0.0.1:%d\r\n'
|
||||
b'Upgrade: websocket\r\n'
|
||||
b'Connection: Upgrade\r\n'
|
||||
b'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n'
|
||||
b'Sec-WebSocket-Version: 13\r\n\r\n' % self.gateway_port
|
||||
)
|
||||
await writer.drain()
|
||||
resp = await asyncio.wait_for(reader.read(256), timeout=timeout)
|
||||
writer.close()
|
||||
return b'101' in resp
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _classify_outcome(exit_code: int, json_result: dict, stderr_text: str,
|
||||
task_status: Optional[str], stdout_text: str = "") -> dict:
|
||||
|
||||
Reference in New Issue
Block a user