问数据:被驳回的那次尝试不写「已手动停止」,会话列表标「被驳回」

为什么:一轮的运行被审批人驳回之后点「重新运行本轮」,「之前的尝试」那一行写「已手动停止」,用户其实没有停过它。会话
列表的 last_status 把被驳回的一轮归成 cancelled,左栏不标——在等审批的那一问被驳回之后,看起来像是答完了(以前驳回
记成失败,左栏标的是「失败」)。

做了什么:
- store/chat 的 attemptOf:被驳回的那次记 outcome=rejected,摘要写「被驳回:张工 驳回了「查数」:…」;老留档里记成
  cancelled 的不改写。ChatPage 的尝试徽标认 rejected。
- api/conversations 的 last_status:前端落库时 meta 里记着 rejected 的、页面关掉没落库而运行是 cancelled +
  end_reason=rejected 的,都记 rejected;手动停止照旧 cancelled。types 的 last_status 加上 rejected。
- 左栏:打开过的看最后一轮(相位 cancelled 且带着驳回),没打开过的看 last_status,都标「被驳回」(不画异常色)。

测试:test_conversation_status 加一条(两种认法的被驳回、两种手动停止),改之前失败;check-chat 加一节被驳回(刷新后
认得出、补救区的话、左栏两种、重新运行之后的尝试记录),把前端改动退回去回跑,那一节 4 项不通过,改完通过。
This commit is contained in:
ThearchyHelios
2026-10-16 12:46:36 +08:00
parent 58c26baa33
commit b6cb5816db
7 changed files with 131 additions and 19 deletions
+35 -2
View File
@@ -43,9 +43,9 @@ async def _turn(client, conv_id: str, question: str = "订单数多少", **patch
return turn
async def _run(status: str, *, pending: bool = False) -> str:
async def _run(status: str, *, pending: bool = False, end_reason: str | None = None) -> str:
async with SessionLocal() as session:
run = Run(workflow_name="状态测试", status=status)
run = Run(workflow_name="状态测试", status=status, end_reason=end_reason)
session.add(run)
await session.flush()
if pending:
@@ -162,6 +162,39 @@ async def test_the_list_says_where_each_conversation_last_stopped(client):
assert got == cases
async def test_a_rejected_turn_is_listed_as_rejected_not_cancelled(client):
"""被审批人驳回结束的一轮(运行 cancelled + end_reason=rejected,05-已知遗留 (a)):列表说「被驳回」,不和手动停止混成
cancelled——发问的人不一定知道被驳回了,以前驳回记成失败,列表标的是「失败」。认法两条:前端落库时记下的
meta.rejected,和页面关掉、轮次还停在 running 时运行的 end_reason。手动停止照旧是 cancelled。"""
cases: dict[str, tuple[str, str | None]] = {}
conv = await _conversation(client, "驳回:前端落库了")
run = await _run("cancelled", end_reason="rejected")
await _turn(client, conv, run_id=run, status="error", error="已取消",
meta={"v": 1, "runId": run, "outcome": "cancelled", "rejected": {"sub": "张工 驳回了「付款」"}})
cases[conv] = ("rejected", run)
conv = await _conversation(client, "驳回:页面关了")
run = await _run("cancelled", end_reason="rejected")
await _turn(client, conv, run_id=run)
cases[conv] = ("rejected", run)
conv = await _conversation(client, "手动停止:页面关了")
run = await _run("cancelled", end_reason="stopped")
await _turn(client, conv, run_id=run)
cases[conv] = ("cancelled", run)
conv = await _conversation(client, "手动停止:前端落库了")
run = await _run("cancelled", end_reason="stopped")
await _turn(client, conv, run_id=run, status="error", error="已取消", meta={"v": 1, "runId": run, "outcome": "cancelled"})
cases[conv] = ("cancelled", run)
listed = await _listed(client)
assert {cid: (listed[cid]["last_status"], listed[cid]["last_run_id"]) for cid in cases} == cases
detail = (await client.get(f"/api/conversations/{next(iter(cases))}")).json()
assert detail["last_status"] == "rejected"
async def test_only_the_last_turn_counts(client):
conv = await _conversation(client, "后来好了")
await _turn(client, conv, status="error", error="查询超时")