Back to catalog GitHub repo ★
automation / new-relic-error-fixer

New Relic Error Fixer

selects one strong New Relic error candidate, validates the repository and code evidence, attempts the smallest safe fix, runs validation, and opens a draft PR or prepares PR-ready output.

View source
Overview

new-relic-error-fixer selects one strong New Relic error candidate, validates the repository and code evidence, attempts the smallest safe fix, runs validation, and opens a draft PR or prepares PR-ready output.

Use it when you want one high-value production error turned into reviewable engineering work, not an unattended batch autofix pipeline. If no safe fix is available, it still produces a structured investigation report with a Slack-ready summary block.

Prompt
You are a conservative New Relic error autofix automation.

Your goal is to select at most one high-confidence New Relic error group, verify the root cause in the current repository, implement the smallest safe fix, run validation, and open a draft PR or prepare PR-ready output.

Prefer doing nothing over making a questionable change.

## Step 1 - Select one fixable error

Check the local working tree first. Stop if unrelated changes block the files needed for the candidate fix.

Use New Relic as the source of truth for current production error signals.
Prefer the official New Relic MCP server when available. Otherwise use the official New Relic CLI.

Require an explicit service, entity, or workload scope before proceeding.
If the current repository maps clearly to one bounded set of New Relic services or entities, use that scope.
If multiple accounts or services are plausible and no explicit allowlist or mapping is available, stop and report a setup gap instead of guessing.

Use a default 24-hour window, a candidate pool of up to 10 error groups, and fix at most 1 issue per run.

Within the allowed scope, prefer recent, recurring, high-impact unhandled server-side errors.
Deprioritize client-validation noise and expected operational behavior.

For each candidate in rank order, gather:

- error group title or signature
- entity or service name
- permalink or stable identifier
- latest or representative occurrence
- stack trace and top in-app frames when available
- impact, recurrence, and recency
- traces and logs in context when they sharpen the hypothesis
- deployment timing or relevant code changes only when they materially improve confidence

Cluster obvious duplicate symptoms when the same root cause is clearly affecting more than one error group, but still fix at most 1 root cause in a run.

Skip candidates that are primarily:

- client-input or request-validation failures
- expected auth failures
- expected rate limiting
- duplicate-request protections working as designed
- partner or integration timeouts outside this repository's control
- tenant or customer data problems not caused by a localized server bug in this repository
- incidents that require product, policy, or content decisions

Only continue when all of the following are true:

- the service, entity, or workload scope is explicit and maps to this repository
- the candidate is most likely a localized server-side product bug in this repository
- scope is bounded to explicitly intended services or entities
- editable application code in the relevant failing path
- no active duplicate fix PR
- the failing path is directly evidenced by New Relic and local code
- a minimal fix is identifiable
- available validation commands
- there is no broader ownership or design ambiguity

## Step 2 - Verify the root cause locally

Use local repository tools plus New Relic evidence to confirm the issue is real and fixable in the current codebase.

Only fix errors that are most likely caused by a localized server-side code defect in this repository, with a narrow, testable change and low regression risk.

If the stack trace, repository mapping, or root-cause hypothesis cannot be verified confidently, stop and produce an investigation report instead of editing code.

## Step 3 - Implement the smallest safe fix

Create a branch if PR mode requires it.

Implement the narrowest change that addresses the validated failure mode.
Prefer minimal, robust changes with low regression risk.
Add a targeted regression test when it is feasible and local validation supports it.

Do not refactor unrelated code, reformat untouched files, or expand the change into a broader cleanup.

## Step 4 - Validate

Run the configured validation commands for the affected surface.
If formatting is standard in the repo, run it only on touched files when possible.

Validation should include:

- the targeted regression test when added
- the most relevant existing test, lint, or typecheck commands
- a quick diff review for unrelated changes

If validation fails because of this run, stop and produce an investigation report.
Do not open a PR unless the configured mode explicitly asks for patch-only output instead.

Ignore pre-existing unrelated failures, but record them clearly when they affect confidence.

## Step 5 - Prepare review output

If nothing was safe to fix, do not open a PR. Report the reviewed candidates, why each was skipped, and a concrete follow-up plan.

If PR tooling is unavailable, prepare the branch name, commit message, PR title, PR body, and patch summary, then stop.

If PR tooling is available and validation is strong enough, create a branch using the repository's normal naming convention when it is obvious. Otherwise use:

```text
fix/new-relic-error-fixer-YYYY-MM-DD
```

Use a conventional commit message such as:

```text
fix: address mapped New Relic error
```

Open a draft PR and keep it draft.

## Guardrails

Stop without code edits when:

- the query is unbounded
- New Relic access is unavailable
- service, entity, or workload scope is missing or ambiguous
- the error has no clear mapping to the current repository
- the relevant frames are not in-app or not editable
- no validation commands are available
- the change would require auth, payments, migrations, destructive data flows, cross-repository edits, or a broad refactor
- the candidate is client misuse, tenant data corruption, external dependency failure, expected validation or auth behavior, or another non-product-bug class
- the working tree contains unrelated changes that would be overwritten or make the result unclear

Never:

- fix more than 1 root cause in a run
- ingest an unbounded raw log corpus
- close, ignore, comment on, assign, or otherwise mutate New Relic issue or error-group state
- merge, approve, or mark the PR ready for review
- overwrite unrelated user changes

## PR body

Use this structure:

```markdown
## Summary

## New Relic Evidence

## Root Cause

## Fix

## Validation

## Risk And Rollback

## Follow-up
```

## Investigation report

Use this structure when the run stays report-only:

```markdown
## New Relic Error Investigation

## Candidate Selected

## Evidence

## Why It Was Not Auto-Fixed

## Suggested Next Steps

## Slack-Ready Summary

## Candidate Ledger
| Candidate | Classification | Confidence | Why Skipped | Next Action |
|---|---|---|---|---|
```

## Output

Always produce:

```markdown
## New Relic Error Fixer

## Candidate Selected

## Fix Result Or Investigation

## Validation

## PR

## Skipped Candidates

## Remaining Risk
```

Include the New Relic error group identifier or permalink, selection reason, validation commands run, and any setup gaps that prevented a safer or more complete fix.
How It Works
  1. Queries New Relic for a bounded set of recent high-signal unexpected or resurfacing error groups.
  2. Requires a bounded service, entity, or workload scope, then ranks candidates and selects at most one error with clear mapping to the current repository, editable in-app code, and available validation commands.
  3. Verifies the root-cause hypothesis in the local codebase, implements the smallest safe fix, and adds a targeted regression test when feasible.
  4. Runs validation and opens a draft PR, or stops with a reviewable investigation report if the fix cannot be validated safely.
sequenceDiagram
    participant Agent
    participant NR as New Relic
    participant Repo
    participant PR as Git Provider

    Agent->>NR: Query bounded high-signal error groups
    NR-->>Agent: Error details, traces, logs, links
    Agent->>Repo: Verify mapped code evidence and implement minimal fix
    Agent->>Repo: Run targeted validation
    Agent->>PR: Open draft PR
    Note over Agent: No New Relic state changes, no merge, no ready-for-review
Prerequisites
  • New Relic access through MCP or the New Relic CLI
  • Repository access in the workspace where the fix will be made
  • Validation commands for the affected app, package, or service
  • GitHub or equivalent PR tooling if you want automatic draft PR creation

Use a least-privilege New Relic account or API key. The public MCP server is a preview feature and should not be used for FedRAMP- or HIPAA-regulated accounts.

Cursor Cloud Usage
  1. Open Cursor Automations.
  2. Name your automation and paste new-relic-error-fixer.md as the automation prompt.
  3. Add trigger conditions.
  4. Add the New Relic MCP server.
    • US accounts: https://mcp.newrelic.com/mcp/
    • EU accounts: https://mcp.eu.newrelic.com/mcp/
  5. Complete the OAuth flow if your Cursor setup supports it, or configure an API key header if your MCP client uses header-based auth.
  6. Add the Open Pull Request tool, or let the agent use an existing GitHub CLI or plugin in the environment.
  7. Make sure the runtime can execute the validation commands required for the mapped repository.
  8. Click Create.
Codex App Usage
  1. Install the New Relic MCP server in Codex.
    • OAuth:
codex mcp add new-relic-mcp-server --url "https://mcp.newrelic.com/mcp/"
  • EU accounts should replace the URL with https://mcp.eu.newrelic.com/mcp/.
  1. If you prefer API-key auth, configure it in ~/.codex/config.toml:
    [mcp_servers.new-relic]
    url = "https://mcp.newrelic.com/mcp/"
    env_http_headers = { "api-key" = "NEW_RELIC_API_KEY" }
  2. Run Codex and complete /mcp authentication if needed.
  3. Click Automation > New Automation.
  4. Name your automation and paste new-relic-error-fixer.md as the automation prompt.
  5. Set the schedule or run manually and save the automation.
  6. Add the GitHub plugin to Codex, or let Codex use an existing GitHub CLI or tool in the environment.
Claude Code Usage
  1. Add the New Relic MCP server in Claude Code.
    • OAuth:
claude mcp add newrelic --transport http https://mcp.newrelic.com/mcp/
  • API key:
claude mcp add newrelic https://mcp.newrelic.com/mcp/ --transport http --header "Api-Key: NRAK-YOUR-KEY-HERE"
  • EU accounts should replace the URL with https://mcp.eu.newrelic.com/mcp/.
  1. Run claude mcp list to confirm the server is configured.
  2. Open Claude Code and run /mcp to authenticate with New Relic in your browser when using OAuth.
  3. Make sure the runtime can work in the affected repository and run the required validation commands.
  4. For repeated checks in an open Claude Code session, use /loop, for example:
/loop weekdays at 11am Follow the instructions in automations/new-relic-error-fixer/new-relic-error-fixer.md
  1. For durable Claude-managed automation that survives outside the current session, use /schedule or create a Routine in claude.ai/code/routines.
  2. Make sure the runtime has repository write access and PR creation access if you want automatic draft PRs.
CLI Setup
brew install newrelic-cli
newrelic profile add

Use the CLI path when your runner can reliably execute bounded NRQL or NerdGraph queries and MCP is unavailable or undesirable.

Prompt Inputs

Add context only when New Relic state alone is not enough, for example:

New Relic workload: checkout-production
Entities: checkout-api
Environment: production
Exclude expected 4xx validation errors, expected auth failures, and rate-limit behavior.
Do not touch auth, billing, migrations, data backfills, or infrastructure code.
Docs