From cc6be8b72eea4513888518e51dd4c47dcd6f761d Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sat, 23 May 2026 00:38:09 +0800 Subject: [PATCH] auto-sync: 2026-05-23 00:38:09 --- src/daemon/spawner.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 0f5c8e8..6f61194 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -501,6 +501,36 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ return # B2/B3/B4: 进程还活着 + # B2: compact 进行中 — 不计入 monitor timeout 计数,继续等 + if state.get("recent_compact"): + logger.info("Agent %s recent compaction detected, extending patience " + "(session=%s, monitor=%d/%d)", + agent_id, session_id, monitor_timeout_count, self.max_monitor_timeouts) + # 不递增 monitor_timeout_count,但最多额外等 max_monitor_timeouts 次 + # 用独立计数器防止无限等待 + compact_wait_count = getattr(self, f"_compact_waits_{task_id}", 0) + 1 + setattr(self, f"_compact_waits_{task_id}", compact_wait_count) + if compact_wait_count >= self.max_monitor_timeouts: + logger.error("Agent %s max compact waits reached (session=%s, count=%d)", + agent_id, session_id, compact_wait_count) + self._mark_task(db_path, task_id, "failed", { + "reason": "compact_hanging", + "compact_wait_count": compact_wait_count, + "diagnostics": state, + }) + await self._do_on_complete_async(on_complete, agent_id, "compact_hanging") + return + # 继续等 + asyncio.create_task( + self._monitor_process( + session_id, proc, agent_id, task_id, + on_complete=on_complete, db_path=db_path, + monitor_timeout_count=monitor_timeout_count, + ) + ) + return + + # B3/B4: 无 compact,正常计数 monitor_timeout_count += 1 if monitor_timeout_count >= self.max_monitor_timeouts: logger.error("Agent %s max monitor timeouts (session=%s, count=%d)",