feat(roundtable): 历史卡片显示所用业务链(自由模式) + 诊断只收报错日志

- 历史「分析记录」卡片/侧边栏列表:把「第X步」改为本次会商所用业务链名,
  无链条显示「自由模式」。后端 list 轻量 meta 从 step2 正则抽取 chain_title
  (不整体解析大块 JSON),个人草稿 + task 草稿两个 store 都覆盖。
- 会商诊断改为只收集报错日志:record_diagnostic 写库前丢弃 level==info
  运行日志(begin/consensus/gather/job_started),只留 warning/error。
  单点收口覆盖前台/后台/recorder 全部写路径;诊断页标题改「会商报错日志」。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-22 16:36:31 +08:00
1 parent e28277b21b
commit 7748661963
11 files changed
+85 -13

No files matched your search

@@ -41,10 +41,17 @@ def get_default_store() -> RoundtableDiagnosticRepository | None:
async def record_diagnostic(store: RoundtableDiagnosticRepository | None = None, **fields: Any) -> None:
"""Best-effort 写一条诊断事件。``store`` 缺省用进程级默认仓储。任何异常静默吞掉。"""
"""Best-effort 写一条诊断事件。``store`` 缺省用进程级默认仓储。任何异常静默吞掉。
会商诊断**只收集报错日志**:``info`` 级是纯运行进度(begin/consensus/gather/job_started
等「运行日志」),对排障没价值、还会淹没真正的报错,直接不落库;只保留 ``warning`` /
``error``(席位失败、空交付、超时、模型容错、产物缺失、崩溃等)。
"""
repo = store or _default_store
if repo is None:
return
if str(fields.get("level") or "").strip().lower() == "info":
return
try:
await repo.record(**fields)
except Exception: # noqa: BLE001 — 诊断日志写失败绝不打断会商
@@ -11,6 +11,7 @@ All write/read paths are scoped by ``user_id`` for ownership isolation.
from __future__ import annotations
import json
import re
from datetime import UTC, datetime
from typing import Any
@@ -24,6 +25,29 @@ from deerflow.persistence.roundtable_drafts.model import (
_UNSET = object()
# 业务链名抽取:在已加载进内存的 step2 JSON 串里直接找 `"chain":{...,"title":"X"}`,
# 不整体 json.loads(step2 是 LONGTEXT 大块),只做一次廉价正则扫描。`"chain":null`
# (recommend/自由模式)不匹配 → 返回 None。`[^{}]*?` 限定在 chain 对象内({id,title}
# 无嵌套花括号)。
_CHAIN_TITLE_RE = re.compile(r'"chain"\s*:\s*\{[^{}]*?"title"\s*:\s*"((?:\\.|[^"\\])*)"')
def _extract_chain_title(step2_raw: Any) -> str | None:
"""从 step2 原始 JSON 串里抽取所用业务链名(无链条 → None,前端显示「自由模式」)。"""
if not isinstance(step2_raw, str) or not step2_raw:
return None
m = _CHAIN_TITLE_RE.search(step2_raw)
if not m:
return None
title = m.group(1)
try:
# 还原 JSON 字符串转义(\" \\ \n \uXXXX 等)。
title = json.loads(f'"{title}"')
except Exception:
pass
title = title.strip()
return title or None
def _loads(value: Any) -> Any:
if not isinstance(value, str):
@@ -56,6 +80,8 @@ class RoundtableDraftRepository:
"task_id": row.task_id,
"title": row.title,
"furthest_step": row.furthest_step,
# 所用业务链名(历史卡片展示用);无链条 → None → 前端显示「自由模式」。
"chain_title": _extract_chain_title(row.step2),
"created_at": row.created_at.isoformat() if isinstance(row.created_at, datetime) else row.created_at,
"updated_at": row.updated_at.isoformat() if isinstance(row.updated_at, datetime) else row.updated_at,
}
@@ -15,6 +15,7 @@ in ``PortableLongText`` and round-tripped with ``json.dumps`` / ``json.loads``.
from __future__ import annotations
import json
import re
from datetime import UTC, datetime
from typing import Any
@@ -25,6 +26,27 @@ from deerflow.persistence.roundtable_task_drafts.model import RoundtableTaskDraf
_UNSET = object()
# 业务链名抽取:在已加载进内存的 step2 JSON 串里直接找 `"chain":{...,"title":"X"}`,
# 不整体 json.loads(step2 是 LONGTEXT 大块)。`"chain":null`(自由模式)不匹配 → None。
# 与 roundtable_drafts/sql.py 保持一致。
_CHAIN_TITLE_RE = re.compile(r'"chain"\s*:\s*\{[^{}]*?"title"\s*:\s*"((?:\\.|[^"\\])*)"')
def _extract_chain_title(step2_raw: Any) -> str | None:
"""从 step2 原始 JSON 串里抽取所用业务链名(无链条 → None,前端显示「自由模式」)。"""
if not isinstance(step2_raw, str) or not step2_raw:
return None
m = _CHAIN_TITLE_RE.search(step2_raw)
if not m:
return None
title = m.group(1)
try:
title = json.loads(f'"{title}"')
except Exception:
pass
title = title.strip()
return title or None
def _loads(value: Any) -> Any:
if not isinstance(value, str):
@@ -55,6 +77,8 @@ class RoundtableTaskDraftRepository:
"task_id": row.task_id,
"title": row.title,
"furthest_step": row.furthest_step,
# 所用业务链名(历史卡片展示用);无链条 → None → 前端显示「自由模式」。
"chain_title": _extract_chain_title(row.step2),
"created_at": row.created_at.isoformat() if isinstance(row.created_at, datetime) else row.created_at,
"updated_at": row.updated_at.isoformat() if isinstance(row.updated_at, datetime) else row.updated_at,
}