落地系统异常:大模型/TMS/建群故障停住本单并告警,后台可重试失败步骤。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-21 14:01:49 +08:00
co-authored by Cursor
parent a5e73c01ae
commit 4381966c4e
26 changed files with 2098 additions and 72 deletions
@@ -44,6 +44,10 @@ class MemoryTicket:
lost_reason: str = ""
next_followup_at: str = ""
deal_notify_summary: str = ""
system_exception: str = ""
system_exception_reason: str = ""
system_exception_step: str = ""
system_exception_payload: dict[str, Any] = field(default_factory=dict)
class MemoryLedger:
@@ -72,6 +76,7 @@ class MemoryLedger:
self._land_staff: list[dict[str, Any]] = []
self._staff_by_wecom: dict[str, dict[str, Any]] = {}
self._staff_by_name: dict[str, dict[str, Any]] = {}
self._exception_notify_users: list[dict[str, Any]] = []
def _next_no(self) -> str:
self._seq += 1
@@ -373,8 +378,69 @@ class MemoryLedger:
"lostReason": ticket.lost_reason,
"deal_notify_summary": ticket.deal_notify_summary,
"next_followup_at": ticket.next_followup_at,
"system_exception": ticket.system_exception,
"systemException": ticket.system_exception,
"system_exception_reason": ticket.system_exception_reason,
"systemExceptionReason": ticket.system_exception_reason,
"system_exception_step": ticket.system_exception_step,
"system_exception_payload": dict(ticket.system_exception_payload),
}
def upsert_exception_notify_user(self, row: dict[str, Any]) -> None:
"""单测注入「系统异常消息通知」接收人(后台账号已绑企微)。"""
data = dict(row)
uid = str(data.get("wecomId") or data.get("wecom_id") or "").strip()
if not uid:
return
data["wecomId"] = uid
with self._lock:
self._exception_notify_users = [
x for x in self._exception_notify_users
if str(x.get("wecomId") or "") != uid
]
self._exception_notify_users.append(data)
def list_exception_notify_users(self) -> list[dict[str, Any]]:
"""角色勾了系统异常消息通知、且账号已绑企微的人。"""
with self._lock:
return [dict(x) for x in self._exception_notify_users]
def mark_system_exception(
self,
*,
work_order_no: str,
system_exception: str,
system_exception_reason: str,
step: str = "",
payload: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""写入工单两列与重试上下文;已关闭拒绝。不改六态。"""
no = (work_order_no or "").strip()
with self._lock:
ticket = self._tickets.get(no)
if ticket is None:
return {"ok": False, "error": "not_found"}
if ticket.status == "已关闭":
return {"ok": False, "error": "closed"}
ticket.system_exception = (system_exception or "").strip()
ticket.system_exception_reason = (system_exception_reason or "").strip()
ticket.system_exception_step = (step or "").strip()
ticket.system_exception_payload = dict(payload or {})
return {"ok": True, "status": ticket.status}
def clear_system_exception(self, *, work_order_no: str) -> dict[str, Any]:
"""重试成功后清两列。"""
no = (work_order_no or "").strip()
with self._lock:
ticket = self._tickets.get(no)
if ticket is None:
return {"ok": False, "error": "not_found"}
ticket.system_exception = ""
ticket.system_exception_reason = ""
ticket.system_exception_step = ""
ticket.system_exception_payload = {}
return {"ok": True}
def upsert_staff(self, row: dict[str, Any]) -> None:
"""单测注入任意岗位(含会话存档账号「询价机器人」)。"""
data = dict(row)