From 93443957603c5a1f5157c9d2f10c4215c7a59fe2 Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Mon, 11 May 2026 22:58:03 +0200 Subject: [PATCH] fix(dashboard): cost live durante run (era 0 fino a complete_run) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: la dashboard mostrava \$0.0000 per Cost (USD) durante i run in corso perché leggeva runs.total_cost_usd, che viene aggiornato solo dentro Repository.complete_run a fine run. I record per-call esistevano già in cost_records (124 record / \$0.019 sul run phase2-qwen3-001 attivo). Fix: in _snapshot() se il run è status=running uso Repository.total_cost(run_id) che fa SUM(cost_usd) live su cost_records. Per i run completed/failed continuo a leggere total_cost_usd dal record runs (storico autoritativo). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/multi_swarm/dashboard/nicegui_app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/multi_swarm/dashboard/nicegui_app.py b/src/multi_swarm/dashboard/nicegui_app.py index 701b152..56bcf2d 100644 --- a/src/multi_swarm/dashboard/nicegui_app.py +++ b/src/multi_swarm/dashboard/nicegui_app.py @@ -402,6 +402,11 @@ def _snapshot(run_id: str) -> dict[str, Any]: evals_total = max(pop_size * n_gens, 1) evals_done = len(evals) gens_done = int(gens["completed_at"].notna().sum()) if not gens.empty else 0 + # runs.total_cost_usd è 0 finché complete_run non viene chiamato. + # Per le run in corso leggiamo la somma live da cost_records. + live_cost = float(repo.total_cost(run_id)) if ov["status"] == "running" else float( + ov["total_cost_usd"] + ) top_fit = float(evals["fitness"].max()) if evals_done else float("nan") median_fit = float(evals["fitness"].median()) if evals_done else float("nan") @@ -414,7 +419,7 @@ def _snapshot(run_id: str) -> dict[str, Any]: "name": cfg.get("run_name", "—"), "started_at": ov["started_at"], "completed_at": ov["completed_at"] or "—", - "cost_usd": ov["total_cost_usd"], + "cost_usd": live_cost, "pop_size": pop_size, "n_gens": n_gens, "evals_done": evals_done,