Sentry backend bugs

From getsentry/sentry · View interactive version

Sentry backend bugs is an AI agent skill from the GitHub repository getsentry/sentry. Review Sentry Python and Django changes for bug patterns drawn from real production issues. Use when reviewing a backend diff or PR, checking Warden findings, auditing the current branch, reviewing production-error patterns, or looking for common regressions in `src/` and `tests/`.

How to use this skill

Skill file

Sentry Backend Bug Pattern Review

Find bugs in Sentry backend code by checking for the patterns that cause the most real production errors.

This skill encodes patterns from 638 real production issues (393 resolved, 220 unresolved, 25 ignored) generating over 27 million error events across 65,000+ affected users. These are not theoretical risks -- they are the actual bugs that ship most often, with known fixes from resolved issues.

Scope

Review the code provided by the user, Warden, or the current branch diff. If the user does not provide a target, review the current branch diff. Start from the changed hunk or file, then read outward only as needed to confirm the behavior.

  1. Analyze the changed code against the pattern checks below.
  2. Use Read and Grep to trace data flow beyond the initial diff when needed. Follow function calls, callers, serializers, tasks, and ORM boundaries until the behavior is confirmed.
  3. Report only HIGH and MEDIUM confidence findings.

| Confidence | Criteria | Action |

| ---------- | --------------------------------------------------------------------- | ---------------------------- |

| HIGH | Traced the code path, confirmed the pattern matches a known bug class | Report with fix |

| MEDIUM | Pattern is present but context may mitigate it | Report as needs verification |

| LOW | Theoretical or mitigated elsewhere | Do not report |

Step 1: Classify the Code

Determine what you are reviewing and load the relevant reference.

| Code Type | Load Reference |

| ----------------------------------------------------------------- | ------------------------------------ |

| ORM queries, model lookups, .objects.get(), FK access | references/missing-records.md |

| Type conversions, None handling, option reads, serializer returns | references/null-and-type-errors.md |

| Data input parsing, field lengths, request bodies, decompression | references/data-validation.md |

| get_or_create, save(), unique constraints, integer overflow | references/database-integrity.md |

| Integration webhooks, external API calls, SentryApp hooks | references/integration-errors.md |

| Dict iteration, shared state, concurrent access | references/concurrency-bugs.md |

| Snuba queries, metric subscriptions, search filters | references/query-validation.md |

| Redirect URLs, URL construction, routing | references/url-safety.md |

If the code spans multiple categories, load all relevant references.

Step 2: Check for Top Bug Patterns

These are ordered by combined frequency and impact from real production data.

Check 1: Metric Subscription Query Errors -- 113 issues, 3,035,640 events

Alert and metric subscriptions referencing tags or functions that do not exist in the target dataset. These fire continuously once created.

Red flags:

Safe patterns:

Check 2: Missing Record / Stale Reference -- 81 issues, 1,403,592 events

Code calls .get() on a Django model assuming the record exists, but it has been deleted, merged, or never created.

Red flags:

Safe patterns:

Not a bug — do not flag:

Check 3: Search Query Validation -- 57 issues, 2,001,330 events

InvalidSearchQuery from user-provided or subscription-stored query filters referencing invalid values, deleted issues, or unresolved tags.

Red flags:

Safe patterns:

Check 4: Value Validation Errors -- 45 issues, 1,000,624 events

ValueError from insufficient input validation: unpacking errors, invalid enum values, missing expected objects, and Pydantic/DRF validation failures.

Red flags:

Safe patterns:

Check 5: Type Errors -- 28 issues, 740,106 events

Wrong types passed to functions: iterating over non-iterables, invalid dict keys, None where object expected.

Red flags:

Safe patterns:

Check 6: Internal API Request Errors -- 71 issues, 829,753 events

ApiError from internal Sentry API calls between services, often caused by stale subscription parameters.

Red flags:

Safe patterns:

Check 7: Database Constraint Violations -- 22 issues, 2,962,198 events

IntegrityError and DataError from integer overflow, foreign key violations, and unique constraint violations.

Red flags:

Safe patterns:

Check 8: Data Parsing & Deserialization -- 19 issues, 272,812 events

JSONDecodeError and ZstdError from parsing external data or stored compressed data.

Red flags:

Safe patterns:

Check 9: Missing Key Access (KeyError) -- 25 issues, 155,020 events

Accessing dictionary keys or HTTP headers without existence check.

Red flags:

Safe patterns:

Check 10: Concurrency and Runtime Bugs -- 23 issues, 38,443 events

Dictionary mutation during iteration, shared mutable state, and unimplemented code paths.

Red flags:

Safe patterns:

Check 11: Logic Correctness -- not pattern-based

After checking all known patterns above, reason about the changed code itself:

Only report if you can trace a specific input that triggers the bug. Do not report theoretical concerns.

Not a bug — do not flag:

If no checks produced a potential finding, stop and report zero findings. Do not invent issues to fill the report. An empty result is the correct output when the code has no bugs matching these patterns.

Each code location should be reported once under the most specific matching pattern. Do not flag the same line under multiple checks.

Step 3: Report Findings

For each finding, provide the evidence the review harness needs:

Fix suggestions must include actual code. Never suggest a comment or docstring as a fix.

When suggesting fixes in API endpoints, use appropriate HTTP status codes (404 for not found, 400 for bad input, 409 for conflicts). Never suggest returning 500 intentionally.

Do not prescribe your own output format — the review harness controls the response structure.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.