fix: detect status: failure in addition to exception for request history

Entry 3 in our logs had metadata.status='failure' but no exception string,
so it was incorrectly shown as ✅ OK. Now checks both exception AND
metadata.status == 'failure'. Also updates failed count in summary.
This commit is contained in:
rin.kagamine committed 2026-06-04 21:26:35 -04:00
1 parent 8d90c0c277
commit 71e4210386
1 file changed
+8 -3
+8 -3
View File
@@ -310,7 +310,9 @@ class Tools:
# Status — check for errors # Status — check for errors
metadata = entry.get("metadata", {}) or {} metadata = entry.get("metadata", {}) or {}
exception = metadata.get("exception", "") exception = metadata.get("exception", "")
status = "❌ FAIL" if exception else "✅ OK" status_flag = metadata.get("status", "")
is_failed = bool(exception) or status_flag == "failure"
status = "❌ FAIL" if is_failed else "✅ OK"
# Duration # Duration
duration_ms = entry.get("request_duration_ms", 0) or 0 duration_ms = entry.get("request_duration_ms", 0) or 0
@@ -358,9 +360,12 @@ class Tools:
base += f" | ${spend:.4f}" base += f" | ${spend:.4f}"
# Error info # Error info
if is_failed:
# Show exception if present, otherwise show status failure
if exception: if exception:
# Truncate long error messages
err_short = exception[:80] + "…" if len(exception) > 80 else exception err_short = exception[:80] + "…" if len(exception) > 80 else exception
else:
err_short = "status: failure"
base += f"\n └─ {err_short}" base += f"\n └─ {err_short}"
lines.append(base) lines.append(base)
@@ -371,7 +376,7 @@ class Tools:
recent_prompt = sum(e.get("prompt_tokens", 0) or 0 for e in recent) recent_prompt = sum(e.get("prompt_tokens", 0) or 0 for e in recent)
recent_completion = sum(e.get("completion_tokens", 0) or 0 for e in recent) recent_completion = sum(e.get("completion_tokens", 0) or 0 for e in recent)
recent_cache = sum(e.get("cache_read_input_tokens", 0) or 0 for e in recent) recent_cache = sum(e.get("cache_read_input_tokens", 0) or 0 for e in recent)
recent_failed = sum(1 for e in recent if (e.get("metadata", {}) or {}).get("exception")) recent_failed = sum(1 for e in recent if ((e.get("metadata", {}) or {}).get("exception")) or ((e.get("metadata", {}) or {}).get("status", "")) == "failure")
lines.append("") lines.append("")
lines.append(f" Summary ({len(recent)} shown): ${recent_spend:.4f} spent | " lines.append(f" Summary ({len(recent)} shown): ${recent_spend:.4f} spent | "