Matchers

A matcher recognises one tool's failure output and keeps the lines around it. ci-doctor ships none: every run loads the ones your config selects from the registries it declares.

Matcher, output, variant

A matcher file describes one tool, wrapper or environment issue. Inside it, each level has one job:

LevelIsThe model seesExample
MatcherOne tool, wrapper or issuenothing of its own when it has several outputsruff, disk_full
OutputOne distinct output: one meaning, one descriptionruff.check [tool]: …ruff.check, ruff.format
VariantOne spelling of that output, such as an older version's formatnothing: it shares the output's descriptionruff.check (full)

A different meaning is a new output; the same meaning spelled differently is a variant. Every variant runs on every log, so whichever spelling the log holds picks itself: there is no tool version to declare. Most matchers have one output and write it at the top level:

schema: 1
id: disk_full
role: issue
description: >-
  The runner ran out of disk - No space left on device / ENOSPC. The step
  that hit it is a victim of the runner, not the cause.
tags: [infra, disk]
match:
  any:
    - template: 'No space left on device'
    - template: 'ENOSPC'
window: { before: 3, after: 3 }

A tool with several outputs lists them, and gives a spelling its own window only when it needs one:

schema: 1
id: ruff
description: Ruff, the Python linter and formatter - lint violations and files ruff format would change.
tags: [python, lint, format]
define:
  FILE: '[\w./-]+\.pyi?'
  NUM: '\d+'
  RULE: '[A-Z]+[0-9]+'
outputs:
  check:
    description: ruff check lint violations, each naming a rule code and the file:line it fired on.
    variants:
      concise:                       # older default: one line per violation
        match: { template: '$FILE:$NUM:$NUM: $RULE ' }
      full:                          # newer default: the code, then the location
        match:
          all:
            - regex: '^%{RULE} '
            - followed_by: { template: '--> $FILE:$NUM:$NUM', within: 2 }
        window: { after: 8 }
  format:
    role: gate
    description: ruff format --check listing the files it would reformat. Running ruff format fixes it.
    match: { regex: '^Would reformat: ' }

Finding and keeping

match finds the anchor lines. A leaf is a regex (RE2), or a template written as the line looks in the log: everything is literal except $NAME, which inserts the matcher's own define, and ..., which matches anything. all, any and not combine leaves on one line; inside, preceded_by and followed_by relate a line to the lines around it.

window says which lines become evidence: before and after, or from a header above, until a closing line, while the next line continues, each capped by max_lines. Every field is on Matcher format v1.

Everything compiles to the one RE2 pass per line ci-doctor has always run, plus a linear pass over the hits: a hundred matchers cost one scan of the log, and no pattern can hang a job.

Roles

role decides which windows survive when the evidence is over budget, and tells the model how to read them. Higher ranks survive:

RoleMeansRank
issueThe environment failed: a full disk, out of memory, the network. Matched only on standard strings.4
toolThe failing tool printing the cause: tsc, pytest, a traceback. The default.3
gateA deliberate check failing the job on purpose: coverage, a scanner, a formatter.2
wrapperAn orchestrator reporting that something it ran failed: npm, make, gradle.1
fallbackThe generic catch-all.0

An issue outranks the tool it broke: shed the full disk and the model blames the compile error it caused; shed the compile error and the cause is still in front of it. A gate ranks below the tool because a failing test fails coverage too. A wrapper prints after the tool it ran, so it must lose to it wherever it sits. Within a role, the later window wins. The section's last lines are always kept as well, ranked below every matcher.

Bundles

A bundle is a named list of matchers and other bundles from the same registry. A registry generates one per ecosystem folder: official/python is every matcher under matchers/python/. Curated bundles, such as all, are written by hand. Bundles nest at most five deep, a cycle is an error, and a matcher reached twice loads once. ci-doctor matchers list shows which entry brought each matcher in.

Registries and refs

A registry is a folder with an index.yaml listing every matcher and bundle it serves. Your config names registries under matchers.registries, alias → location, and selects from them under matchers.include, each entry an alias/name ref to a matcher or a bundle. Including a matcher includes all its outputs; matchers.exclude drops one by its dotted id. One registry is declared for you: official, at https://matchers.cidoc.dev/. Nothing is included for you.

matchers:
  registries:                       # official is already declared; add your own
    acme: ./ci/matchers             # relative to this file
  include:
    - official/python               # a bundle: every matcher under matchers/python/
    - official/ruff                 # a matcher, with all its outputs
    - acme/mytool
  exclude:
    - official/ruff.format          # drop one output

Before analysis starts, each run reads every registry an include names, expands the bundles, and fetches, validates and compiles each selected matcher. Every read is bounded: an index of at most 1 MiB and 2,000 entries, a file of at most 64 KiB, paths that cannot leave the registry, a redirect that cannot drop from https to http, and every matcher and bundle must match the sha256 its index lists. Anything wrong, including an empty include, an unknown alias or name, an exclude that names no output, a file that doesn't match its hash, or an unreachable registry with nothing cached, is a broken setup: the job exits 1, naming the registry and the cause. ci-doctor config --validate runs the same steps as a dry run.

Schema versions

Every matcher file says which format it is written in (schema: 1). Every ci-doctor compiles every schema version it knows, and a released version never changes how it compiles. A matcher in a newer version than your ci-doctor knows is skipped with a warning when a bundle brings it in, and fails the setup when you included it by name.

The cache

Files from an http(s):// registry are kept in a local cache, stored by the sha256 their index lists. A run revalidates each index with a conditional request (none at all while the server's max-age holds; GitHub Pages sends 10 minutes) and fetches only the files whose hash changed, so a warm run of official/all makes one request instead of over a hundred. A cached file is used only while its bytes still match its hash. Local registries aren't cached.

If a registry can't be reached (a connection error, a timeout, a 5xx) and its index is cached, the run warns with the index's age and uses the cache; a file the cache doesn't have still fails the setup. The cache lives in the OS cache directory (~/.cache/ci-doctor on Linux); matchers.cache_dir moves it and matchers.cache: false turns it off. On a CI runner it lasts as long as your pipeline keeps it: see GitHub Actions and GitLab CI.

Pinning, and running with no network

There is no lock file: every run uses each registry's index as it is now. That keeps a fix to a matcher one push away from every pipeline, and it means a registry change reaches your next run unreviewed. To hold a registry still, point at a URL that contains a fixed revision.

matchers:
  registries:
    acme: https://raw.githubusercontent.com/acme/matchers/v1.4.0/   # a tag or a commit SHA

Registries are the one network dependency besides your CI provider and your LLM. On an air-gapped network, copy the registry inside it with ci-doctor registry mirror official DIR on a machine that can reach both, and point the alias at that path or serve it; see Hosting a registry. The Docker image ships with the official registry already in its cache, so a run starts warm.

Finding, trying and writing matchers

The official catalogue, with each matcher's fixtures beside what it selects from them, is at matchers.cidoc.dev. From the terminal, ci-doctor matchers search and ci-doctor matchers info read the same indexes. To see what a matcher selects from your own log, with the real engine:

ci-doctor matchers examine matchers/python/ruff/matcher.yaml ./job.github.log
ci-doctor matchers examine official/ruff ./job.log --framing gitlab

It marks each anchor and names the variant that fired. Writing and testing matchers in a registry of your own is on Hosting a registry; contributing to the official one is in the ci-doctor/matchers repository.