Factorik Factorik Start free trial
← See all articles

From Sentry Alert to Merged Fix With an AI Agent

Quick answer: An AI bug-fixing agent wakes when an alert or issue reports a bug, reads the error and the production data behind it, reproduces the bug with a failing test, fixes the cause and proves the fix before it opens a pull request. When it cannot reproduce or fix the bug safely, a good agent stops and says why and who has to act, instead of guessing. The pull request then goes through the same checks, review and merge policy as any other change.

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

What is an AI bug-fixing agent, and what should it actually do?

An AI bug-fixing agent is a coding agent with one narrow job: take a reported bug, find out why it happens, change the code so it stops happening, and show evidence that it stopped. The report can come from an error tracker such as Sentry, from an issue a person opened, or from a label someone put on an issue. The output is a pull request, or an honest statement that the agent could not finish.

The word that matters in that definition is cause. A stack trace points at the line that threw, which is rarely the line that is wrong. A null value that crashes a price formatter was usually produced somewhere upstream: an API that started returning a new shape, a migration that left old rows empty, a feature flag that skipped an initialisation step. An agent that adds a null check at the crash site makes the alert go quiet and leaves the real defect in place, often to surface somewhere harder to see.

So a useful bug-fixing agent behaves the way a careful engineer on call behaves. It reads the error and the request that triggered it. It looks at production data to see how many users are affected and what they have in common. It writes a test that fails for the same reason production fails. Only then does it change code, and it is done when that test passes and nothing else broke.

This article walks through that loop step by step, from a Sentry alert to a merged fix, and then covers what happens when the loop does not close: when the bug cannot be reproduced, when the fix needs a decision nobody gave the agent, or when the report itself is too thin to act on.

Why do AI-generated bug fixes go wrong?

AI coding tools have made it cheap to produce a plausible patch, and plausible is not the same as correct. Faros AI's AI Engineering Report 2026, a vendor report published in April 2026 from the telemetry of about 22,000 developers, found bugs per developer up 54% between each organization's periods of lowest and highest AI adoption. That figure is about AI-assisted code in general, not about bug fixing, but it describes the environment a bug-fixing agent works in: more code, written faster, with more defects to chase.

Commentary on AI-written code points at the same patterns again and again. Generated code can run and pass its tests while coverage stays incomplete. Tests written by the same model often repeat the wrong assumption the code makes, so they pass for the wrong reason. Hallucinated APIs, duplicated logic, missing error handling and undocumented decisions show up often. A bug fix written without a reproduction inherits every one of these risks, because nothing forces it to confront what actually happened in production.

Security is the other quiet risk. "Trust but Verify? Uncovering the Security Debt of Autonomous Coding Agents", a preprint posted to arXiv in July 2026 that studied 4,022 agent-generated pull requests, reports that 38.9% of them contain at least one security smell. A fix that swallows an exception, widens a permission check to make an error disappear, or logs a full request body to help debugging can close one ticket and open a worse one.

None of this argues against letting agents fix bugs. It argues for a workflow that makes them prove the fix, keeps their changes small and reviewable, and puts the merge decision behind the same gates every other change passes.

+54%
Bugs per developer, each organization's lowest to highest AI adoption
Faros AI, AI Engineering Report 2026, April 2026, about 22,000 developers (vendor report)
38.9%
Agent-generated pull requests with at least one security smell
"Trust but Verify?", arXiv preprint, July 2026, 4,022 pull requests
Why a bug fix needs evidence, not just a plausible patch

How does a Sentry alert become a pull request? A worked example

Here is the whole loop on an illustrative repository, acme/checkout-web, a TypeScript storefront. It is an example of how the steps fit together, not a customer story. The team has a Factorik agent made from the Bug Fixer preset, pointed at this repository, with Sentry and the read-only production Postgres connected as tools. Its trigger is an incoming webhook, and the webhook URL is set as the target of a Sentry alert rule for new issues in the checkout project.

Step one, the event. Sentry records a new issue: TypeError: Cannot read properties of undefined (reading 'currency'), thrown in src/lib/pricing/formatPrice.ts, 412 events in the last hour. The alert rule fires and calls the webhook. Factorik records the event and queues a run of the Bug Fixer. The same run could just as well start from an issue titled "Checkout total shows blank for gift card orders" being opened, or from someone adding a chosen label such as bug to an existing issue.

Step two, the sandbox. The run starts in an isolated sandbox with a clone of the repository. The sandbox gets a short-lived token that can only read this one repository; it cannot push, open pull requests or touch any other repository. The agent also reads the team's standing rules for this agent, recent feedback, and any findings on its past changes, so it knows, for example, that the team wants every fix to include a regression test and never wants a dependency bumped inside a bug fix.

Step three, the diagnosis. The agent calls Sentry through the connected tool and reads the event: the stack trace, the breadcrumbs, the request path /api/cart/summary, and the tags showing every affected cart contains a gift card. It queries Postgres and finds that gift card line items created since the last release have a null price_currency, because a new import job writes the amount and leaves the currency empty. The crash site is formatPrice; the cause is the import job in src/jobs/importGiftCards.ts. These tool calls do not happen inside the sandbox with credentials it can copy: they go through Factorik's gateway, which holds the credentials on the server and records each call.

Step four, the reproduction. The agent adds a test to src/jobs/importGiftCards.test.ts that imports a gift card fixture and asserts the stored line item carries the order's currency. It runs the test and watches it fail with the same missing value seen in production. It adds a second test to formatPrice.test.ts showing that a line item with no currency throws, because the team's rules say formatters should fail loudly rather than print a blank price.

Step five, the fix and the proof. The agent changes the import job to copy the order currency onto each gift card line item, and adds a one-off backfill note to the pull request rather than a migration, since migrations are a protected path for this team. It runs the new tests, which now pass, then the full test suite and the type check. The run ends with the outcome "pull request": the server reads the change out of the sandbox and publishes it as one commit on a new branch it names, and opens the pull request with the diagnosis, the evidence and the commands it ran.

Step six, the checks and the merge. GitHub runs CI on the pull request. If the repository has a Code Reviewer agent, it reviews the change and ends with a verdict on that exact commit. This Bug Fixer is at the first level, so a person reads the pull request and merges it. After the merge the change is still watched: if CI or a deploy fails at the merged commit, or the change is reverted, that becomes a finding the team is told about and the agent reads on its next runs.

StepWhat happensEvidence left behind
EventSentry alert rule calls the agent's webhookRecorded event and queued run
SandboxClone with a short-lived, read-only token for one repositoryRun log
DiagnosisReads the Sentry event and queries production data through the gatewayRecorded tool calls
ReproductionWrites a test that fails the way production failsFailing test output
Fix and proofChanges the cause, runs the new tests and the full suitePassing test output
Pull requestServer publishes one commit on a new branch and opens the pull requestDiff, description, checks
MergeA person merges at the first level; later levels follow the merge policyMerge decision
The illustrative run on acme/checkout-web, step by step

How does an AI agent prove a bug fix works?

The proof is a test that failed before the change and passes after it, for the reason the bug report describes. That sounds obvious, and it is the step most often skipped. An agent that writes the fix first and the test second tends to write a test shaped like its fix, which passes whether or not the fix addresses what users hit.

Order matters, then. Reproduce first, watch it fail, read the failure message and confirm it matches production. A failing test that fails for a different reason, such as a missing fixture or an import error, proves nothing. A good pull request from a bug-fixing agent shows the failing output, the change, and the passing output, so a reviewer can check the chain without rerunning it.

Not every bug fits a unit test. A layout bug on a phone, a race between two workers, or a slow query that only hurts with production-sized data needs different evidence: a screenshot of the page before and after, a script that runs the two workers against each other many times, or the query plan and timing from a copy of real data. The principle is the same. The agent should show the bug happening, change the code, and show it no longer happening, in whatever form the bug allows.

Then the rest of the suite has to pass. A fix that makes one test green and breaks three others is not a fix, and an agent that runs only its own test will not notice. Running the full suite, the type check and the linter inside the sandbox before the pull request opens saves a round trip through CI and a reviewer's time.

What happens when the agent cannot fix the bug, and what are its limits?

Sometimes the honest answer is that the agent should not fix it. The bug may live in a third-party service. The fix may need a product decision, such as whether gift cards should be allowed in a currency the store no longer sells. The data may need a correction only a person with production write access should make. Or the reproduction may simply not come: the error appeared twice, under conditions the agent cannot recreate.

In Factorik, a run in that position ends "blocked" and says why and who has to act, rather than producing a speculative patch. A blocked run publishes nothing. If the agent understands the problem but the fix involves a choice, it can instead finish with a proposal: a written plan that a person can build, reply to so the author revises it, or turn down. By default a proposal waits for a person to decide; it starts without one only where an owner switched that on for the agent or its team, and one that asks for a decision always waits.

If the agent found nothing wrong, for example because the error came from a bot sending malformed requests that the code already rejects correctly, it can end with "nothing to do" and explain what it checked. That outcome is useful in its own right: it tells the on-call engineer the alert is noise and why.

These outcomes are not failures of the workflow. A bug-fixing agent that always produces a pull request is one that sometimes produces a wrong one. The value of letting it say "blocked" is that the pull requests it does open are the ones it could prove.

An agent fixes what it can reproduce and prove inside a sandbox with the tools it was given. It does not write to production data, and it does not push to the default branch: in Factorik the server publishes one commit on a branch it names, never forced. At the first level a person merges every fix. Later levels, earned on a record of merged changes without problems, let it merge low-risk changes and then whatever the merge policy allows, and any problem traced to one of its merged changes moves it down a level at once.

It also depends on what it can see. An agent without access to the error tracker or the logs is guessing from the stack trace in an issue. Connecting the tools is part of setting it up, and each connection is a choice about what the agent may read. Credentials stay on Factorik's server and each call is recorded, but read access to production data is still access, and teams should grant what the job needs.

Pros
  • +Every fix arrives with a reproduction and the commands that prove it
  • +Alerts get a diagnosis within one run instead of waiting for someone free
  • +Small, single-bug pull requests that are quick to review
  • +Runs that cannot prove a fix end blocked and say who must act
Cons
  • −Needs connected tools to see production; without them it guesses
  • −Bugs that need product decisions or production data changes stay with people
  • −Hard-to-reproduce bugs often end blocked rather than fixed
  • −A person still merges until the agent's record earns more
Trade-offs of handing bug fixing to an agent

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

Can an AI agent find bugs before anyone reports them?

Alerts and issues are reactive: they wake an agent after someone or something noticed. Many teams also carry a backlog of errors nobody filed, the ones that fire a few times a day, affect a small group of users, and never cross an alert threshold. Those are often the cheapest to fix and the easiest to forget.

The Production Bug Hunter preset covers that ground. It runs on a schedule, for instance every weekday morning in the team's time zone, checks production through the connected tools, picks the bug that is hurting users most, and fixes it with the same reproduce, fix and prove loop. One bug per run keeps each pull request small enough to review in a few minutes.

Giving the scheduled task a sharp focus helps. "Look at the last 24 hours of errors in the checkout project and fix the one affecting the most users" produces better runs than "find bugs". The team's rules can add limits, such as never touching the payment provider integration, which a person handles.

The two presets fit together. The Bug Fixer answers what people and alerts report. The Production Bug Hunter works the long tail that no one reported. Both open pull requests at their level and both are watched after merge, so neither is trusted further than its record.

How do I write issues an AI bug-fixing agent can act on?

An agent reads an issue the way a new hire reads it: literally, without the hallway context. The issues that produce good runs are the ones that would also help a new hire. They say what happened, what should have happened, and where to look.

Start with the observed behaviour in one sentence, including the exact error text if there is one. "Checkout total shows blank for orders containing a gift card" beats "checkout broken". Add how to reach it: the page or endpoint, the kind of account or data involved, and whether it happens every time. Link or paste the Sentry issue title, the request ID or the user ID, since the agent can look those up through connected tools when they are named.

Say what you already know and what you suspect, and mark which is which. "Started after Tuesday's release; I suspect the gift card import job" saves the agent an hour of searching and leaves it free to disagree if the evidence points elsewhere. Say what is out of scope too: "do not change the pricing API contract" or "the fix must not need a migration".

Keep in mind that issue text is treated as data, not instructions. Factorik fences what people write in issues and comments in the prompt so that a sentence in an issue cannot quietly change the agent's job. That protects the run from hostile text, and it also means the place to set lasting rules, such as "always add a regression test", is the agent's standing rules, not individual issues. On a public repository, people outside the team do not start agents unless the trigger allows anyone, so a stranger's issue does not wake the Bug Fixer by default.

How do I try an AI bug-fixing agent on my repository?

Pick one repository with a test suite and CI, and one source of bugs: a Sentry alert rule, or a label on issues. Create an agent from the Bug Fixer preset, connect the error tracker it should read, and write two or three standing rules about what a fix must include. Leave it at the first level and read its first pull requests closely, including the failing test it wrote and whether the cause it named is the real one.

You can do this on a free 7-day trial of the Team plan, with no payment details needed. Point a real alert at it, see what comes back, and let its record decide how far you trust it.

Frequently asked questions

Can an AI agent fix bugs directly from Sentry alerts?

Yes, when the alert can call a URL. In Factorik a Sentry alert rule can call an agent's incoming webhook, which starts a run of the Bug Fixer. The agent reads the error through the connected Sentry tool, reproduces it, fixes the cause and opens a pull request, or ends blocked with the reason.

Does an AI bug-fixing agent push changes to my main branch?

Not in Factorik. The sandbox only gets a short-lived read-only token for one repository, and the server publishes the change as one commit on a new branch it names, never forced. A pull request is merged only when the agent's level and the repository's merge policy allow it, and at the first level a person merges.

What if the agent cannot reproduce the bug?

It should not guess. A Factorik run that cannot reproduce or safely fix a bug ends blocked and says why and who needs to act, and it publishes nothing. If the fix needs a decision, the agent can leave a proposal for a person to build, revise or turn down.

How is the Production Bug Hunter different from the Bug Fixer?

The Bug Fixer acts on a reported bug, from an alert, an issue or a label. The Production Bug Hunter runs on a schedule, checks production through connected tools and fixes the bug hurting users most, so it covers errors nobody filed.

Can someone trick the agent with text in an issue?

No system makes prompt injection impossible, so the design limits what a run can do. Issue and comment text is fenced as data in the prompt, the sandbox cannot write to GitHub, tool credentials stay on the server, and on public repositories outsiders do not start agents unless the trigger allows anyone.

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

How helpful was this article?

Articles by Factorik →