All Articles

How I Automatically Fixed 100 Bugs on Sentry

AI Automation Sentry

You know the feeling. You open your Sentry dashboard and see hundreds of bugs. Many of them are simple null pointer exceptions or range errors that would be easy to fix. But who has the time to work through each stacktrace one by one?

I thought: this has to be automatable. The result is ralph-sentry-fixer, an AI agent that automatically analyzes bugs from Sentry, fixes them, and creates pull requests. In my Flutter project Space, the agent has already successfully fixed 132 bugs.

What is ralph-sentry-fixer?

ralph-sentry-fixer is an automation tool that uses Claude AI to systematically fix Sentry bugs. The tool is based on the Ralph Wiggum Plugin from Claude Code, an iterative AI loop approach. The name is a reference to Ralph Wiggum from The Simpsons, who “learns through mistakes”.

The principle behind Ralph Wiggum: Claude works in a loop on a task until it’s done. Each iteration sees the modified files and can build on them. For Sentry bugs, this means: the agent picks up a bug, fixes it, creates a PR, and moves on to the next one.

The tool works in three phases:

  1. PLAN: Load bugs from Sentry and prioritize by impact
  2. BUILD: Implement fixes and create pull requests
  3. REVIEW: Handle code review comments

Each phase runs as its own Claude agent in an endless loop until all bugs are fixed.

Prerequisites

  • Claude Code CLI (claude command)
  • GitHub CLI (gh), authenticated
  • Flutter SDK (or adapted for your project)
  • Node.js 18+ (for the Sentry MCP server)
  • A Sentry account with API access

Not just for Flutter

The tool was developed for a Flutter project but can easily be adapted for other languages. The fix patterns are universal: null checks, range validation, and collection safety exist everywhere.

Installation & Setup

1. Clone the repository

Clone the repository next to your project:

git clone https://github.com/friebetill/ralph-sentry-fixer
cd ralph-sentry-fixer
your-workspace/
├── ralph-sentry-fixer/   # This repo
└── your-flutter-app/     # Your project

2. Create configuration

Copy the environment variables template and customize it:

cp .env.example .env

Edit .env with your configuration:

GITHUB_ORG=your-github-org
GITHUB_REPO=your-repo-name
PROJECT_PATH=../your-flutter-app

3. Create Implementation Plan

cp IMPLEMENTATION_PLAN.template.md IMPLEMENTATION_PLAN.md

4. Directory structure

ralph-sentry-fixer/
├── loop.sh                         # Main script to start
├── .env                            # Your configuration (gitignored)
├── PROMPT_plan.md                  # Prompt for PLAN phase
├── PROMPT_build.md                 # Prompt for BUILD phase
├── PROMPT_review.md                # Prompt for REVIEW phase
├── IMPLEMENTATION_PLAN.md          # Bug list (gitignored)
├── IMPLEMENTATION_PLAN.template.md # Template for the plan
├── AGENTS.md                       # Codebase patterns
└── specs/                          # Project specification

5. Customize AGENTS.md

The AGENTS.md file describes your codebase patterns. Claude uses this info to write better fixes:

# My Project Patterns

## Architecture
- BLoC pattern for state management
- Repository pattern for data access

## Null Safety Patterns
- Use `firstOrNull`, `lastOrNull` instead of `first`, `last`
- Use `singleWhereOrNull` instead of `singleWhere`

6. Sentry Authentication

The tool uses the official Sentry MCP Server. On first run, a browser opens for OAuth authentication.

The Three Modes in Detail

PLAN Mode: Prioritize bugs

./loop.sh plan 1    # One iteration
./loop.sh plan 5    # Five iterations
./loop.sh plan      # Unlimited

The PLAN agent connects to Sentry and:

  • Loads all unresolved issues
  • Analyzes stacktraces and categorizes error types
  • Calculates priority using: Events × 0.7 + Users × 100 × 0.3
  • Updates IMPLEMENTATION_PLAN.md

The result is a prioritized bug list:

PriorityIssue IDEventsUsersDescription
1SPACE-NK-1Z18,71385Null check in deck/card getAll
2SPACE-NK-21010,30221Null check in markdown body
3SPACE-NK-MG6,24323RangeError in review session

BUILD Mode: Implement fixes

./loop.sh build 1   # Fix one bug
./loop.sh build 5   # Fix five bugs
./loop.sh build     # Unlimited

The BUILD agent processes one bug per iteration:

  1. Reads the highest priority bug from the plan
  2. Creates a feature branch (fix/SPACE-XXX-description)
  3. Analyzes the code and implements the fix
  4. Runs flutter analyze
  5. Uses Extended Thinking for consequence analysis
  6. Creates a pull request with detailed description
  7. Updates the implementation plan

Extended Thinking

The agent uses Claude’s Extended Thinking (ultrathink) to check each fix for unintended side effects. The PR template then contains a complete consequence analysis.

REVIEW Mode: Get PRs merged

./loop.sh review 1  # One iteration
./loop.sh review    # Unlimited

The REVIEW agent monitors open PRs and:

  • Checks for unaddressed code review comments
  • Implements requested changes
  • Or explains why a suggestion won’t be implemented
  • Triggers re-reviews when needed

Practical Example: A Bug from A to Z

Here’s a concrete example from my Space project:

The Sentry Error

StateError: No element
  at List.last (dart:core/list.dart)
  at Card.latestLearningState (card.dart:61)

Impact: 952 events, 12 users affected

The Cause

// card.dart:61 - BEFORE
LearningState get latestLearningState =>
    learningState ?? learningStates.last;

The problem: learningStates.last crashes when the list is empty, even if learningState is already null.

The Automatic Fix

// card.dart:61 - AFTER
LearningState get latestLearningState =>
    learningState ?? learningStates.lastOrNull ?? _defaultLearningState;

The agent:

  1. Detected the unsafe .last operation
  2. Used lastOrNull from package:collection
  3. Added a sensible fallback

The Pull Request

The created PR automatically contains:

  • Problem description with Sentry link
  • Root cause analysis
  • Consequence analysis (Behavior Changes, Edge Cases, Risk Assessment)
  • Test checklist

Typical Fix Patterns

The agent automatically applies the following patterns:

Null Safety

// Before: Crash on null
final result = data!.value;

// After: Graceful handling
final result = data?.value ?? defaultValue;

Collection Safety

// Before: Crash on empty list
final item = list.first;
final item = list.singleWhere((x) => x.id == id);

// After: Safe alternatives
final item = list.firstOrNull;
final item = list.singleWhereOrNull((x) => x.id == id);

Range Validation

// Before: Index out of bounds
final item = list[index];

// After: Bounds check
final item = index >= 0 && index < list.length
    ? list[index]
    : null;

Results

After using ralph-sentry-fixer in my Space project:

  • 132 bugs fixed through automatically created PRs
  • All PRs merged without manual code changes
  • 0 regressions thanks to consequence analysis
  • Time saved: Estimated 40+ hours of manual work

Not a replacement for good tests

The agent fixes symptoms, not causes. Null pointer exceptions often point to deeper architectural problems. Use the tool as first aid, but also invest in better tests and type safety.

Learnings

What works well:

  • Simple defensive programming fixes (null checks, bounds checks)
  • Stacktrace analysis and root cause identification
  • PR creation with detailed documentation

What works less well:

  • Complex architectural refactorings
  • Bugs without clear stacktraces
  • Race conditions and timing issues

Conclusion

ralph-sentry-fixer shows how AI agents can automate repetitive bug-fixing work. Instead of manually working through hundreds of Sentry issues, you let an agent handle the grunt work.

The tool is open source on GitHub. I appreciate feedback, issues, and pull requests!

Links:

Till Friebe

About Till Friebe

Part of the FriebeDev team - four siblings from Berlin who develop Flutter apps together. With over 300,000 downloads and projects for companies like get2Card and BlazeSQL.

More about our team →

Ready for Your App?

Let's discuss your project in a free initial consultation.

Free Consultation