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:
1 parent
8d90c0c277
commit
71e4210386
1 file changed
+10
-5
+10
-5
@@ -310,7 +310,9 @@ class Tools:
|
||||
# Status — check for errors
|
||||
metadata = entry.get("metadata", {}) or {}
|
||||
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_ms = entry.get("request_duration_ms", 0) or 0
|
||||
@@ -358,9 +360,12 @@ class Tools:
|
||||
base += f" | ${spend:.4f}"
|
||||
|
||||
# Error info
|
||||
if exception:
|
||||
# Truncate long error messages
|
||||
err_short = exception[:80] + "…" if len(exception) > 80 else exception
|
||||
if is_failed:
|
||||
# Show exception if present, otherwise show status failure
|
||||
if exception:
|
||||
err_short = exception[:80] + "…" if len(exception) > 80 else exception
|
||||
else:
|
||||
err_short = "status: failure"
|
||||
base += f"\n └─ {err_short}"
|
||||
|
||||
lines.append(base)
|
||||
@@ -371,7 +376,7 @@ class Tools:
|
||||
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_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(f" Summary ({len(recent)} shown): ${recent_spend:.4f} spent | "
|
||||
|
||||
Reference in new issue
Block a user