fix(dashboard): correct stage key mismatch, add created_at, persist cancelled tasks

- Fix ANALYSIS_STAGES key 'trader' → 'trading' to match backend STAGE markers
- Add created_at field to task state at creation, sort list_tasks by it
- Persist task state before broadcast in cancel path (closes restart race)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
陈少杰 2026-04-07 00:29:32 +08:00
parent 4b007c16ae
commit 3998984094
2 changed files with 6 additions and 4 deletions

View File

@ -231,6 +231,7 @@ async def start_analysis(request: AnalysisRequest):
"status": "running",
"progress": 0,
"current_stage": "analysts",
"created_at": datetime.now().isoformat(),
"elapsed": 0,
"stages": [
{"status": "running", "completed_at": None},
@ -419,10 +420,10 @@ async def list_tasks():
"progress": state.get("progress", 0),
"decision": state.get("decision"),
"error": state.get("error"),
"created_at": state.get("stages", [{}])[0].get("completed_at") if state.get("stages") else None,
"created_at": state.get("created_at"),
})
# Sort by task_id (which includes timestamp) descending
tasks.sort(key=lambda x: x["task_id"], reverse=True)
# Sort by created_at descending (most recent first)
tasks.sort(key=lambda x: x.get("created_at") or "", reverse=True)
return {"tasks": tasks, "total": len(tasks)}
@ -446,6 +447,7 @@ async def cancel_task(task_id: str):
task.cancel()
app.state.task_results[task_id]["status"] = "failed"
app.state.task_results[task_id]["error"] = "用户取消"
_save_task_status(task_id, app.state.task_results[task_id])
await broadcast_progress(task_id, app.state.task_results[task_id])
# Clean up temp script

View File

@ -6,7 +6,7 @@ import { CheckCircleOutlined, SyncOutlined, CloseCircleOutlined } from '@ant-des
const ANALYSIS_STAGES = [
{ key: 'analysts', label: '分析师团队' },
{ key: 'research', label: '研究员辩论' },
{ key: 'trader', label: '交易员' },
{ key: 'trading', label: '交易员' },
{ key: 'risk', label: '风险管理' },
{ key: 'portfolio', label: '组合经理' },
]