> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gitar.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CI Failure Analysis

> Automatic analysis and fixes for CI failures on your pull requests

export const ThemeImage = ({src, alt}) => {
  let lightSrc, darkSrc;
  if (src.includes("-light.")) {
    lightSrc = src;
    darkSrc = src.replace("-light.", "-dark.");
  } else if (src.includes("-dark.")) {
    darkSrc = src;
    lightSrc = src.replace("-dark.", "-light.");
  } else {
    lightSrc = src;
    darkSrc = src;
  }
  return <span>
      <img className="block dark:hidden rounded-lg border" src={lightSrc} alt={alt} />
      <img className="hidden dark:block rounded-lg border" src={darkSrc} alt={alt} />
    </span>;
};

## Overview

Gitar monitors your CI pipelines and automatically analyzes failures on every PR. It identifies root causes, posts detailed breakdowns, and can push fixes.

<CardGroup cols={2}>
  <Card title="Root Cause Analysis" icon="magnifying-glass">
    Instant breakdown of why CI failed, posted as a comment on your PR
  </Card>

  <Card title="Automated Fixes" icon="wrench">
    Gitar pushes code changes that resolve CI failures
  </Card>

  <Card title="Multi-Iteration" icon="rotate">
    If a fix introduces a new failure, Gitar re-analyzes and attempts another fix automatically
  </Card>

  <Card title="CI Retry" icon="rotate-right">
    Automatically retry CI jobs with failures unrelated to your PR
  </Card>
</CardGroup>

## CI Failure Analysis

When CI fails on a PR, Gitar automatically:

<Steps>
  <Step title="Analyze the failure">
    Gitar reads the CI logs, identifies the failing step, and determines the root cause of the failure.
  </Step>

  <Step title="Post an analysis comment">
    A detailed explanation of the failure is posted to the dashboard comment on your PR, including which files and lines are involved.
  </Step>

  <Step title="Suggest or apply a fix">
    Depending on your auto-apply setting, Gitar either waits for your approval or pushes a fix commit directly to the branch.
  </Step>
</Steps>

The analysis appears in the [Gitar dashboard comment](/gitar-dashboard) on your PR.

The analysis covers your full CI pipeline output, so Gitar can diagnose failures across multiple jobs and steps in a single run. Identical failures across multiple jobs are deduplicated so they only get analyzed once. CI events for outdated commits are ignored after you push new code.

| Failure Type       | Examples                                                           |
| ------------------ | ------------------------------------------------------------------ |
| **Build errors**   | Compilation failures, missing imports, type errors                 |
| **Test failures**  | Broken assertions, missing setup, incorrect expected values        |
| **Linting errors** | Code style violations, formatting issues, static analysis warnings |
| **Flaky tests**    | Race conditions, timing issues, non-deterministic behavior         |

## Applying Fixes

After Gitar posts its analysis, you have three options:

| Option                     | How                                                                                                               |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| **Let Gitar auto-fix**     | Enable auto-apply on the PR with `gitar auto-apply:on`. Gitar pushes a fix commit to your branch.                 |
| **Fix it yourself**        | Use the root cause analysis as context and push your own fix. Gitar updates its analysis when new commits arrive. |
| **Request a targeted fix** | Comment `Gitar <specific instruction>` on the PR to tell Gitar exactly how you want the issue resolved.           |

Auto-apply can be toggled at any time with `gitar auto-apply:on` / `gitar auto-apply:off`. See [Commands & Interactions](/commands) for all available commands.

## CI Retry for Unrelated Failures

Gitar can automatically retry CI jobs whose failures are not related to the changes in your PR — for example, flaky tests, transient infrastructure hiccups, or failures caused by the target branch. When any failure in a pipeline is classified as unrelated to the PR, those jobs are rerun without any manual action. CI retry has its own toggle in organization settings, independent from auto-apply.

## Multi-Iteration Fixing

CI failures may not be resolved in a single pass. Gitar supports multi-iteration fixing:

1. Gitar pushes a fix for the original CI failure.
2. CI re-runs on the updated branch.
3. If CI fails again (whether from the same issue or a newly introduced one), Gitar re-analyzes the new failure.
4. Gitar attempts another fix, taking into account the full history of previous attempts.

This loop continues automatically until CI passes or Gitar determines it cannot make further progress. Each iteration builds on the context of previous attempts, so Gitar avoids repeating the same fix.
