Building a Zero-Trust AI Code Review Agent with GitLab, LangGraph, and Qwen3-Coder
From the publisher’s feed, collected in the ZeroLabs newsroom.
Image by Author via AIA fully local AI reviewer for teams that can never send code to the cloudTL;DR — Most AI code review tools require uploading proprietary code to the cloud. That isn’t acceptable in many enterprise environments — automotive, embedded, fintech. In this article we build a fully local AI code review pipeline using GitLab CI/CD, LangGraph, Ollama, and Qwen3-Coder-30B. Every review happens inside the corporate network. Developers get native GitLab inline suggestions, and no code ever leaves the building. Full source is linked at the end so you can reproduce it yourself.Figure 1 — End-to-end flow. Everything inside the dashed red boundary stays on the private LAN; nothing crosses it. (Diagram by the author.)1. Why “just use the cloud” isn’t an optionIn the automotive industry — especially smart-cockpit and autonomous-driving software — source code is one of the company’s most closely guarded assets. Cloud LLMs can be genuinely excellent reviewers. But security teams will still refuse to send unreleased, proprietary code to a third-party API, no matter how good the model is.This isn’t unique to automotive. Any organization under strict IP, export-control, or regulatory rules faces the same wall. The practical fix isn’t asking legal for an exception — it’s bringing the LLM inside the perimeter.Stack: GitLab CI/CD + GitLab Runner for orchestration, Ollama for local LLM serving, Qwen3-Coder-30B as the reviewer, and LangGraph to turn a single LLM call into a self-correcting review loop.Hardware: two machines on the same LAN — a GitLab server, and an Ubuntu AI server with a single RTX 3090.2. Standing up the local modelcurl -fsSL https://ollama.com/install.sh | shollama pull qwen3-coder:30bWe wrap the model in a custom Modelfile to control context length and generation length precisely:FROM qwen3-coder:30bPARAMETER num_ctx 65536PARAMETER num_predict 8192Why 30B? It’s the sweet spot on a single 24GB-class GPU. Larger models need multi-GPU setups; smaller ones missed too many bugs and were less reliable at following our strict JSON output format.Why a 64K context window? Code review is context-hungry. A single request can carry a diff hundreds of lines long, plus supporting context. Ollama’s default window (4K–8K) truncates that. A model that can’t see the full diff either misses real bugs or hallucinates line numbers for code it never actually saw. num_predict = 8192 gives it enough room to finish a full JSON array of findings without cutting the output off mid-object.Inference speed and timeouts. On the RTX 3090, we consistently measured 100–110 tokens/second. Since reviews run asynchronously inside CI rather than in a chat window, we don’t need real-time streaming — so we set a generous 360-second timeout to prioritize robustness over latency. In practice, a typical diff completes the whole round trip in under 10 seconds; the timeout is a safety margin, not something we routinely hit.3. GitLab Runner: the part nobody warns you aboutInstalling GitLab Runner is easy:# Download the official GitLab Runner binarysudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64# Give it execution permissionssudo chmod +x /usr/local/bin/gitlab-runner# Create a GitLab Runner user and install as a servicesudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bashsudo gitlab-runner install --user=gitlab-runner --working-directory=/home/"Your User"/gitlab-runnersudo gitlab-runner start# Once the service is live, link it toinstance by registering itsudo gitlab-runner register# URL: your GitLab instance# Token: the project's Runner registration token# Executor: shellWe use the shell executor, not Docker — the review script calls directly into a Conda-managed Python interpreter and needs low-latency access to localhost:11434 (Ollama). A container layer would only add friction here.Getting this stable on a private, non-Docker AI server was the hardest part of the whole project. We hit two issues that looked like completely unrelated infrastructure bugs: a stale external_url that sent every job to the wrong IP, and a su - shell-profile crash that killed jobs before our script even ran (prepare environment: exit status 1). Both are fixable with a few lines of config — full details, with exact fixes, are in the repo TROUBLESHOOTING, since they're specific enough that most readers won't need to read them inline.4. The review agent: a self-correcting LangGraph loopA single LLM call isn’t reliable enough for a production gate. Open-weight models, unlike hosted frontier APIs, don’t reliably enforce structured output — they occasionally wrap JSON in prose, forget a bracket, or add a stray comma. So instead of trusting one shot, we built a small 3-node LangGraph workflow that automatically validates the model’s JSON output and retries failed generations, up to three times, feeding the previous error back into the prompt so the model can self-correct:[START] → analyze_and_retrieve → execute_review ⇄ node_validate_format → [END] ↑___________________| (retry on bad JSON, max 3×)The system prompt enforces three review categories — naming conventions, formatting/magic numbers, and syntax/security issues (mutable default arguments, bare except, eval()/exec(), SQL injection, unclosed resources) — and a strict JSON schema. It also tells the model to wrap fixes in GitLab's own suggestion-block syntax:```suggestion```That single convention enables GitLab’s built-in “Apply suggestion” button, turning plain text into a one-click code fix — no custom UI required.5. Talking back to GitLabOnce the agent has a validated list of findings, ci/ai_agent_review.py calls the GitLab REST API v4 to fetch the MR's diffs, then posts each finding as an inline discussion anchored to the exact line (using base_sha / head_sha / old_path / new_path / new_line). If the exact-line anchor fails — line mapping mismatches do happen, especially around renamed files — the agent falls back to a top-level MR comment instead of silently dropping the finding.6. Wiring it into the pipelinestages: - reviewvariables: FF_DISABLE_AUTOMATIC_PROFILE_LOADING_ON_SHELL_EXECUTORS: "true" GITLAB_ACTUAL_URL: "http://:"ai_agent_review: stage: review tags: - ai-review only: - merge_requests script: - /home/ubuntu/miniconda3/envs/gitlab_ai/bin/python ci/ai_agent_review.pyonly: merge_requests keeps this off regular branch pipelines — it only runs when there's an MR to comment on.only: merge_requests keeps this off regular branch pipelines — it only runs when there's an MR to comment on. You'll also need three things set up on the GitLab web UI first: a runner tag under Settings → CI/CD → Runners, an AI_REVIEW_TOKEN under Settings → CI/CD → Variables, and the right Job token permissions so the pipeline can call the project's own API. Exact steps are in the repo README.7. Does it actually catch bugs? A live testTo validate the loop, we branched off main and added one file, src/utils/data_processor.py, containing four classic Python anti-patterns on purpose:def merge_records(new_items, result=[]): # ① mutable default argument for item in new_items: result.append(item) return resultdef wait_for_next_cycle(): time.sleep(86400) # ② magic numberdef safe_divide(a, b): try: return a / b except: # ③ bare except passdef ProcessData(D): # ④ PascalCase function name return [x * 2 for x in D]The pipeline completed the whole round trip in about 9 seconds and returned 4 validated findings on the first attempt — zero retries needed. All four defects were caught, each posted back as an MR comment with a working “Apply suggestion” button:Figure 2 — One of the four inline comments the agent posted on the test Merge Request(Diagram by the author.)8. Reproduce it yourselfThe GitLab CI pipeline, the LangGraph review agent, and the test file used above are all on GitHub, along with the full troubleshooting notes for the Runner issues in Section 3: → https://github.com/CobenGao/local-llm-code-review-agentTools usedOllama — local LLM servingQwen3-Coder — the reviewing modelLangGraph — state-machine orchestrationGitLab CI/CD, Runner, and REST API v4All screenshots and logs in this article are the author’s own, captured from a private lab GitLab instance. IP addresses and project identifiers have been genericized before publication.Building a Zero-Trust AI Code Review Agent with GitLab, LangGraph, and Qwen3-Coder was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.