Latest Findings · ASI Lab

R2Code: Teaching an AI to See Which Code Implements Which Requirement, With 7.4 Percent Better Links and 41.7 Percent Fewer Tokens

Every software feature starts as a written requirement and ends as lines of code, but the invisible thread between them is usually lost. R2Code is an AI framework that rebuilds that thread by reading a requirement, breaking it into intent, actions, conditions, and outputs, then finding the code that truly implements each part. Across five real world projects in healthcare, tourism, sensors, and public services, it found more correct links than strong keyword and AI baselines while using up to 41.7 percent fewer tokens, a major cost saving at scale.

Yifei Wang, Jacky W. Keung, Xiaoxue Ma, Zhenyu Mao, Kehui Chen, Yishu Li
Agentic Software Intelligence Research Lab · Department of Computer Science, City University of Hong Kong
COMPSAC · 2026

Every software feature starts as a written requirement and ends as lines of code, but the invisible thread between them is usually lost. R2Code is an AI framework that rebuilds that thread by reading a requirement, breaking it into intent, actions, conditions, and outputs, then finding the code that truly implements each part. Across five real world projects in healthcare, tourism, sensors, and public services, it found more correct links than strong keyword and AI baselines while using up to 41.7 percent fewer tokens, a major cost saving at scale.

![R2Code traceability workflow diagram showing evidence construction with dynamic context adaptive retrieval, semantic matching with hierarchical semantic decomposition and bidirectional alignment, self reflective consistency verification, and ranked trace links as output](/news/img/r2code.JPG)
Fig. 1: R2Code traceability workflow. A requirement and candidate code units enter evidence construction, where cached code summaries, a complexity based retrieval budget, and semantic overlap filtering produce a compact evidence set. Structured semantic matching then aligns the requirement and evidence through HSD and BAN, and the self reflective consistency verification step calibrates confidence before ranked trace links with explanations are returned.

Why it matters

Software teams live with a quiet maintenance tax: when a requirement changes, nobody is quite sure which parts of the code must change with it. Traceability links spell out that mapping, and they power change impact analysis, code comprehension, and safer refactoring. Yet in real evolving repositories these links are frequently missing, outdated, or inconsistent, and keeping them current is a slow manual job that can consume a substantial share of development effort.

Classic tools tried to rebuild these links by matching words. That works for obvious phrasing but fails whenever a requirement is written as a business goal and the code is written as control flow, loops, and return values. R2Code treats this as a reasoning problem instead: it decomposes both sides into matching semantic layers, aligns them in two directions, and then uses the AI own explanation as evidence to check whether a link is genuine. The result is a traceability assistant that is more accurate, more portable across languages and domains, and cheaper to run, which is what practice actually needs.

Key findings

Three ideas that make traceable AI code links work

What it means for practitioners

If you are modernising a legacy system or preparing for an audit that demands traceability, R2Code offers a practical path: it recovers requirement to code links automatically, returns an explanation for each link, and does so at a cost per correct link roughly 37 percent lower than a standard retrieval augmented generation pipeline. The explanation output matters for human review, because reviewers can accept or reject a link with visible reasons rather than trusting a bare score.

The cross language result is the strongest signal for adoption. A single fixed configuration, with no dataset specific tuning, improved results on every project including a C# codebase and four Java codebases from entirely different domains. That suggests the decomposition based approach travels well, which is exactly what teams facing mixed technology stacks need.

Related reading

Get the paper & cite it

Download full PDF ↓ View at DOI

Official citation: Yifei Wang, Jacky W. Keung, Xiaoxue Ma, Zhenyu Mao, Kehui Chen, Yishu Li (2026). R2Code: A Self-Reflective LLM Framework for Requirements-to-Code Traceability.. COMPSAC. DOI: 10.1109/COMPSAC69091.2026.00057.

requirements traceability LLM software maintenance self reflection code comprehension