Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

ci-doctor

Root-cause analysis for CI/CD.
A postmortem step that runs when a pipeline fails, works out where and why it broke, and emits a structured report — without ever touching your code.

Python 3.11+ Providers: GitLab | GitHub Read-only, exit 0 after setup LLM: bring your own (optional)


When a pipeline fails, the logs are long and loud. An LLM handed the whole trace will confidently blame the runner or a missing cache — because that text is alarming — even when the real failure was an exit code 1 three sections down. ci-doctor fixes that with one rule:

Deterministic code decides where the job failed. The LLM only explains why.

Phase attribution is a pure function of job metadata and log structure, computed before any model is called. A loud, non-fatal WARNING: can never outrank the actual failure. If the classifier is wrong, that's a bug with a failing test — not a prompt to tune.

Features

  • Deterministic phase attribution — a pure, fully-tested classifier decides where a job broke (provision · prepare · fetch · script · post) from metadata and log structure. Non-fatal WARNING: lines can never be blamed.
  • Read-only and safe — never edits code, commits, or opens MRs, and exits 0 once analysis starts, so it can't change your pipeline's status or hide the real failure. Only a broken setup (bad config, no matchers selected, an unreachable registry) exits 1.
  • Useful with no LLM — ships a deterministic report out of the box: phase, reason, terminal command, evidence excerpt, and templated remediation.
  • Bring-your-own model — optional LLM step via openai (any OpenAI-compatible endpoint, self-hosted or hosted), anthropic, azure, bedrock, google, groq, mistral, cohere and xai, all through Pydantic AI's own providers, selected by config.
  • GitLab & GitHub — one provider-neutral core; the GitHub adapter was added with zero changes to core.
  • Air-gap friendly — no telemetry, no update checks; ship as a self-contained Docker image or an offline wheel bundle, with the matcher registry cloned to a local path.
  • Secret redaction — scrubs secrets from the prompt and the report (round-trip tested).
  • Structured output — a rich terminal report, report.md + report.json artifacts (with a self-contained handoff_prompt you can paste into a coding agent), and one idempotent MR/PR note.

How it works

acquire → segment → attribute → denoise → extract → budget → (LLM) → render / deliver
          └── deterministic: decides WHERE it failed ──┘        └── explains WHY ──┘
  1. Acquire the failed jobs and their logs (a missing log is valid data — the "never got a runner" case).
  2. Segment the trace into sections (GitLab section_* markers / GitHub ##[group]).
  3. Attribute the failure to a phase — the pure classifier, first-match-wins precedence ladder with a WARNING:-is-never-fatal rule.
  4. Denoise / extract / budget the blamed section into a small, high-signal evidence slice (ANSI/CR/dedup denoising, anchored windows, token budgeting — every truncation is visible). Matchers come from registries, selected with matchers.include: browse the official one at https://matchers.cidoc.dev, and add your own under matchers.registries.
  5. LLM (optional) explains the cause within the already-decided phase, returning a validated JSON report. Disabled or unreachable → deterministic report instead.
  6. Render / deliver to the terminal, report.md/report.json, and an idempotent MR/PR note.

Install

On PyPI the distribution is ci-doctorr (the ci-doctor name was taken); the import package is ci_doctor and the command stays ci-doctor.

git clone https://github.com/ci-doctor/ci-doctor
cd ci-doctor
uv sync                       # or: pip install .

# pick the LLM backend extra for your provider:
uv sync --extra openai        # or: pip install '.[openai]'      — Ollama/vLLM/OpenAI-compatible
uv sync --extra anthropic     # or: pip install '.[anthropic]'   — Anthropic direct
uv sync --extra bedrock       # or: pip install '.[bedrock]'     — Amazon Bedrock, AWS IAM auth
uv sync --extra google        # or: pip install '.[google]'      — Gemini / Vertex AI (also: groq, mistral, cohere, xai)

Or build the self-contained image. It has no LLM SDK; bake some in with --build-arg EXTRAS=openai,anthropic, or add one in the job with pip install "ci-doctorr[openai]" (pinned to the lock):

docker build -t ci-doctor .

Quickstart

# Select matchers once (writes your user config; with none selected a run exits 1):
uv run ci-doctor matchers add official/python

# Replay a captured log — no CI, no token, no LLM: the log's own framing says
# which CI produced it.
uv run ci-doctor analyze failing-job.log

# Against a live pipeline (reads $CI_PIPELINE_ID etc. inside CI):
uv run ci-doctor analyze "$CI_PIPELINE_ID"

# From your laptop, in a clone — the repo is taken from `git remote origin`
# (with a warning) when GITHUB_REPOSITORY / CI_PROJECT_ID isn't set:
uv run ci-doctor analyze 18234567890

ci-doctor config prints the effective config; --diff shows only what your layers changed, --schema emits the JSON Schema. Full CLI and config reference on the documentation site.

When a pipeline has several failed jobs, the report is framed as a pipeline: a header with a code-vs-infra triage count, then each job under its own separator, in the order they ran.

Use it from a coding agent (MCP)

ci-doctor mcp is an MCP server on stdio, in the base install. Your agent is the model: ci-doctor hands it each failed job's phase and evidence and the agent explains the failure, so no llm: block is needed. Connect your agents from the repository's root:

ci-doctor agent install                    # asks which agents and where (from a script: the ones found here)
ci-doctor agent install --target auto      # the agents found here, no questions
ci-doctor agent install --location global  # in your own config, for every project
ci-doctor agent install --dry-run          # show the files and config, write nothing
ci-doctor agent uninstall                  # remove ci-doctor's entries (asks first in a terminal)

It supports Claude Code, Cursor, Codex CLI, opencode, Hermes Agent, Gemini CLI, Antigravity, Kiro and pi (--target claude,cursor picks; pi also needs its pi-mcp-adapter extension). For each it writes the MCP server entry and a short instructions block (CLAUDE.md, AGENTS.md, ...), and for Claude Code it auto-allows the read-only tools. Running it again changes nothing; a file it cannot edit safely is left alone and the config is printed to add by hand. To analyze live runs, set CI_DOCTOR_GITHUB_TOKEN or CI_DOCTOR_GITLAB_TOKEN where the agent runs. To set it up by hand, see examples/mcp.example.json.

Tool Does
list_runs Lists the project's runs, newest first, filtered by status, branch, commit, actor, event or date
analyze_run Briefs each failed job of a run for the agent to explain
search_matchers, list_matchers Browse the registries; show what the config selects
add_matchers, remove_matchers Edit matchers.include in ./.ci-doctor.yml (--write-to picks another file)
check_setup Validate the config and load every selected matcher

Ask the agent to "pick ci-doctor matchers for this project": it reads the repository, searches the registries and adds what fits. Only the two edit tools write anything, and only the matchers: block; the CI system and the repository are never touched.

Configuration

Layered and pydantic-validated — defaults.yml < your user config < repo .ci-doctor.yml < CI_DOCTOR_* env < CLI flags, with nested env vars using __ (CI_DOCTOR_LLM__MODEL=…). Unknown keys are an error. Minimal config:

ci: github                            # default; `gitlab` for GitLab CI

github:
  base_url: https://api.github.com    # default; override for GitHub Enterprise
  token_env: CI_DOCTOR_GITHUB_TOKEN   # or github.token_file for a secret mount

llm:
  enabled: true                       # false => deterministic-only report
  backend: openai                     # openai | anthropic | azure | bedrock | google | groq | mistral | ...
  model: qwen2.5-coder:32b
  api_base: http://openai-compatible-endpoint.internal:8000/v1

analysis:
  max_parallel_jobs: 4                # jobs analyzed at once; 1 to serialize

Every knob, and the LLM backends, are documented on the configuration page. The LLM step is optional throughout — disabled, unconfigured or unreachable, ci-doctor emits the deterministic report instead of failing.

Use it in CI

GitHub Actions — one step; run-id defaults to the run that just failed:

permissions: { actions: read, contents: read, pull-requests: write }
steps:
  - id: doctor
    uses: ci-doctor/ci-doctor@master   # or pin a release tag
    with:
      post-pr-note: 'true'
  - if: steps.doctor.outputs.is-infra-not-code == 'true'
    run: echo "::notice::Infrastructure, not the change."

Outputs phase, category, confidence, is-infra-not-code, and the two report paths, so a workflow can branch on the verdict. Inputs, PR comments and GitHub Enterprise are on the action page; the full workflow is in examples/github-actions.example.yml.

Listing on GitHub Marketplace is a one-time manual step and cannot be scripted: draft or edit a release in the GitHub UI, tick Publish this Action to the GitHub Marketplace, and accept the terms. action.yml already carries the metadata that requires. None of this affects uses: — that resolves straight from the repo either way.

GitLab (.gitlab-ci.yml) — runs only on failure, exits 0 once analysis starts:

ci-doctor:
  stage: .post
  image: registry.internal.example.com/ci-doctor:latest
  rules:
    - when: on_failure
  allow_failure: true
  variables:
    CI_DOCTOR_CI: "gitlab"          # the default is github
    CI_DOCTOR_GITLAB_TOKEN: "$CI_DOCTOR_TOKEN"
  script:
    - ci-doctor analyze "$CI_PIPELINE_ID"
  artifacts:
    when: always
    paths: [report.md, report.json]

Both providers have a complete, commented workflow in examples/.

Air-gapped / offline

ci-doctor makes no network calls except to the GitLab/GitHub and LLM endpoints you configure and the matcher registries you declare — no telemetry, no update checks, no model or schema downloads. Registries are read on every run, with no cache: clone one inside the network and point matchers.registries at the local path. Build once where there is internet, then ship inside:

docker build -t ci-doctor .                              # a self-contained image
pip wheel . -w ./wheels                                  # ...or a wheel bundle
pip install --no-index --find-links ./wheels ci-doctorr  # on the air-gapped host

Custom CA bundles (gitlab.ca_bundle, github.ca_bundle, llm.ca_bundle) and the standard HTTPS_PROXY / NO_PROXY / REQUESTS_CA_BUNDLE variables are honoured.

Documentation

docs.cidoc.dev — overview, requirements, configuration, usage, the GitHub Action, and CI/CD examples. Source in docs/site/ (Astro); mise run docs previews it locally.

Start with Concepts — the pipeline end to end, what each module decides, and what a phase, a matcher or a redaction pass actually is. Matchers explains matchers, bundles and registries; the official catalogue is at https://matchers.cidoc.dev.

For contributors: how the code is built — where things go, the invariants, how to write tests — is GUIDELINES.md; how to get a change in — setup, commits, pre-push checks — is CONTRIBUTING.md.

Development

mise run setup       # uv sync + the repo's git hooks  (or just: uv sync)
mise run check       # everything CI runs: tests, lint, secret scan

The suite blocks real sockets and never calls an LLM, so it runs in seconds.

License

MIT © Elad Cohen

Metadata

Release files for ci-doctorr 0.0.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ci-doctorr 0.0.1b1
File Size Uploaded Provenance Actions
ci_doctorr-0.0.1b1.tar.gz 1.7 MB With provenance Details for ci_doctorr-0.0.1b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ci-doctorr 0.0.1b1
File Interpreter ABI Platform Actions
ci_doctorr-0.0.1b1-py3-none-any.whl Python 3 none any Details for ci_doctorr-0.0.1b1-py3-none-any.whl

Total release size: 1.9 MB

Release files / ci_doctorr-0.0.1b1.tar.gz

Download URL ci_doctorr-0.0.1b1.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
6b4376b9d1a15f8b06133642a24a8f115a6454902fe1a4d05ba9437f4ad6fc97
BLAKE2b-256 checksum
How to use checksums
414d032fa2a6010d04cc4371e178a9b7d839a8bf2a6002ba86bf59128c3116fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / ci_doctorr-0.0.1b1-py3-none-any.whl

Download URL ci_doctorr-0.0.1b1-py3-none-any.whl
Size 246.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c269d7fd12f6192c13e1785ef0d3de9d04a37061be0e2cd01e3c04cf25aefcb3
BLAKE2b-256 checksum
How to use checksums
bcc42fb47901476872aaa915644353befb0fc3c1524d791f4add5e132c54e6eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for ci-doctorr 0.0.1b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ci_doctorr-0.0.1b1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page