DEV Community

Alan P. Oliver
Alan P. Oliver

Posted on

How I Built an AI Agent That Monitors My SaaS and Fixes Issues Before Users Notice

My SaaS has 2,400 users. I'm a solo dev. Two months ago I built an AI agent that monitors production and automatically fixes common issues. It's saved me from at least 3 outages.

The Architecture

Vercel (Next.js) → Sentry (errors) → Webhook → AI Agent → GitHub PR / Hotfix
Enter fullscreen mode Exit fullscreen mode

The agent runs as a Vercel serverless function triggered by Sentry webhooks. When an error hits a threshold (>5 occurrences in 10 minutes), the agent:

  1. Fetches the error details + stack trace from Sentry
  2. Pulls the relevant source files from GitHub
  3. Analyzes the root cause
  4. Generates a fix
  5. Runs the test suite against the fix
  6. If tests pass, opens a PR (or auto-merges for known safe patterns)

What It's Fixed Automatically

  • Database connection pool exhaustion — It detected the leak pattern and added proper connection cleanup
  • Rate limit errors from a third-party API — Added exponential backoff that I'd been meaning to implement
  • Null pointer in a new feature — Added a guard clause and a comment "auto-fixed: missing null check on user.subscription"

What It Can't Fix

  • Business logic bugs (it doesn't know what the product should do)
  • Performance issues (it can spot N+1 queries but won't restructure your data model)
  • Anything requiring a database migration

The Cost

About $30/month in AI API costs. Compared to being woken up at 3am or losing users to preventable bugs, it's the best $30 I spend.

Key Lessons

  1. Start narrow. Don't try to auto-fix everything. Start with null pointer errors and connection issues.
  2. Always require tests to pass. The agent can't merge if it can't prove the fix is safe.
  3. Log everything. I have a full audit trail of every auto-fix. This saved me when one "fix" introduced a subtle regression.

Solo devs: you need this. You can't monitor production 24/7, but an AI agent can.

Happy to share the webhook handler code if there's interest.

Top comments (1)

Collapse
 
kalihl3 profile image
Tim F.

Super useful. This saved me a lot of time figuring things out on my own.