auto-sync: 2026-05-26 08:24:38
This commit is contained in:
+10
-23
@@ -433,17 +433,14 @@ class Dispatcher:
|
|||||||
return "pangtong-fujunshi"
|
return "pangtong-fujunshi"
|
||||||
|
|
||||||
async def _legacy_dispatch(self, task, action_type="", project_config=None):
|
async def _legacy_dispatch(self, task, action_type="", project_config=None):
|
||||||
"""旧版 dispatch(兼容过渡用)"""
|
"""旧版 dispatch(兼容过渡用)
|
||||||
|
|
||||||
|
v2.7.2: counter acquire/release 移到 spawn_full_agent 内部。
|
||||||
|
"""
|
||||||
decision = self._legacy_decide(task, action_type)
|
decision = self._legacy_decide(task, action_type)
|
||||||
level = decision["level"]
|
level = decision["level"]
|
||||||
agent_id = decision["agent_id"]
|
agent_id = decision["agent_id"]
|
||||||
|
|
||||||
if self.counter and level in (DispatchLevel.FULL_AGENT, DispatchLevel.ESCALATE):
|
|
||||||
if not await self.counter.can_acquire(agent_id):
|
|
||||||
return {"level": level.value, "agent_id": agent_id,
|
|
||||||
"session_id": None, "status": "skipped",
|
|
||||||
"reason": "Agent busy (concurrent limit)"}
|
|
||||||
|
|
||||||
if level == DispatchLevel.LOCAL:
|
if level == DispatchLevel.LOCAL:
|
||||||
return {"level": level.value, "agent_id": "daemon",
|
return {"level": level.value, "agent_id": "daemon",
|
||||||
"session_id": None, "status": "dispatched",
|
"session_id": None, "status": "dispatched",
|
||||||
@@ -455,16 +452,11 @@ class Dispatcher:
|
|||||||
"session_id": None, "status": "error",
|
"session_id": None, "status": "error",
|
||||||
"reason": "No spawner configured"}
|
"reason": "No spawner configured"}
|
||||||
try:
|
try:
|
||||||
if self.counter:
|
|
||||||
await self.counter.acquire(agent_id)
|
|
||||||
|
|
||||||
# [v2.7.1] Mail: spawn 前系统标 working
|
# [v2.7.1] Mail: spawn 前系统标 working
|
||||||
is_mail_legacy = project_config.get("project_id") == "_mail" if project_config else False
|
is_mail_legacy = project_config.get("project_id") == "_mail" if project_config else False
|
||||||
if is_mail_legacy:
|
if is_mail_legacy:
|
||||||
db_path_legacy = Path(project_config["db_path"]) if project_config and "db_path" in project_config else None
|
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 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,
|
return {"level": level.value, "agent_id": agent_id,
|
||||||
"session_id": None, "status": "error",
|
"session_id": None, "status": "error",
|
||||||
"reason": "mail_auto_working_failed"}
|
"reason": "mail_auto_working_failed"}
|
||||||
@@ -484,28 +476,21 @@ class Dispatcher:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
message = f"Task: {task.title}"
|
message = f"Task: {task.title}"
|
||||||
# [v2.7.1] Mail: on_complete 增强
|
|
||||||
|
# v2.7.2: on_complete 只含业务逻辑
|
||||||
on_complete_legacy = None
|
on_complete_legacy = None
|
||||||
if is_mail_legacy:
|
if is_mail_legacy:
|
||||||
_t_id = task.id
|
_t_id = task.id
|
||||||
_a_id = agent_id
|
|
||||||
_m_db = db_path_legacy
|
_m_db = db_path_legacy
|
||||||
_m_mh = task.must_haves or ""
|
_m_mh = task.must_haves or ""
|
||||||
_ct = self.counter
|
|
||||||
_disp = self
|
_disp = self
|
||||||
|
|
||||||
def _mail_oc_legacy(aid, outcome):
|
def _mail_oc_legacy(aid, outcome):
|
||||||
if _ct:
|
|
||||||
_ct.release(aid)
|
|
||||||
try:
|
try:
|
||||||
_disp._mail_auto_complete(_t_id, aid, _m_db, _m_mh)
|
_disp._mail_auto_complete(_t_id, aid, _m_db, _m_mh)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Mail %s: legacy on_complete error: %s", _t_id, e)
|
logger.error("Mail %s: legacy on_complete error: %s", _t_id, e)
|
||||||
on_complete_legacy = _mail_oc_legacy
|
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(
|
session_id = await self.spawner.spawn_full_agent(
|
||||||
agent_id=agent_id, message=message,
|
agent_id=agent_id, message=message,
|
||||||
@@ -518,9 +503,11 @@ class Dispatcher:
|
|||||||
return {"level": level.value, "agent_id": agent_id,
|
return {"level": level.value, "agent_id": agent_id,
|
||||||
"session_id": session_id, "status": "dispatched",
|
"session_id": session_id, "status": "dispatched",
|
||||||
"reason": decision["reason"]}
|
"reason": decision["reason"]}
|
||||||
|
except AgentBusyError:
|
||||||
|
return {"level": level.value, "agent_id": agent_id,
|
||||||
|
"session_id": None, "status": "skipped",
|
||||||
|
"reason": "Agent busy (concurrent limit or cooling down)"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.counter:
|
|
||||||
self.counter.release(agent_id)
|
|
||||||
return {"level": level.value, "agent_id": agent_id,
|
return {"level": level.value, "agent_id": agent_id,
|
||||||
"session_id": None, "status": "error",
|
"session_id": None, "status": "error",
|
||||||
"reason": str(e)}
|
"reason": str(e)}
|
||||||
|
|||||||
Reference in New Issue
Block a user