mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
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:
@@ -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,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user