fix: 切迭代时自动关闭旧迭代 pending 问题(status=answered)

_cancel_active_tasks 作废任务时,一并把该迭代的 pending 问题置 answered(随迭代作废)。
否则旧迭代问题持续 pending 冒泡、阻塞诊断视图,需手动 SQL 清理。
This commit is contained in:
ymq 2026-08-22 18:38:56 +08:00
parent a9145ee3a4
commit 84b2e83213

View File

@ -197,13 +197,22 @@ async def _active_task_ids(sor, project_id, iteration_name):
async def _cancel_active_tasks(sor, project_id, iteration_name):
"""作废某迭代内所有活跃任务(非终态 → cancelled + 清 claimed_by。返回作废数量。"""
"""作废某迭代内所有活跃任务(非终态 → cancelled + 清 claimed_by+ 关闭其 pending 问题。返回作废数量。"""
ids = await _active_task_ids(sor, project_id, iteration_name)
if ids:
in_clause = ",".join(["'" + x.replace("'", "''") + "'" for x in ids])
await sor.sqlExe(
f"UPDATE pipeline_tasks SET state='cancelled', claimed_by=NULL, updated_at=NOW() "
f"WHERE id IN ({in_clause})", {})
# 关闭该迭代的 pending 问题(随迭代作废,不再冒泡):问题通过 task_id 关联任务,任务通过
# params.iteration_id 关联迭代。不关闭则旧迭代问题持续 pending 冒泡、阻塞诊断视图2026-08 实测)。
await sor.sqlExe(
"UPDATE pipeline_agent_questions SET status='answered', "
"answer='旧迭代已作废,本问题随迭代关闭', answered_by='system', answer_source='main_agent', updated_at=NOW() "
"WHERE tenant_id=${pid}$ AND status='pending' AND task_id IN ("
"SELECT id FROM pipeline_tasks WHERE tenant_id=${pid}$ "
"AND JSON_UNQUOTE(JSON_EXTRACT(params,'$.iteration_id'))=${iter}$)",
{"pid": project_id, "iter": iteration_name})
return len(ids)