ai gemini agents code-review gitlab llm devops

My Code Reviewer Is a Gemini Agent With a GitLab Account

· 8 min read
On this page

When the same AI model writes code and reviews it, I expect the review to miss what the author missed. So I use Claude Code to write code and a Gemini agent to review it. The reviewer has its own GitLab account, and it comments on merge requests (MRs), blocks them and approves them like a person would.

In six weeks, Claude Code opened 792 MRs, and the median time to the reviewer’s first comment was four minutes. It found real security problems. It also reported approvals it never made, and it was sent the same prompt every two minutes for work that needed nothing from it. If you want to add an AI reviewer to your own repositories, this is what made mine work, how it failed and where the money went.

How the pipeline is set up

Every 30 minutes, before a Claude Code session starts, a script asks GitLab whether any issue is ready, and exits without calling the model if none is. Otherwise Claude Code claims an issue, builds it in its own git worktree, runs the tests and opens an MR. Later sessions read the review comments and push fixes.

Three agents then take the MR to develop, the branch that collects finished work until I merge it into main. They run in containers on Hermes Agent, an open-source agent runtime from Nous Research.

AgentJobModel in the six weeks I measured
ReviewerReviews the code, and approves or blocks itgemini-3.1-pro-preview
Product managerChecks the MR against the issue’s acceptance criteriagemini-3.1-pro-preview
Merge botMerges after the other two approveNone, it’s a script

Each agent has its own GitLab account, and they pass work to each other by @-mentioning the next one:

Claude Code opens MR  ->  reviewer approves, mentions the product manager
                      ->  product manager approves, mentions the merge bot
                      ->  merge bot merges into develop
                      ->  I merge develop into main

What the reviewer caught

The reviewer found a path traversal and commented on the exact line, five minutes after the MR was opened. Claude Code pushed a fix, and the reviewer checked it and approved. It has also found a race condition and missing validation. On one MR, the description said two bugs were fixed, and the reviewer blocked it because the code contained only one of the fixes.

In six weeks
MRs opened by Claude Code792, of which 693 merged
Median time to the reviewer’s first comment*4 minutes
Median time from opened to merged*38 minutes
Reviews that blocked or asked for changes**20%
MRs that needed a second review*25%

* From a sample of 150 merged MRs. ** From 182 review summaries.

I haven’t run a Claude reviewer on the same MRs, so I can’t measure how much the second model adds.

What made it work

1. A script picks the work

Every reviewer run starts with a shell script that asks GitLab for new review requests, @-mentions and unanswered replies. If there are none, the script exits and the model is never called. Otherwise it prints the list for the model to work through. This is the end of the script, simplified:

[ -z "$REQUESTS" ] && [ -z "$MENTIONS" ] && [ -z "$UNANSWERED" ] && exit 0   # silent

[ -n "$REQUESTS" ] && { echo "## New review requests"; echo "$REQUESTS"; }
[ -n "$MENTIONS" ] && { echo "## Someone is talking to you"; echo "$MENTIONS"; }

2. A script does the merging

GitLab Community Edition can’t require approvals, so a script checks that the reviewer and the product manager have both approved. It reads GitLab’s approval records and ignores what the agents write in comments. It never calls a model, so a prompt can’t talk it into a merge.

Community Edition also keeps old approvals when new code is pushed, so the script compares the time of each approval with the time of the latest commit. Simplified:

for uid in REQUIRED:                  # the reviewer and the product manager
    if uid not in approvers:
        missing.append(NAMES[uid])
    elif when.get(uid) and when[uid] < head_time:
        # Approved, then more code was pushed. Treat as unapproved.
        missing.append("%s (stale: approved before the current head)" % NAMES[uid])

In repositories with CI, the script also requires a passing pipeline on the latest commit. A skipped pipeline doesn’t count. When it merges, it tells GitLab which commit it checked, and GitLab refuses if the branch has changed since.

3. The reviewer can call only the tools I list

The reviewer reaches GitLab through a Model Context Protocol (MCP) server. At first I listed the tools it must not use. A new version of the server then added about 95 tools, and none of them were on my list. On its first run with that version, the reviewer edited an MR description and posted a thread that said test.

I now list the tools it may use and pin the server version. The container refuses to start if my list names a tool that the pinned version doesn’t have. I also removed the reviewer’s terminal, because it had used curl to call the GitLab API without going through the MCP server.

4. The agents get only the files they need

The containers once cloned my main working repository, so a model with a GitLab token could read files that had nothing to do with code review. They now clone a small repository that holds only the agents’ scripts, instructions and configuration.

What went wrong

The reviewer ran on low thinking for almost four weeks

Hermes translates its effort setting into Gemini’s thinking level, and for 3.x Pro it sends only low or high. My container used the default, medium, which Hermes sent as low.

In one run the reviewer’s reasoning said “the effort level is capped at 0.25. That means minimal effort”. It had ignored 13 requests. After I set the effort to high, the next run cleared 13 of the 16 pending requests with the same model and prompt. I later lowered it again to save money, and two days later it reported approvals it had not made. The reviewer’s effort is now set to high in its deployment.

An idle loop cost about $14 a day

The reviewer’s script listed every MR with a reply newer than the reviewer’s last comment. At one point, 17 of the 21 MRs on the list were there because another agent had posted a status note that needed no answer. The reviewer did nothing, the list never cleared, and the same 57K-token prompt was sent every two minutes. I estimated the cost from two measured runs.

The script now ignores status notes from other agents, and shows any one reply to the model at most once a day.

The reviewer reported approvals it never made

On one day, six runs reported that they had examined and approved MRs without making a single tool call. They had not read the code or recorded an approval.

These claims couldn’t merge anything, because the merge script reads GitLab’s approval records, but they could mislead a person who reads them. The reviewer’s instructions now say that it may write “Approved” only if the approval call succeeded in that run, and each run gets at most six MRs.

The agents approved code they should have blocked

The agents once approved about 22 MRs in eight minutes, and the reviewer’s comments said “automated check (no manual pass)”. Several of those MRs had between 43 and 71 failing tests. A separate review found serious problems in the batch, and the MRs went back to draft. The merge script’s rule about passing pipelines now stops an MR like that from merging.

The reviewer also approved an MR after blocking it, although the new push didn’t touch the bug it had found. That bug reached develop.

A broken job looked the same as an idle one

A job with nothing to do prints nothing and exits successfully. A job that couldn’t find its files did the same, so the reviewer worked for hours without the list of past defects it was meant to check. Jobs now fail with an error when their configuration is wrong.

What it cost

Most of the cost came from the number of reviews. A run took about 20 calls, and each call sent more than 50,000 tokens, mostly tool definitions and instructions, before the reviewer looked at any code. On 3.1 Pro that came to about $0.76 per run.

Gemini’s automatic caching kept this from being much higher. The start of the prompt is almost the same in every run, and cached input on 3.1 Pro costs a tenth of the normal price. In two runs I compared, 52,665 of the second run’s 56,880 input tokens came from the cache. Without caching, the idle loop would have cost about $82 a day.

To reduce the cost, the reviewer now loads only the tools it uses and runs every 10 minutes, so each run handles more work. It also tries GLM-5.3 on a flat-rate plan first, and uses Gemini 3.8 Flash when that plan’s quota runs out. I never compared either model with 3.1 Pro on the same MRs, so I don’t know whether they review as well.

If you want to try this

  • Review with a different model from the one that writes the code, and record what it catches.
  • Use a script to choose the work and to decide what merges, and leave judgement to the model.
  • Check the thinking level that reaches the API, because your framework may change it.
  • List the tools the agent may use, pin the MCP server version, and don’t give the agent a terminal.
  • Check approvals in GitLab’s records, because the agent’s own account can be wrong.
  • Send less on each call, because every call sends the whole prompt again.