Abstract
Maintaining code quality in large-scale industrial environments is a significant challenge, often resulting in technical debt and developer fatigue. This paper presents the Code Quality Score (CQS), a multi-agent system powered by Llama 3.1-70B models designed to automate the detection of non-trivial maintainability issues. By employing a decoupled "collector-validator" architecture and Direct Preference Optimization (DPO) aligned with human developer feedback, the system achieves a precision of 78.2% and a 60% helpfulness rate in production at Meta. Our findings suggest that prioritizing precision over recall is essential for maintaining developer trust in automated review systems.
Introduction
In massive software ecosystems, traditional static analysis tools—such as linters and security scanners—are effective at identifying syntax errors and known vulnerabilities. However, they frequently fail to capture "soft" quality attributes like modularity, readability, and adherence to architectural best practices. These nuances are typically addressed during manual peer reviews, which create a significant bottleneck as codebases scale.
Meta researchers developed the CQS system to bridge this gap. The goal was to create an automated "critic" capable of providing actionable, high-level feedback on code changes (diffs), thereby reducing the manual burden on senior engineers and accelerating the development lifecycle.
System Architecture
The CQS system utilizes a multi-agent workflow to ensure high-quality outputs. Rather than relying on a single model to both identify and evaluate issues, the architecture separates these concerns into two distinct stages:
- The Issue Collector: This agent scans code diffs to identify potential quality concerns, such as overly long functions, missing constants, or duplicated logic. It is a Llama 3.1-70B model fine-tuned via Supervised Fine-Tuning (SFT) on a dataset of high-quality human reviews.
- The Issue Validator: This agent acts as a critical filter. It receives the issues identified by the Collector and assigns a validity score (1–10). Only issues that meet a high threshold of validity and helpfulness are surfaced to the developer.
This separation of concerns is vital; the Collector focuses on creative discovery, while the Validator focuses on rigorous verification. This synergy allows the system to achieve a precision of approximately 78%, a dramatic improvement over the ~13% precision observed in single-agent baselines.
Training Methodology
The models were trained using a multi-stage pipeline designed to align the LLM's intuition with that of experienced human engineers.
Supervised Fine-Tuning (SFT)
The initial training phase utilized 6,000 curated diffs from Meta’s internal codebase across multiple languages (Python, C++, PHP). Each diff was paired with high-quality human comments to teach the model the expected format and style of a professional code review.
Direct Preference Optimization (DPO)
To refine the model's judgment, the team employed Direct Preference Optimization. They generated 8,400 preference pairs where a "winner" review was compared against a "loser." To scale this process, they developed a specialized LLM-as-a-Judge. Unlike generic frontier models, this judge was specifically fine-tuned on actual developer feedback—including "thumbs up/down" signals and written critiques—allowing it to better mimic the specific engineering culture and standards of the organization.
Results and User Experience
The CQS system has been deployed to over 5,000 engineers at Meta. The output is integrated directly into the code review UI, providing developers with clear rationales and categorized tags for each identified issue.
Performance Metrics
- Precision: The system achieved 78.2% precision, significantly outperforming raw frontier models like Claude 3.7 Sonnet (51.63%).
- Helpfulness: In production, the system maintains a 60% week-over-week helpfulness rate based on developer interactions.
- Trust-Centric Design: The system is intentionally tuned for high precision at the cost of recall (identifying only ~1.2% of all possible issues). In an industrial setting, a "quiet" tool that is always right is far more valuable than a "noisy" tool that frequently hallucinates.
Discussion and Future Work
While CQS represents a major step forward, limitations remain. The system occasionally struggles with deep language-specific semantics, such as misinterpreting complex memory management patterns in C++. Furthermore, the current low recall means many valid improvements are still missed.
Future iterations will focus on expanding the system’s scope to include complex security vulnerability detection and establishing a continuous "data flywheel." By automatically incorporating real-time developer feedback into the training loop, the system will continue to evolve alongside the codebase and changing engineering standards.
Summary updated