Skip to content

Self-Healing Production Agent

A self-healing pipeline detects post-deploy regressions, triages whether the deploy caused them, and dispatches an agent to open a fix PR for human review.

The loop

The self-healing loop automates the first three steps of the incident cycle and keeps human judgment for the merge gate alone. The classic cycle — detect, ticket, triage, fix, review — needs a person at every hand-off.

graph TD
    A[Deploy] --> B[Run eval suite / functional tests]
    B --> C{Regression detected?}
    C -->|No| D[Done]
    C -->|Yes| E[Causality triage agent]
    E --> F{New or pre-existing?}
    F -->|Pre-existing| G[Log and skip]
    F -->|New — caused by deploy| K{Fix attempts exceeded?}
    K -->|Yes — circuit breaker| L[Escalate to human ticket]
    K -->|No| H[Fix agent]
    H --> I[Open fix PR]
    I --> J[Human review & merge]

LangChain applied this to their GTM Agent: after every deploy, the system compares eval scores before and after the deploy, triages causality, and opens a fix PR (LangChain: How My Agents Self-Heal in Production, April 2026).

Four components

1. Regression detection

Compare a fixed eval suite or functional test results before and after each deploy. A score drop or new failure triggers the loop. Use the same deterministic graders used for harness hill-climbing — test suite pass/fail and schema checks are more reliable than LLM-as-judge for repeated automated runs (Anthropic: Demystifying evals for AI agents).

Trigger condition: post-deploy score falls below a threshold or one or more test cases that previously passed now fail.

2. Causality triage

The current deploy does not cause every regression. A triage agent — the attribution step in LangChain's GTM Agent loop — compares the failure against pre-deploy baselines to find the cause:

Outcome Action
Regression present before deploy Log as pre-existing; skip fix dispatch
Regression linked to the deploy after investigation Dispatch fix agent
Ambiguous Escalate to human; do not dispatch

The causal diff — the changes in the deploy that correlate with the failure — becomes part of the fix agent's input. Without triage, every test flake generates a fix PR, burning tokens and review capacity.

3. Fix agent dispatch

The fix agent receives three inputs: the failing test, the causal diff, and a fix-PR instruction. It writes the minimal change to make the test pass without broadening scope, then opens a PR against the main branch — leaving main untouched until human merge, consistent with rollback-first design.

Scope constraints: - Fix is limited to the failing test's coverage area - No refactoring unless directly required by the fix - PR description includes the triggering eval result and the causal diff for reviewer context

4. Circuit breaker

Repeated fix attempts on the same regression — each failing — indicate the agent cannot self-resolve the issue. A circuit breaker stops dispatch after N consecutive failed attempts for a given regression identifier and escalates to a human ticket instead.

Without this gate, the loop generates unbounded fix PRs on an unfixable regression, consuming tokens and polluting the PR queue. The same principle underlies per-tool circuit breakers; here it applies at the fix-dispatch level.

Human gate

In the recommended workflow, fix PRs go to human review. The fix agent operates on a branch, leaving main unchanged until a human confirms — consistent with rollback-first design.

Replit's Monitoring Agent makes automatic publication configurable through three controls: monitoring alerts, Auto-fix, and Auto-republish, which are "separate settings". With the last enabled, "Agent can automatically publish its validated fix" to a live app (Replit docs). Replit marks it "experimental and requires Auto-fix" and warns that "Some changes, including migrations and index operations, may be risky". The cited page states no retry cap. That does not establish that retries are unbounded; this pattern separately requires a circuit breaker after N failures.

Treat an auto-publish setting as an autonomy promotion, not a convenience toggle. Progressive autonomy has the reliability metrics that earn the move. Flip it early and the loop ends with an agent that holds write access to production and no approval step.

Scope boundaries

This pattern handles post-deploy regression detection and remediation. It does not:

  • Improve overall agent quality offline (see Agentic Flywheel)
  • Tune harness configuration against an eval suite (see Harness Hill-Climbing)
  • Catch regressions introduced by the fix PR itself — the same pipeline re-runs after the fix PR merges

Example

The following pseudocode describes the orchestration contract. It requires project-specific evaluation, baseline storage, and dispatch implementations:

on successful deployment:
    load the deployed revision and its pre-deploy baseline
    run the same eval suite against the deployed service
    if the runner fails before producing valid results:
        escalate the infrastructure failure; stop
    compare valid results even when individual tests fail
    for each newly failing test:
        investigate whether the deployment caused the failure
        if causality is ambiguous:
            escalate; continue
        if the failure is pre-existing:
            record it; continue
        use a persistent (repository, regression) attempt counter
        if the attempt limit is reached:
            escalate; continue
        reserve an attempt before dispatch
        send the failing test, relevant diff, and PR instruction to the fix agent
        require review before merging the proposed fix

The regression identifier must survive fix deployments. A new commit SHA must not reset the attempt limit. A newly failing test is evidence for triage, not proof that the deployment caused it.

When this backfires

The pattern adds overhead that only pays off under specific conditions:

  • Low deploy frequency: teams shipping once a week or less rarely need automated causality triage — the deploy-to-failure gap is wide enough for manual triage to stay fast.
  • No stable eval suite: the loop needs a fixed set of deterministic graders to compare scores before and after a deploy — the same stable suite harness hill-climbing tunes against. If the eval suite itself changes between deploys, the causal diff becomes unreliable and triage produces false positives.
  • Fix agent exceeds the scope constraint: if the fix agent regularly writes changes outside the failing test's coverage area — coding-agent scope expansion — human reviewers face a growing review burden that can exceed the time saved by automated dispatch. This usually signals that the regression is architectural, not surgical.
  • High flake rate in the test suite: intermittent failures that no deploy caused trigger the triage agent repeatedly, exhaust the circuit breaker budget, and escalate noise to human tickets — the opposite of what the pattern promises.

Key Takeaways

  • Trigger on deploy events, not scheduled runs — the loop is reactive, not periodic
  • Causality triage is mandatory; without it, pre-existing failures generate spurious fix PRs
  • The fix agent's scope must be bounded to the failing test — broad fixes increase review burden and risk
  • Circuit-break after repeated failures on the same regression; unbounded dispatch wastes tokens and review capacity
  • Default to human review at merge; where a product makes it a setting, promote off that default on measured reliability, not on a checkbox