Every team has a backlog of production errors that are real, understood well enough and never quite urgent enough to fix this sprint. A null check here, an unhandled timeout there, a parser that chokes on one customer’s data. They sit in Sentry collecting events until someone has a quiet afternoon.

That backlog is a good fit for agents. Errors come with a stack trace, a release, often a reproduction path, and an unambiguous definition of done: the error stops happening and a test proves it. This guide walks through a workflow that turns a Sentry alert into a reviewed fix pull request, and the guardrails that keep it safe.

Which errors are good candidates

Not every error should go to an agent. Start with the ones where a fix is likely to be local and verifiable.

Good candidatesKeep with people
Null or undefined access with a clear stack traceErrors caused by infrastructure or capacity
Unhandled edge cases in parsing or validationData corruption or anything needing a data repair
Missing error handling around a network callSecurity-related exceptions
Type errors introduced by a recent releaseErrors you cannot reproduce outside production
Deprecation warnings with a known replacementIssues spanning several services

A practical filter: if an engineer could plausibly fix it in under an hour once they understood it, it is a good candidate.

The workflow at a glance

  1. Trigger on a Sentry alert that crosses a threshold you choose.
  2. Triage: collect the stack trace, release, tags and recent changes, and decide whether the error is in scope.
  3. Reproduce: write a failing test that triggers the same error.
  4. Plan the fix and route it for approval if it touches anything sensitive.
  5. Implement the fix so the new test passes.
  6. Verify: run the full suite and any contract tests.
  7. Review and deliver: open a pull request that links back to the Sentry issue.

Each step is covered below.

Step 1: Trigger on the right signal

Sentry can notify external services when an alert rule fires, through its integrations or a webhook. The workflow’s trigger should listen for those notifications, but not for every event.

Most of the design work is in deciding what fires:

  • Use a threshold. “More than N events in an hour” or “affecting more than N users” filters out one-off noise. Choose numbers that match how your team already prioritises.
  • Scope by project and environment. Start with one service and production only. Errors in staging are often caused by half-finished work.
  • Deduplicate. One Sentry issue should start at most one run. If a run is already open for an issue, new alerts should attach to it rather than start another.
  • Skip what is already handled. Ignore issues that are assigned, resolved or linked to an open pull request.

A webhook trigger exposes the alert payload to later steps, so the run starts with the issue ID, the project and a link back to Sentry.

Step 2: Triage before touching code

The first agent step gathers context and decides whether the run should continue. It reads:

  • the stack trace and the frames inside your code,
  • the release and the commits in it, especially changes to the files in the trace,
  • tags such as browser, route or customer plan, which often point at the triggering condition,
  • breadcrumbs leading up to the error.

The output is a short triage note: the likely cause, the files involved, a confidence level and a recommendation to continue or to hand off. A decide step routes on that recommendation. Out-of-scope errors, such as infrastructure, data or security problems, go to a person with the triage note attached instead of to implementation. That alone saves review time, because the agent stops early on work it should not attempt.

Step 3: Reproduce with a failing test

This is the step that makes the whole workflow trustworthy. Before changing any application code, the agent writes a test that triggers the same error, and a check confirms that the test fails for the right reason.

If the agent cannot reproduce the error, the run stops and escalates. A fix without a reproduction is a guess, and reviewing guesses is expensive.

Step 4: Plan the fix and decide who approves

With a reproduction in hand, the agent writes a plan: the root cause, the change, and any side effects. Route approval by risk:

  • Low risk (a guard clause, a missing default, a corrected type): the plan can proceed automatically, because the failing test and later review provide the safety net.
  • Higher risk (changes to shared libraries, schema, authentication or payment paths): require a person to approve the plan before implementation.

A rule can make this automatic, for example “Changes under billing/ require plan approval”.

Step 5: Implement the fix

The implementer works in an isolated sandbox, makes the change and runs the reproduction test until it passes. Instructions should emphasise a minimal fix: handle the failing case, keep the diff small and resist refactoring nearby code. Small diffs are faster to review and safer to ship.

Step 6: Verify

A deterministic check runs the full suite, type checks and linters. If anything fails, the run returns to implementation with the output attached, up to a small number of attempts before escalating.

For services with contract or integration tests, run those too. A fix that makes one error disappear by changing a response shape is not a fix.

An agent reviewer checks that the diff matches the plan and includes the regression test. Then the workflow opens a pull request that:

  • links to the Sentry issue and quotes the key frame of the stack trace,
  • explains the root cause in two or three sentences,
  • points at the regression test,
  • requests review from the code owners of the files touched.

Once the pull request merges and ships, mark the issue in Sentry as resolved in the next release. If the error comes back after that release, Sentry flags it as a regression, which is a useful signal that the fix was incomplete.

Guardrails for production errors

Error-driven workflows need a few guardrails beyond the usual ones:

  • No production access. The agent works from the alert payload and the repository. It never queries production systems or customer data.
  • Concurrency limits. A bad deploy can fire many alerts at once. Cap concurrent runs for this workflow so an incident does not turn into a stack of speculative pull requests.
  • Per-run budget. Set a modest spend cap. A fix that needs a large budget probably needs a person. See Controlling AI agent spend.
  • Never during an incident. Consider pausing the workflow while an incident is open, so agent pull requests do not compete with the response.
  • Escalate generously. When triage confidence is low, hand off. A short note to a person is cheap; a wrong fix is not.

How to tell if it is working

Track a handful of signals per week, from your own data:

  • how many alerts started a run, and how many ended in a merged pull request,
  • how often triage stopped early, and whether it was right to,
  • how many fixes regressed after release,
  • how long runs waited on people, and at which step.

If most runs fail at reproduction, the problem is usually missing test infrastructure for that service, not the agent. Fixing that helps your human engineers too.

Frequently asked questions

Can an AI agent fix Sentry errors automatically?

For a well-chosen subset, yes: localised errors with a clear stack trace and a reproducible cause. The safe pattern is that the agent proposes a fix as a pull request with a regression test, and a person reviews it before it merges.

What does the agent need access to?

The alert payload from Sentry, read access to the repository, and a sandbox where it can run your test suite. It should not need production credentials.

How do we avoid duplicate pull requests for the same error?

Deduplicate at the trigger: one Sentry issue maps to at most one open run, and later alerts for the same issue attach to it.

What if the agent cannot reproduce the error?

The run should stop and hand off to a person with its triage notes. Without a failing test, there is no reliable way to know the fix works.

Connect your error monitoring

Duun connects to Sentry, Linear, GitHub and more, and lets you build this workflow with approvals and budgets in place. See Designing an AI agent workflow for the underlying patterns and the docs on connecting integrations and workflow triggers for setup. Duun is in early access: request access.