feat(ai-monitoring): Fetch model context size and rename task to fetch_ai_model_info #112656
1 issue
sentry-backend-bugs: Found 1 issue (1 medium)
Medium
Missing JSONDecodeError handling when parsing OpenRouter API response - `src/sentry/tasks/ai_agent_monitoring.py:423`
The _fetch_openrouter_models_metadata function calls response.json() without catching JSONDecodeError. External APIs can return HTML error pages (e.g., CDN errors, rate limit pages) that return HTTP 200 but contain non-JSON content. This matches the production bug pattern SENTRY-5CKF (30,593 events) where webhook bodies were truncated. If OpenRouter returns malformed JSON, the task fails with an unclear JSONDecodeError instead of a graceful warning.
Also found at:
src/sentry/tasks/ai_agent_monitoring.py:499
Duration: 2m 13s · Tokens: 641.2k in / 9.8k out · Cost: $0.87 (+extraction: $0.01, +merge: $0.00)
Annotations
Check warning on line 423 in src/sentry/tasks/ai_agent_monitoring.py
sentry-warden / warden: sentry-backend-bugs
Missing JSONDecodeError handling when parsing OpenRouter API response
The `_fetch_openrouter_models_metadata` function calls `response.json()` without catching `JSONDecodeError`. External APIs can return HTML error pages (e.g., CDN errors, rate limit pages) that return HTTP 200 but contain non-JSON content. This matches the production bug pattern SENTRY-5CKF (30,593 events) where webhook bodies were truncated. If OpenRouter returns malformed JSON, the task fails with an unclear `JSONDecodeError` instead of a graceful warning.
Check warning on line 499 in src/sentry/tasks/ai_agent_monitoring.py
sentry-warden / warden: sentry-backend-bugs
[FPW-PJC] Missing JSONDecodeError handling when parsing OpenRouter API response (additional location)
The `_fetch_openrouter_models_metadata` function calls `response.json()` without catching `JSONDecodeError`. External APIs can return HTML error pages (e.g., CDN errors, rate limit pages) that return HTTP 200 but contain non-JSON content. This matches the production bug pattern SENTRY-5CKF (30,593 events) where webhook bodies were truncated. If OpenRouter returns malformed JSON, the task fails with an unclear `JSONDecodeError` instead of a graceful warning.