Developer Guide

Improving Complexity Analysis with Radon

Get precise cyclomatic complexity scores in your merge requests by enabling tool-based analysis.

How it works

When GitLab Duo runs static complexity analysis on your merge request, it measures cyclomatic complexity for every function you touched or added. This helps catch overly complex code before it gets merged.

Fallback
LLM-approximated
The AI reads your code and counts decision points manually

If you saw an info box in the MR comment about improving accuracy, read on.

If a merge request was linked

The analysis agent detected that your project can support radon but doesn't have it installed yet. It created a merge request that adds (or updates) your .gitlab/duo/agent-config.yml file to include pip install radon in the setup step.

Review and merge that MR. Radon will be used for precise scores on the next run.

The MR adds a configuration like this:

version: 1
base_image: python:3.12-slim
setup:
  - pip install radon

If your project already had an agent-config.yml, the MR modifies it to add radon to the existing setup steps.

If no merge request was linked

The analysis agent found an existing .gitlab/duo/agent-config.yml in your repository but could not safely modify it. This typically happens when:

Add radon to your config manually. See base-image-specific instructions below.

Python base image

If your base_image is any Python variant (python:*, debian:*, ubuntu:*), add to your setup:

setup:
  - pip install radon    # Add this line
  - # ... your existing setup steps

Node.js base image

If your base image is Node-based, you'll need Python available:

setup:
  - apt-get update && apt-get install -y python3 python3-pip
  - pip3 install radon
  - # ... your existing setup steps

Other base images

For Alpine, Ruby, Go, or other images, ensure Python 3 and pip are available, then pip install radon.

What is .gitlab/duo/agent-config.yml?

This file configures the execution environment for GitLab Duo agent workflows. It specifies:

When this file exists and includes radon, the complexity analysis agent can call radon cc directly on your source files for exact cyclomatic complexity scores. Without it, the agent falls back to LLM-based estimation, which is less precise.

What is cyclomatic complexity?

Cyclomatic complexity (CC) measures the number of independent paths through a function. It counts decision points like if, for, while, case, catch, &&, ||, and ternary operators.

CC ScoreRankRisk Level
1–5ASimple, low risk
6–10BModerate, well-structured
11–15CMore complex, consider refactoring
16–20DComplex, should refactor
21–25EVery complex, high risk
26+FUntestable, must refactor

Functions with CC above 10 are harder to test and more likely to contain bugs. The analysis highlights these so you can address them during code review.