From 5e1ea6efa178207317524da2adcfe70a3d83ad34 Mon Sep 17 00:00:00 2001 From: claude_dev Date: Sat, 11 Jul 2026 14:43:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=5Fget=5Fmetrics=5Ffile=5Fpath=20?= =?UTF-8?q?=E5=85=88=E8=A7=A3=E6=9E=90=20result.task=5Fid(uuid)=E2=80=94?= =?UTF-8?q?=E4=BF=AE=20runner=20task=5Fid=E2=89=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=20task=5Fid=20=E5=AF=BC=E8=87=B4=20benchmark-curve/ri?= =?UTF-8?q?sk-series=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanguo_api/routes.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sanguo_api/routes.py b/sanguo_api/routes.py index 29c4c8a..0da44c9 100644 --- a/sanguo_api/routes.py +++ b/sanguo_api/routes.py @@ -329,11 +329,16 @@ def optimization_results(task_id: str): # ===== Task 4: Backtest result API extensions ===== def _get_metrics_file_path(task_id: str) -> str | None: - """Get the metrics file path for a task_id from orchestrator config.""" + """Get the metrics file path. Resolves the request task_id to the result's + internal task_id first — run_cta_backtest writes {task_id}_metrics.json under + ITS OWN uuid task_id (result.task_id), which differs from the runner's task_id.""" orch = get_orchestrator() + r = orch.get_result(task_id) + if r is None or not getattr(r, "task_id", None): + return None if hasattr(orch, 'db_path') and orch.db_path: file_dir = os.path.dirname(os.path.abspath(orch.db_path)) - metrics_file = os.path.join(file_dir, f"{task_id}_metrics.json") + metrics_file = os.path.join(file_dir, f"{r.task_id}_metrics.json") if os.path.exists(metrics_file): return metrics_file return None