auto-sync: 2026-05-24 19:52:30

This commit is contained in:
cfdaily
2026-05-24 19:52:30 +08:00
parent d948acede8
commit 5a64e13f82
+40 -8
View File
@@ -229,8 +229,6 @@ class Dispatcher:
logger.error("Mail %s: on_complete error: %s", _task_id, e)
else:
logger.info("Mail %s: on_complete outcome=%s, skip auto-done", _task_id, outcome)
if _counter:
_counter.release(aid)
on_complete = _mail_on_complete
else:
on_complete = (
@@ -472,6 +470,18 @@ class Dispatcher:
try:
if self.counter:
await self.counter.acquire(agent_id)
# [v2.7.1] Mail: spawn 前系统标 working
is_mail_legacy = project_config.get("project_id") == "_mail" if project_config else False
if is_mail_legacy:
db_path_legacy = Path(project_config["db_path"]) if project_config and "db_path" in project_config else None
if not db_path_legacy or not self._mail_auto_working(task.id, db_path_legacy):
if self.counter:
self.counter.release(agent_id)
return {"level": level.value, "agent_id": agent_id,
"session_id": None, "status": "error",
"reason": "mail_auto_working_failed"}
if hasattr(self.spawner, 'build_spawn_message') and project_config:
retry_ctx = self._build_retry_context(task)
message = self.spawner.build_spawn_message(
@@ -487,16 +497,38 @@ class Dispatcher:
)
else:
message = f"Task: {task.title}"
# Agent 完成后自动 release counter
on_complete = (
lambda aid, _outcome: self.counter.release(aid)
) if self.counter else None
# [v2.7.1] Mail: on_complete 增强
on_complete_legacy = None
if is_mail_legacy:
_t_id = task.id
_a_id = agent_id
_m_db = db_path_legacy
_m_mh = task.must_haves or ""
_ct = self.counter
_disp = self
def _mail_oc_legacy(aid, outcome):
if _ct:
_ct.release(aid)
if outcome in ("completed", "agent_failed"):
try:
_disp._mail_auto_complete(_t_id, aid, _m_db, _m_mh)
except Exception as e:
logger.error("Mail %s: legacy on_complete error: %s", _t_id, e)
else:
logger.info("Mail %s: legacy on_complete outcome=%s, skip auto-done", _t_id, outcome)
on_complete_legacy = _mail_oc_legacy
else:
on_complete_legacy = (
lambda aid, _outcome: self.counter.release(aid)
) if self.counter else None
session_id = await self.spawner.spawn_full_agent(
agent_id=agent_id, message=message,
new_session=decision.get("new_session", False),
task_id=task.id,
on_complete=on_complete,
use_main_session=project_config.get("project_id") == "_mail" if project_config else False,
on_complete=on_complete_legacy,
use_main_session=is_mail_legacy,
task_db_path=Path(project_config["db_path"]) if project_config and "db_path" in project_config else None,
)
return {"level": level.value, "agent_id": agent_id,