mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
fix(backend): lower PlatformCostLog DataError to warning during schema mismatch
The autogpt-database-manager pod can run a stale Prisma client immediately after a schema migration (e.g. rolling deploy of PR #12696 that added PlatformCostLog). This caused every copilot token-tracking write to raise prisma.errors.DataError ('userId'/'metadata' field not found), which was caught by logger.exception() — firing Sentry events at ERROR level. Catch DataError specifically in both log_platform_cost_safe (platform_cost.py) and the _safe_log closure in token_tracking.py, and demote to WARNING so Sentry is not spammed during deploy windows. All other exceptions still escalate to ERROR/Sentry as before.
This commit is contained in:
@@ -15,6 +15,8 @@ import math
|
||||
import re
|
||||
import threading
|
||||
|
||||
from prisma.errors import DataError
|
||||
|
||||
from backend.data.db_accessors import platform_cost_db
|
||||
from backend.data.platform_cost import PlatformCostEntry, usd_to_microdollars
|
||||
|
||||
@@ -50,6 +52,18 @@ def _schedule_cost_log(entry: PlatformCostEntry) -> None:
|
||||
async with _get_log_semaphore():
|
||||
try:
|
||||
await platform_cost_db().log_platform_cost(entry)
|
||||
except DataError as e:
|
||||
# Prisma DataError typically means the DB manager pod is running a
|
||||
# stale Prisma client (e.g. during a rolling deploy after a schema
|
||||
# migration). Log at WARNING so Sentry is not spammed.
|
||||
logger.warning(
|
||||
"Skipping platform cost log (schema mismatch?) for "
|
||||
"user=%s provider=%s block=%s: %s",
|
||||
entry.user_id,
|
||||
entry.provider,
|
||||
entry.block_name,
|
||||
e,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to log platform cost for user=%s provider=%s block=%s",
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any
|
||||
|
||||
from prisma.errors import DataError
|
||||
from prisma.models import PlatformCostLog as PrismaLog
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -87,6 +88,18 @@ async def log_platform_cost_safe(entry: PlatformCostEntry) -> None:
|
||||
try:
|
||||
async with _log_semaphore:
|
||||
await log_platform_cost(entry)
|
||||
except DataError as e:
|
||||
# Prisma DataError typically means the DB manager pod is running a stale
|
||||
# Prisma client (e.g. during a rolling deploy after a schema migration).
|
||||
# Log at WARNING so Sentry is not spammed.
|
||||
logger.warning(
|
||||
"Skipping platform cost log (schema mismatch?) for "
|
||||
"user=%s provider=%s block=%s: %s",
|
||||
entry.user_id,
|
||||
entry.provider,
|
||||
entry.block_name,
|
||||
e,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to log platform cost for user=%s provider=%s block=%s",
|
||||
|
||||
Reference in New Issue
Block a user