Improve failed executions error extraction and counting

Extract error messages from the stats JSON field in failed executions details. Update the admin diagnostics route to always count the actual number of failed executions within the specified time window, ensuring accurate pagination.
This commit is contained in:
Nicholas Tindle
2025-11-03 18:37:01 -06:00
parent 6068ed3516
commit 1403c8f2de
2 changed files with 15 additions and 6 deletions

View File

@@ -978,6 +978,11 @@ async def get_failed_executions_details(
results = []
for exec in executions:
# Extract error from stats JSON field
error_message = None
if exec.stats and isinstance(exec.stats, dict):
error_message = exec.stats.get("error")
results.append(
FailedExecutionDetail(
execution_id=exec.id,
@@ -994,7 +999,7 @@ async def get_failed_executions_details(
created_at=exec.createdAt,
started_at=exec.startedAt,
failed_at=exec.updatedAt,
error_message=getattr(exec, "error", None),
error_message=error_message,
)
)

View File

@@ -1,5 +1,5 @@
import logging
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone
from typing import List
from autogpt_libs.auth import requires_admin_user
@@ -281,10 +281,14 @@ async def list_failed_executions(
)
# Get total count for pagination
from backend.data.diagnostics import get_execution_diagnostics as get_diag
diagnostics = await get_diag()
total = diagnostics.failed_count_24h if hours == 24 else len(executions)
# Always count actual total for given hours parameter
cutoff = datetime.now(timezone.utc) - timedelta(hours=hours)
total = await AgentGraphExecution.prisma().count(
where={
"executionStatus": AgentExecutionStatus.FAILED,
"updatedAt": {"gte": cutoff},
}
)
return FailedExecutionsListResponse(executions=executions, total=total)
except Exception as e: