feat(roundtable): 会商诊断日志 + 后台挂起卡死兜底(idle 超时)

- 新增会商全流程诊断日志:新表 roundtable_diagnostics + 仓储 + admin API
  (/api/roundtable-diagnostics) + 管理员诊断页(会商页右上角设置按钮入口),
  覆盖第一/二/三步及后台执行器/进程内网关各处报错与关键事件,支持按
  范围/阶段/级别/事件/关键词筛选 + 分页。诊断写入全程 best-effort,绝不打断会商。
- 修复后台挂起「执行完第一个席位后永久卡死」:进程内网关每轮 agent run 改为
  idle(无活动)超时(默认 20min)——只要还在持续产出 token/工具事件就一直等,
  仅当连续无任何输出才判卡死并取消+报错+落 seat_turn_timeout 诊断;慢但活着的
  生成绝不打断。可经 ROUNDTABLE_SEAT_IDLE_TIMEOUT_SECONDS 调整。
- 一并提交进行中的会商 seat-skill 注入 / 业务链条编辑器相关改动。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-19 22:55:56 +08:00
1 parent 8ca16c74bc
commit 4a403c95c5
27 files changed
+1873 -61

No files matched your search

@@ -101,6 +101,11 @@ async def run_orchestration(
intent = (intent_text or seed_message or "").strip()
try:
await progress.begin()
await progress.diag(
stage="step2_orchestration", level="info", event="begin",
message=f"会商编排启动(mode={mode},{len(agents)} 个席位)",
detail={"mode": mode, "agents": [a.agent_id for a in agents]},
)
dag_plan = parse_dag_plan(plan) if mode == "dag" else None
if mode == "dag" and dag_plan is not None:
outcome = await _run_dag(gateway, progress, agents, thread_ids, coordinator_name, model, seed_message, intent, dag_plan)
@@ -112,6 +117,11 @@ async def run_orchestration(
if outcome.kind == "clarification":
question = outcome.question or "总控需要补充信息,请补充后继续。"
await progress.diag(
stage="step2_leader", level="info", event="clarification",
message="总控发起澄清,会商暂停等待补充信息",
detail={"question": question[:500]},
)
await progress.awaiting_input(question)
return OrchestrationResult(
status="awaiting_input",
@@ -120,8 +130,17 @@ async def run_orchestration(
dialogues=progress.dialogues(),
)
if outcome.kind == "max_cycles":
await progress.diag(
stage="step2_orchestration", level="warning", event="max_cycles",
message=f"达到最大研讨轮次({MAX_CYCLES}),强制收口——可能未真正达成共识",
)
# consensus 或 max_cycles:均收口。Step3(总结报告 + 结果绘制)按 enable_report 开关执行。
await progress.consensus(100)
await progress.diag(
stage="step2_orchestration", level="info", event="consensus",
message="研讨收口,进入第三步" if enable_report else "研讨收口(未启用第三步报告)",
)
step3 = None
if enable_report:
step3 = await _run_step3(
@@ -144,6 +163,11 @@ async def run_orchestration(
)
except Exception as exc: # noqa: BLE001 — 顶层兜底:标记 error 并返回
logger.exception("roundtable orchestration failed")
await progress.diag(
stage="step2_orchestration", level="error", event="orchestration_crash",
message=f"会商编排顶层异常:{exc}",
detail={"type": type(exc).__name__, "error": str(exc)},
)
await progress.error(str(exc))
return OrchestrationResult(status="error", error=str(exc), dialogues=progress.dialogues())
@@ -229,6 +253,12 @@ async def _run_recommend(
seat_msg = _seat_message(intent_text, deliveries, name_by_id, task)
seat = await gateway.run_seat(thread_ids=thread_ids, agent_id=agent_id, task=seat_msg, model=model)
deliveries[agent_id] = seat.final_text
if not (seat.final_text or "").strip():
await progress.diag(
stage="step2_seat", level="warning", event="seat_empty_delivery",
message=f"席位「{name_by_id.get(agent_id, agent_id)}」本轮交付为空(可能模型未产出或被截断)",
agent_id=agent_id, agent_name=name_by_id.get(agent_id, agent_id), cycle=cycle,
)
await progress.add_seat_dialogue(
agent_id, name_by_id.get(agent_id, agent_id), seat.final_text, cycle,
tool_calls=seat.tool_calls, thread_id=thread_ids.get(agent_id),
@@ -298,6 +328,12 @@ async def _run_chain(
seat_msg = _seat_message(intent_text, deliveries, name_by_id, task)
seat_turn = await gateway.run_seat(thread_ids=thread_ids, agent_id=seat.agent_id, task=seat_msg, model=model)
deliveries[seat.agent_id] = seat_turn.final_text
if not (seat_turn.final_text or "").strip():
await progress.diag(
stage="step2_seat", level="warning", event="seat_empty_delivery",
message=f"席位「{seat.name}」本轮交付为空(可能模型未产出或被截断)",
agent_id=seat.agent_id, agent_name=seat.name, cycle=i + 1,
)
await progress.add_seat_dialogue(
seat.agent_id, seat.name, seat_turn.final_text, i + 1,
tool_calls=seat_turn.tool_calls, thread_id=thread_ids.get(seat.agent_id),
@@ -398,6 +434,12 @@ async def _run_dag(
seat_msg = _seat_message(intent_text, deliveries, name_by_id, task)
seat_turn = await gateway.run_seat(thread_ids=thread_ids, agent_id=seat.agent_id, task=seat_msg, model=model)
deliveries[seat.agent_id] = seat_turn.final_text
if not (seat_turn.final_text or "").strip():
await progress.diag(
stage="step2_seat", level="warning", event="seat_empty_delivery",
message=f"席位「{seat.name}」本轮交付为空(可能模型未产出或被截断)",
agent_id=seat.agent_id, agent_name=seat.name, cycle=i + 1,
)
await progress.add_seat_dialogue(
seat.agent_id, seat.name, seat_turn.final_text, i + 1,
tool_calls=seat_turn.tool_calls, thread_id=thread_ids.get(seat.agent_id),
@@ -477,6 +519,11 @@ async def _run_step3(
}
except Exception as exc: # noqa: BLE001 — 总结失败不阻塞结果绘制
logger.exception("roundtable step3 summary failed")
await progress.diag(
stage="step3_summary", level="error", event="summary_failed",
message=f"第三步「方案总结报告」生成失败:{exc}",
detail={"type": type(exc).__name__, "error": str(exc)},
)
errors.append(exc)
async def _report_task() -> None:
@@ -494,6 +541,11 @@ async def _run_step3(
step3.update(report)
except Exception as exc: # noqa: BLE001 — 绘制失败时保留已写出的总结报告
logger.exception("roundtable step3 report failed")
await progress.diag(
stage="step3_report", level="error", event="report_failed",
message=f"第三步「结果绘制」(方案总览.html) 生成失败:{exc}",
detail={"type": type(exc).__name__, "error": str(exc)},
)
errors.append(exc)
async def _dashboard_task() -> None:
@@ -510,6 +562,11 @@ async def _run_step3(
step3["dashboardJson"] = data_json
except Exception as exc: # noqa: BLE001 — 大屏失败不拖垮另两段
logger.exception("roundtable step3 dashboard failed")
await progress.diag(
stage="step3_dashboard", level="error", event="dashboard_failed",
message=f"第三步「大屏数据」(report-json) 生成失败:{exc}",
detail={"type": type(exc).__name__, "error": str(exc)},
)
errors.append(exc)
await asyncio.gather(_summary_task(), _report_task(), _dashboard_task())
@@ -53,11 +53,15 @@ class JobProgressWriter:
agents: list[SeatRef],
event_sink: EventSink = None,
on_dialogue: Any | None = None,
recorder: Any | None = None,
) -> None:
self._store = store
self._job_id = job_id
self._agents = list(agents)
self._event_sink = event_sink
# 诊断日志记录器(DiagnosticsRecorder,已绑定本作业上下文)。引擎经
# ``await progress.diag(...)`` 在每个报错 / 关键转折处落一条事件。None = 不记录。
self._recorder = recorder
# 每轮 leader/seat 模型返回后回调(dialogues, consensus)—— 执行器据此把对话
# 写进草稿(和手动跑同一存取路径)。
self._on_dialogue = on_dialogue
@@ -105,6 +109,35 @@ class JobProgressWriter:
except Exception: # noqa: BLE001
logger.warning("roundtable job progress event sink failed", exc_info=True)
async def diag(
self,
*,
stage: str,
level: str,
event: str,
message: str | None = None,
detail: Any = None,
agent_id: str | None = None,
agent_name: str | None = None,
cycle: int | None = None,
) -> None:
"""落一条诊断日志(best-effort;无 recorder 时 no-op)。"""
if self._recorder is None:
return
try:
await self._recorder.record(
stage=stage,
level=level,
event=event,
message=message,
detail=detail,
agent_id=agent_id,
agent_name=agent_name,
cycle=cycle,
)
except Exception: # noqa: BLE001 — 诊断日志绝不打断编排
logger.debug("roundtable diag record failed", exc_info=True)
# ── 语义方法(引擎调用)─────────────────────────────────────────────────
async def begin(self) -> None: