VITAL-RAG: Invariance Race for Context Allocation in Coding Agents Zijian Lu1 , Yonghua Lu2 , Mingcai Chen1 , Yiping Zuo1 , Xin He1 , Weijun Wang3 , Weibei Fan1 1
Nanjing University of Posts and Telecommunications, Nanjing, China 2 Tianjin University, Tianjin, China 3 Institute for AI Industry Research, Tsinghua University, Beijing, China [email protected], [email protected], [email protected] [email protected], [email protected], [email protected], [email protected]
Abstract
arXiv:2607.26937v1 [cs.SE] 29 Jul 2026
Code
Coding agents often retrieve code from an entire repository, but only limited evidence can fit into the final model input. Conventional retrieval-augmented generation (RAG) for coding agents treats fragments from the same code object as separate results, so redundant views can occupy multiple context positions and crowd out useful code. Grouping fragments by code object reduces this redundancy, but can discard local information needed for the task. We describe this tension as an invariance race: allocation should stay stable under redundant renderings but change when a fragment adds task-relevant semantics. To address this race, we introduce VITAL-RAG, which organizes evidence by canonical code object, keeps one query-relevant companion only when it adds semantics not already represented, and renders selected evidence under per-object and global token budgets. On RepoBench, VITALRAG improves Recall@4K from 39.59% to 63.67% while reducing evidence tokens by 35.63%. Across three model backends, it matches or outperforms recent baselines on RepoClassBench and achieves the highest raw Pass@1 on RepoExec.
1
Introduction
Many coding-agent tasks require more repository evidence than can fit in the final model input. Agents that generate code, repair bugs, modify interfaces, write tests, or maintain repositories must select among callees, types, tests, imports, documentation, and failure paths (Jimenez et al. 2024; Wang et al. 2025; Soni et al. 2026). This creates a general context-allocation problem. A coding agent must decide which evidence receives enough of the bounded token budget to influence generation. The problem is especially pronounced at repository scale. Existing work improves candidate discovery through selective retrieval and reranking (Wu et al. 2024; Zhang et al. 2025), filters low-utility chunks (Huo et al. 2026), or enriches multi-view context (Liu et al. 2026; Oh and Lee 2026). However, a function body, signature, docstring, and call site may all describe the same code object. To our knowledge, prior work has not isolated and quantified the failure that occurs after correct evidence is retrieved but before generation, when repeated views compete with independent objects under a bounded rendering budget. We refer to this problem as repository evidence allocation for coding agents. Figure 1 presents the resulting retrieval-to-context failure.
Generation
Code Transformation
Bug Fixing
Test & Verification
Maintenance &Evolution
Repository context
1 Multi-view Context retrieval
2
A Body
Function A — Body
def f(x: int) -> int: return helper(x)
Function A — Signature
def f(x: int) -> int
Function A — Call site
y = f(x) ...
Unit test B
def test_f(): assert f(5) == 5
Helper function C
def helper(z: int) -> int: return z
A Signature
A Call site
Context-window Budget
Test B
Helper C
Independent Context Evicted
3
Function A — Body
def f(x: int) -> int: return helper(x)
Multi-view Context retrieval
Function A — Signature
def f(x: int) -> int
Function A — Call site
y = f(x) ...
Unit test B
def test_f(): assert f(5) == 5
Helper function C
def helper(z: int) -> int: return z
Required Context Missing
Figure 1: A repository-context failure after successful retrieval. Repeated views of Function A consume slots, so required Helper C is clipped by the input budget.
Retrieval and allocation govern different stages of repository context construction. Selective retrieval and utilityaware filtering determine which candidates enter the pool (Wu et al. 2024; Zhang et al. 2025; Huo et al. 2026), while long-context studies show that position affects model use (Liu et al. 2024a). Our focus is the intervening stage, where retrieved candidates are rendered into a bounded model input. As Figure 1 shows, repeated views can occupy several positions even when the ranking is correct, leaving less context for independent evidence. Repository-scale agents therefore require an allocation rule that preserves broad discovery without allowing representation count to determine context
share. This allocation must operate at two coupled scales. Fragment-level selection is too fine-grained because multiple renderings of one code object receive separate opportunities to influence generation. Selection over only the globally strongest canonical code objects is too coarse-grained because a task-relevant validator, exception helper, or downstream call may be a distinct object within the same source region. We call this tension the invariance race: allocation should remain invariant to redundant views but sensitive to task-relevant new information. We call the corresponding design principle selective invariance. Context authority thus has a discrete component that selects objects and a continuous component that determines how much of each selected object survives the token budget. We introduce VITAL-RAG, a repository context allocation layer placed between a provenance-preserving retriever and a coding-agent generator. The name expands to ViewInvariant, Task-Aware Allocation Layer for RAG and reflects its allocation principle. VITAL-RAG groups multiview fragments into canonical code objects, keeps one queryrelevant companion from the same source region, and assigns bounded token authority through compact evidence rendering. An optional program-semantic transfer extension arbitrates between programs produced from alternative portfolios. This design separates candidate discovery, object allocation, token allocation, and generation. We make three contributions. First, we identify and analyze a systematic retrieval-tocontext failure in repository-level coding agents. Relevant evidence may be retrieved successfully but lost during bounded context construction. We trace this loss to authority multiplication and formalize the resulting invariance race between suppressing redundant views and preserving task-relevant local evidence. Second, we introduce VITAL-RAG, a retriever-agnostic context allocation layer built on selective invariance. It groups multi-view fragments by canonical code object, keeps at most one query-relevant companion from the same source region, and controls token use through per-object and global budgets. Third, we evaluate VITAL-RAG from evidence preservation to downstream code generation. On RepoBench, it raises Recall@4K from 39.59% to 63.67% while using 35.63% fewer evidence tokens. It remains competitive on RepoClassBench and achieves the highest raw Pass@1 on RepoExec across three model backends.
2 2.1
Related Work
Repository-Level Retrieval for Coding Agents
Repository-level code generation depends on cross-file evidence, as established by RepoBench and CrossCodeEval (Liu, Xu, and McAuley 2024; Ding et al. 2023). Recent systems decide when to retrieve, follow dataflow or repository graphs, identify necessary knowledge, combine textual and structural signals, and preserve semantics across chunks (Wu et al. 2024; Cheng, Wu, and Hu 2024; Ouyang et al. 2025; Zhang et al. 2025; Shi, Gao, and Gao 2026; Oh and
Lee 2026). SWE-bench, RepoClassBench, OpenHands, and OpenHands-Versa connect these advances to issue resolution, class generation, and tool-using agents (Jimenez et al. 2024; Deshpande et al. 2024; Wang et al. 2025; Soni et al. 2026). This broader evidence pool makes bounded context construction a distinct stage after retrieval.
2.2
Evidence Selection and Context Allocation
RAG selection determines which external information conditions generation (Lewis et al. 2020). MMR and submodular objectives balance relevance with coverage, while codingagent systems add selective retrieval, structural reranking, and learned filtering (Carbonell and Goldstein 1998; Lin and Bilmes 2011; Wu et al. 2024; Cheng, Wu, and Hu 2024; Zhang et al. 2025; Shi, Gao, and Gao 2026). RepoShapley further models interaction-aware chunk utility (Huo et al. 2026). These methods move beyond raw recall but usually let candidate texts compete independently. Exact deduplication misses multiple renderings of one object, whereas coarse grouping can hide a query-relevant companion. The unresolved question is how code objects receive context authority before rendering.
2.3
Context Robustness in Coding Agents
Retrieved chunks can complement one another, interfere with decoding, lose semantics during chunking, or become less usable because of context position (Huo et al. 2026; Oh and Lee 2026; Liu et al. 2024a; Yan, Liu, and Ling 2025). In coding agents, these choices affect repository edits, tests, and builds (Jimenez et al. 2024; Wang et al. 2025; Soni et al. 2026). Repository pipelines sharpen the problem because parsers, graph indexes, and sliding windows often render one code object several ways. Context allocation must therefore ignore redundant views while retaining distinct nearby evidence, which motivates measuring evidence survival under a bounded model input.
3
Empirical Evidence of Retrieval-to-Context Loss
The literature distinguishes retrieval quality from context usefulness, but does not reveal how much already-retrieved evidence is lost during model input construction. We test this boundary before model-specific generation or execution. RepoBench provides labeled cross-file evidence at scale, letting us observe whether evidence found by retrieval remains available under a finite token budget. A fixed pre-method selection setting isolates this transition at the bounded model input.
3.1
Dataset and Measurement Protocol
RepoBench supplies repository-level completion tasks with labeled cross-file evidence (Liu, Xu, and McAuley 2024). The source has 16,755 rows. Exact-row deduplication leaves 16,741, and leakage and invalid-label screening yields 16,490 eligible tasks from 2,798 repositories. The shared evaluation set contains 8,556 Java and 7,934 Python tasks. We test whether required evidence enters the portfolio but its labeled content disappears from the bounded model input.
Scope
Tasks
R@5 Auth.@5 R@4K ∆Recall Tokens
All 16,490 64.16 Java 8,556 63.97 Python 7,934 64.37
4.422 4.413 4.432
39.59 37.60 41.73
24.57 26.37 22.64
2,720 2,798 2,637
Table 1: RepoBench evidence-survival gap under Entity-First 4+1.
Entity-First 4+1 fixes the discrete allocation to at most four canonical code objects and one ungated companion from a selected provenance fiber. Ranking, surface views, and token budget remain fixed, while exact text identity is tracked separately from provenance identity. Each object is capped at 1,024 tokens. Recall@5 measures portfolio entry, while Recall@4K grants credit only when the complete labeled snippet survives within 4,096 tokens. A path or clipped signature therefore does not count as preserved evidence. ∆Recall is the difference between the two measures. Auth.@5 counts selected canonical code objects, and Tokens reports mean rendered length.
3.2
Cross-Language Evidence Survival
Table 1 shows ∆Recall = 24.57 points over all 16,490 tasks: required evidence appears in the selected top five for 64.16% of tasks, but survives in the 4K model input for only 39.59%. The pattern is not confined to one language. ∆Recall is 26.37 points on Java and 22.64 points on Python, despite similar candidate recall and authority counts. Thus, a substantial part of the failure occurs after candidate selection, when retrieved evidence competes for bounded input context. The scale and consistency of ∆Recall matter more than the absolute recall of this setting. The finding spans thousands of repository clusters and two languages with different syntax, type systems, and file organization. Java has the larger ∆Recall, but Python still loses more than one third of the evidence counted as retrieved at five. Because the selection setting and metric definitions are fixed across the two splits, the result is difficult to explain as a language-specific ranking artifact. It instead points to a shared stage of the pipeline: converting ranked repository candidates into a bounded model input. This observation changes what a method must improve. Raising Recall@5 alone is insufficient when selected evidence can disappear during rendering. Conversely, a context constructor can improve Recall@4K without changing the candidate set if it assigns the budget more carefully. Having established this gap, we next trace the allocation mechanism that produces it.
4
Analysis of Evidence Allocation
The large-scale finding establishes that candidate recall and input-level recall can diverge substantially. We now analyze where this divergence comes from and why familiar context controls do not resolve it.
Control
Method
R@5 Auth.@5 R@4K Tokens
Identity
Raw Surface Exact Dedup
46.56 46.51
2.860 2.859
25.08 25.10
3,254 3,253
Coverage
Canonical-5 File Quota MMR Entity-First 4+1
64.10 63.98 64.21 64.16
4.422 4.424 4.424 4.422
39.47 39.42 39.41 39.59
2,734 2,714 2,738 2,720
Table 2: Standard allocation controls on the 16,490 RepoBench tasks.
4.1
Authority Multiplication from Surface Views
A repository retriever can expose a signature, body slice, call site, or test fragment for the same code object. Let q be the task, v a retrieved view, gI (v) the object assigned by repository index I, and B the evidence budget. When allocation treats each view independently, one object can claim several input positions. = PThe resulting context share is share(e) v:gI (v)=e tokens(v). We call the repeated opportunities created by multiple views of e authority multiplication. Object identity follows provenance rather than lexical similarity. Different strings from one code object share an authority claim, while similar strings from independent helpers remain distinct. Under budget B, repeated views can displace independent evidence even when the ranking is correct. For example, a top-five list may contain the signature, body, and call-site view of method a, followed by dependencies b and c. Surface allocation gives a three positions. Exact deduplication cannot remove these distinct strings, and lexical diversity may retain them because they emphasize different tokens. If the required evidence is the full body of c, Recall@5 records success when c enters the list, while earlier views of a can leave only a clipped form of c in the model input. The failure comes from counting one object’s relevance several times before assigning the bounded budget.
4.2
Limitations of Existing Allocation Controls
Table 2 separates several possible explanations. Exact Dedup changes Recall@4K by only 0.02 points, showing that byteidentical repetition is not the main issue. Canonical-5, File Quota, MMR (Carbonell and Goldstein 1998), and EntityFirst 4+1 all raise Recall@5 to about 64% and represent about 4.42 authorities among five candidates, yet Recall@4K remains between 39.41% and 39.59%. These controls improve retrieval diversity or object coverage, but they do not determine which query-relevant meaning should survive the token budget. The controls act at distinct levels. Exact Dedup hashes normalized surface text. Canonical-5 keeps the strongest candidate for each normalized path-and-identifier key. File Quota first takes candidates from previously unseen normalized paths and fills remaining slots from deferred candidates. MMR balances retrieval or query overlap against Jaccard redundancy with equal weight. Entity-First 4+1 fixes four canonical code objects and allows one ungated candidate
from the provenance fiber of a selected object. Their similar Recall@4K values are informative because they remove different kinds of repetition. Together, these controls leave a more specific bottleneck. Identity, query-specific refinement, and rendering must be decided jointly: the context builder must decide which objects own external positions, which local distinctions matter, and how much text each selected object may contribute.
4.3
Selective Invariance as an Allocation Principle
Canonical quotienting prevents one code object from owning several external positions, but a purely global object ranking creates the opposite risk. Repository semantics are often distributed across provenance-local companions. A handler and its validator, a class and its exception helper, or an interface wrapper and its conversion routine are distinct canonical code objects whose relevance is coupled by the task. Ignoring this local structure preserves identity but can erase a necessary distinction. Selective invariance resolves the invariance race at two scales. Allocation is invariant to view multiplicity at the object scale and sensitive to query-relevant additions at the provenance-fiber scale. Let Sq (V) ⊆ V be the representative views assigned external positions from a candidate set V. For canonical code object e, define its authority multiplicity as µq (e | V) = |{v ∈ Sq (V) | gI (v) = e}| , ≤ 1, e ∈ gI (V).
(1)
The guarantee concerns slot ownership rather than absolute rank stability under arbitrary score perturbations. Adding more renderings may replace an object’s representative, but it cannot create another external authority for that object. Task sensitivity is introduced separately by allowing one distinct, query-relevant object from a selected provenance fiber. This separation turns the observed gap into a concrete allocation problem: preserve object-level invariance while keeping query-relevant local semantics.
5 5.1
5.2
The first decision is which retrieved views make the same authority claim. VITAL-RAG obtains this relation from a provenance adapter supplied by repository index I. The adapter gI may use parser-qualified symbol IDs, graph nodes, or another stable object identifier. In our evaluation, the available index exposes a path p(v) and identifier n(v), so the adapter is instantiated as gI (v) = (normpath(p(v)), casefold(n(v))). We write Eq = gI (Vq ) for the resulting object set and Vq (e) = {v ∈ Vq | gI (v) = e} for the views of object e. All views in Vq (e) now compete for one external position. Let ≻q denote their retrieval order. VITAL-RAG assigns the position to the strongest view and inherits its relevance score: ve⋆ = max Vq (e), ≻q
rq (e) = sq (ve⋆ ).
(2)
Equation 2 quotients authority without accumulating scores across repeated views. Low-overlap renderings of one object share a key, while similar helpers with different provenance remain separate. A new view may replace ve⋆ , but Eq. 1 prevents it from creating another position. Neither labels nor generator outputs enter this decision.
5.3
Query-Conditioned Provenance Refinement
Object-level invariance alone can be too rigid because a selected source region may contain a distinct helper needed by the task. VITAL-RAG therefore reserves one of the K positions for task-aware refinement. The other kq = min(K − 1, |Eq |) positions form the core set Cq = Topkq (Eq , rq ). With K = 5, one reserved position is the smallest nonzero refinement that retains four globally ranked objects. The boundary ablation compares zero, one, and two companion positions. Let π(e) denote an object’s normalized source path, let π(Cq ) denote the paths represented by the core, and let T (x) extract identifier-like tokens from a task or view. The reserved position is offered to the strongest non-core object that is both provenance-local and query-relevant: e+ q = arg max rq (e)
VITAL-RAG
e∈Eq \Cq
subject to
Method Overview
VITAL-RAG is a repository context allocation layer between a provenance-preserving retriever and a coding-agent generator. It accepts ranked multi-view evidence from sparse, dense, or graph retrieval. Figure 2 follows the allocation path used by the method. First, a repository-index provenance adapter groups body, signature, call-site, and related views by canonical code object and selects one representative for each object. Second, query-conditioned provenance refinement keeps one position for a distinct query-relevant companion. Third, budget-constrained token authority renders the resulting portfolio as C(q), the model input. These three stages form the core allocation layer. The lower-right branch in Figure 2 is an optional post-generation extension that arbitrates between two already generated programs and never changes C(q). Formally, q is a coding task, Vq is a finite set of retrieved views, sq : Vq → R is the retrieval score, K = 5 is the slot budget, and B ∈ N is the token budget.
View-Quotiented Authority Allocation
π(e) ∈ π(Cq ),
(3) T (q) ∩ T (ve⋆ ) ̸= ∅.
If the constraint set is nonempty, the final object portfolio is Aq = Cq ∪ {e+ q }. Otherwise, the highest-ranked remaining object fills the position, or the position is omitted when no object remains. Thus |Aq | = min(K, |Eq |), and every member owns one position. Crucially, e+ q is a distinct query-relevant companion rather than another fragment of a core object. The certificate uses only provenance and query tokens, never the labeled dependency.
5.4
Budget-Constrained Token Authority
Discrete allocation determines which objects own positions. Rendering determines their continuous token authority. Write the ordered allocation as Aq = (e1 , . . . , em ), where m = |Aq |. Let ρ̄q (ei ) be the unclipped descriptor and querycentered code window for object ei , let di = ℓ(ρ̄q (ei )), and let ρq (ei , bi ) be its largest line-complete rendering of at most bi tokens.
Input: Ranked Multi-View Evidence 1
A Function A — Body def f(x: int) -> int: return helper(x)
2
A
4
C
def test_f(): assert f(5) == 5
5
6
7
E Type Definition E
D
B
……
Helper function C def helper(z: int) -> int: return z
Test B
Token Budget C(q)
?
Exception help D
Matches query "helper"? ✓
?
def format_error(x: int) -> str: return f"invalid: {x}"
C Helper function C
B
D
E
+
C
Refined Evidence
def helper(z: int) -> int: return z
Context Allocation
Program-Semantic Authority Transfer ���
Same provenance as A? ✓
A*
C
E
Final model input
4
class Input: value: int
B
D
A
Query:Complete f using helper
B Unit test B B
B
Agent Output:
3
Query-Conditioned Provenance Refinement
2
y = f(x) ...
A*
Help D
A* Function
A Call site
A Function A — Call site A A
Budget-Constrained Token Authority
3 D
Body
A Signature
A Function A — Signature def f(x: int) -> int
3
Provenance Graph Adapter
1
��
��alt
Typed Directional Witnesses
Transfer
Abstain
�� = ���� �
�� = ���� �
Repository Update
Figure 2: VITAL-RAG’s allocation path. A repository-index provenance adapter groups multi-view evidence by canonical code object. Query-conditioned refinement keeps one query-relevant companion, and budget-constrained rendering constructs C(q). The lower-right transfer branch is an optional post-generation extension and does not alter context allocation. The per-object cap bobj prevents one object from consuming the model input. A conditional floor βq equalsP bmin when B ≥ mbmin and zero otherwise. Let Ri = B − j<i bj be the unspent budget before object ei . VITAL-RAG reserves the floor for every later object, then assigns the largest admissible share to the current object: n o bi = min di , bobj , [Ri − (m − i)βq ]+ . (4) Here, [x]P + = max(x, 0). Equation 4 guarantees 0 ≤ bi ≤ bobj and i bi ≤ B. Once the token shares are fixed, the selected objects are rendered in allocation order to form the agent context: C(q) =
m M
ρq (ei , bi ).
(5)
i=1
L The operator denotes ordered concatenation. Each rendering emits a compact path, identifier, and signature descriptor before using the remaining share for a query-centered code window. We use B = 4096, bobj = 1024, and bmin = 128. Rendering therefore adjusts how much evidence each selected object contributes without granting it another context position.
5.5
Agent-Level Extension: Program-Semantic Transfer
The three preceding operations produce the agent context. When two fixed evidence portfolios are available, the coding agent may additionally generate a default program yqdef and an authority-oriented alternative yqalt . For witness type τ , let
ϕτ (y) be its code-visible feature and let ≻τ,q denote taskconditioned semantic improvement. Output authority transfers only when at least one typed, directional witness favors the alternative: alt yq , ∃τ ∈ Tm : ϕτ (yqalt ) ≻τ,q ϕτ (yqdef ), (6) ybq = yqdef , otherwise. The witness families cover syntax repair, interface consistency, suspicious-name reduction, and validity-guarded compactness. In Eq. 6, the relation supplies direction-aware authority, Tm supplies typed semantics, and the default branch supplies abstention. This high-precision stage is optional and does not alter context allocation. The context-construction layer is training-free and applies to sparse, dense, graph-based, and agent-generated retrievers that retain repository provenance. For n candidates, provenance grouping and refinement are linear in the candidate set, while ordering object representatives costs O(n log n) in the general case. These design choices also give the evaluation a natural order. Provenance quotienting decides which code objects receive authority in the portfolio. Bounded rendering decides whether accepted evidence survives the 4K budget. The transfer gate decides when an alternative program may replace the default, and whether such replacements help execution. We therefore read the results along the same path: entry, survival, and program-level consequence.
6
Experimental Evaluation
The evaluation follows the repository evidence path rather than three unrelated leaderboards. RepoBench measures
Scope
Base
VITAL-RAG
Gain
Tokens B/V
Red.
All Java Python
39.59 37.60 41.73
63.67 63.69 63.65
+24.08 +26.09 +21.92
2,720/1,751 2,798/1,765 2,637/1,736
35.63% 36.91% 34.18%
Table 3: Paired RepoBench results. Base denotes Entity-First 4+1, and reductions use unrounded means.
whether retrieved evidence survives bounded context construction. RepoClassBench tests transfer to class-level generation, where output remains close to context choice. RepoExec is the strict end-to-end check: allocation decisions must survive generation and repository-level execution. These roles test the phenomenon, cross-task transfer, and executable consequence without defining VITAL-RAG around one benchmark.
6.1
Experimental Setup
The primary RepoBench comparison holds the discrete candidate portfolio fixed, thereby isolating continuous token allocation during rendering. Recall@4K requires complete labeled evidence within 4,096 evidence tokens, and Tokens is the mean rendered length. We report Recall@4K gains in points and token reductions as relative percentages. For downstream generation, we evaluate Gpt-5.4, Claude Sonnet 4.6, and Qwen3-8B on RepoClassBench (Deshpande et al. 2024) and RepoExec (Hai, Nguyen, and Bui 2025). Both comparisons use CodeRAG, GraphCoder (Liu et al. 2024b), RepoScope (Liu et al. 2026), and VITAL-RAG. The suffix “-style” indicates a common evaluation setting rather than an exact reproduction of each original system. The ablation study removes provenance quotienting, budget-aware rendering, and all structural controls on RepoBench, then isolates the optional transfer policy. Optional transfer compares paired programs produced by the same language model from two fixed evidence portfolios. One authority-oriented alternative is used consistently across models. The transfer ablations keep both programs fixed and isolate abstention, directionality, and typed semantic witnesses.
6.2
Isolating Token Authority under a 4K Budget
Table 3 isolates continuous token authority under the paired setup above. VITAL-RAG raises Recall@4K from 39.59% to 63.67% while using 35.63% fewer evidence tokens. Because the selected candidates are held fixed, this improvement cannot come from discovering easier evidence or changing the ranking. It reflects whether the evidence already admitted to the portfolio remains visible after rendering. Recall and context length improve together. Rather than exchanging evidence coverage for compression, VITAL-RAG reduces ∆Recall between portfolio entry and 4K survival to 0.49 points. Java and Python show similar final recall and token reductions despite different starting points, indicating that the gain follows the allocation rule rather than one language’s syntax or typical snippet length.
Method CodeRAG’25 GraphCoder’24 RepoScope’26 VITAL-RAG
Claude Sonnet Gpt-5.4 Qwen3-8B 4.6 Token-F1/Char Token-F1/Char Token-F1/Char 0.5764/0.4220 0.5138/0.3434 0.5948/0.4491 0.6012/0.4561
0.7084/0.5632 0.4865/0.3479 0.6509/0.4673 0.4059/0.2799 0.7203/0.5700 0.5164/0.3457 0.7203/0.5700 0.5164/0.3457
Table 4: RepoClassBench Token-F1/character similarity on 227 tasks.
6.3
Class-Level Reconstruction
RepoClassBench contains natural-language-to-class tasks drawn from real Java, Python, and C# repositories, where each target class depends on code objects outside the class itself (Deshpande et al. 2024). A model must recover fields, methods, types, imports, and cross-file calls from allocated repository evidence and assemble them into one coherent class. We score the 227 tasks that provide reference class bodies. Token-F1 compares lexical code tokens and measures finegrained recovery of identifiers, type names, helper calls, literals, and control-flow vocabulary. Character similarity compares complete class bodies and gives a coarser view of whole-code resemblance, including broad structure and surface form. Together, they distinguish recovery of critical code details from production of code with only a similar overall shape. Table 4 shows that VITAL-RAG is best or tied across most model-metric combinations. It leads both Gpt-5.4 measures and matches RepoScope-style on both Claude Sonnet 4.6 measures. For Qwen3-8B, it ties for the highest Token-F1 while remaining close to the best character similarity. This split is informative because repository-specific tokens can be recovered even when the complete surface form differs. The agreement across backends indicates that bounded allocation preserves usable class-level information rather than favoring one model’s rendering style.
6.4
End-to-End Execution
RepoExec provides the complementary executable setting (Hai, Nguyen, and Bui 2025). Its 355 tasks ask the model to generate a target function whose behavior depends on the surrounding repository. The generated implementation is inserted into the project and evaluated by its tests. We use one generation per task, and Pass@1 is the fraction of the common 355-task set for which that implementation passes. Pass@1 is stricter than similarity because execution depends on several facts being correct together. The code must respect signatures and types, invoke the right repository helpers, preserve state and return behavior, and handle tested boundary conditions. One wrong dependency or missing validation branch can invalidate an otherwise similar implementation. Pass@1 therefore measures whether allocation retains a jointly sufficient set of critical repository evidence. Table 5 shows that VITAL-RAG obtains the highest raw Pass@1 with all three backends. The advantage is largest
Method CodeRAG’25 GraphCoder’24 RepoScope’26 VITAL-RAG
Claude Sonnet Gpt-5.4 Qwen3-8B 4.6 Passed/Pass@1 Passed/Pass@1 Passed/Pass@1 185/52.11 186/52.39 197/55.49 205/57.75
189/53.24 194/54.65 191/53.80 233/65.63
53/14.93 75/21.13 54/15.21 77/21.69
Table 5: RepoExec Passed/Pass@1 over 355 tasks per model.
(a) Context-allocation components on RepoBench Variant R@5 R@4K ∆Recall Full No quotient No rendering No structure
64.16 46.54 64.16 46.56
6.5
Ablation of Context Allocation and Program Transfer
Panel (a) separates the two allocation failures. Without the provenance quotient, too few correct objects enter the portfolio. Without budget-aware rendering, entry is preserved but ∆Recall rises to 24.57 points. Removing both structural controls yields the lowest Recall@4K and the largest context. Thus, object authority protects portfolio entry, while token authority protects accepted evidence from later clipping. The complete layer is the only variant that achieves both high entry and low loss. Panel (b) tests the choice of one companion over 231 tasks. The strict subset contains the 33 cases where a query-relevant local companion is eligible, so it directly measures whether refinement recovers evidence that canonical-only allocation would miss. Moving from 5+0 to 4+1 substantially improves strict recall with little change in broad recall. Reserving a second companion yields only a small additional strict gain while reducing broad recall and increasing token use. The 4+1 split is therefore the empirical balance point: it recovers query-relevant local semantics without allowing refinement to dominate global object coverage. Panel (c) tests whether the 4K result depends on a particular context limit. VITAL-RAG improves rapidly from 1K to 4K and then saturates, while the rendering ablation remains substantially lower at 8K. Larger windows therefore do not remove the need for structured allocation. Panel (d) treats transfer as an optional precision-oriented extension. Full VITAL-RAG transfers 181 outputs with 59 gains and 11 losses. Removing abstention, direction, or typed semantics lowers Pass@1. Panels (a)–(c) do not use transfer. Together, the ablations trace the gains to provenance quotienting, budget-aware rendering, and one companion, linking the improvement to allocation rather than additional retrieval or a specific model.
0.49 0.39 24.57 21.48
1,751 2,061 2,720 3,254
(b) Companion-slot boundary on RepoExec Allocation All R Strict R All Tok. Strict Tok. Canonical 5+0 VITAL-RAG 4+1 Refined 3+2
with Claude Sonnet 4.6 and remains positive with Gpt-5.4 and Qwen3-8B, so the shorter allocated context does not trade away executable correctness. The consistent raw ordering across all three backends links evidence preservation to end-to-end utility. RepoClassBench shows fine-grained content recovery and broad code similarity. RepoExec then shows that the retained information points can jointly support execution, where one missing dependency is enough to lose the task.
63.67 46.15 39.59 25.08
Tokens
39.59 38.94 34.16
16.26 21.31 22.20
1,594 1,612 1,778
1,536 1,485 1,725
(c) Context-budget sensitivity on RepoBench Budget Full No rendering
∆Recall
1K 2K 4K 8K
19.33 30.07 39.59 40.86
+24.26 +30.06 +24.08 +22.82
(d) Optional transfer policy on RepoExec Variant Pass@1 Trans.
W/L
Prec.
Full No abstention No direction No types
59/11 96/79 69/45 20/12
84.3% 54.9% 60.5% 62.2%
43.58 60.13 63.67 63.68
48.36 45.45 46.10 44.60
181 1,065 362 181
Table 6: VITAL-RAG ablations. Panel (c) reports raw ∆Recall. Panel (d) rounds W/L only.
7
Limitations
VITAL-RAG receives object identity from a repositoryindex provenance adapter. Our evaluated adapter uses normalized paths and identifiers, while richer indexes can supply qualified symbols or graph nodes without changing allocation. The experiments use a fixed 4,096-token evidence budget and object caps; other context windows can keep the allocation order with adjusted caps.
8
Conclusion
Repository-level coding agents benefit from retrieval only when evidence survives bounded context construction. We identify authority multiplication as the cause of this gap and derive selective invariance as its allocation principle. VITAL-RAG implements this principle through object-level allocation, task-aware refinement, and bounded rendering. Across RepoBench, RepoClassBench, and RepoExec, it improves evidence survival, class reconstruction, and executable outcomes across three model backends. This points to a simple lesson: repository RAG needs allocation, not only ranking. Stronger retrievers expand the pool; VITALRAG decides which retrieved code objects receive bounded context authority.
References Carbonell, J. G.; and Goldstein, J. 1998. The Use of MMR, Diversity-Based Reranking for Reordering Documents and Producing Summaries. In Proceedings of the 21st Annual International ACM SIGIR Conference on Research and Development in Information Retrieval, 335–336. ACM. Cheng, W.; Wu, Y.; and Hu, W. 2024. Dataflow-Guided Retrieval Augmentation for Repository-Level Code Completion. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 7957–7977. Association for Computational Linguistics. Deshpande, A.; Agarwal, A.; Shet, S.; Iyer, A.; Kanade, A.; Bairi, R.; and Parthasarathy, S. 2024. Class-Level Code Generation from Natural Language Using Iterative, Tool-Enhanced Reasoning over Repository. arXiv:2405.01573. Ding, Y.; Wang, Z.; Ahmad, W. U.; Ding, H.; Tan, M.; Jain, N.; Ramanathan, M. K.; Nallapati, R.; Bhatia, P.; Roth, D.; and Xiang, B. 2023. CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion. In Advances in Neural Information Processing Systems, volume 36, 46701–46723. Curran Associates, Inc. Hai, N. L.; Nguyen, D. M.; and Bui, N. D. Q. 2025. On the Impacts of Contexts on Repository-Level Code Generation. In Findings of the Association for Computational Linguistics: NAACL 2025, 1496– 1524. Albuquerque, New Mexico: Association for Computational Linguistics. Huo, Y.; Zeng, K.; Zhang, S.; Lu, Y.; Yang, C.; Guo, Y.; and Tang, X. 2026. RepoShapley: Shapley-Enhanced Context Filtering for Repository-Level Code Completion. In Findings of the Association for Computational Linguistics: ACL 2026, 10390–10412. Association for Computational Linguistics. Jimenez, C. E.; Yang, J.; Wettig, A.; Yao, S.; Pei, K.; Press, O.; and Narasimhan, K. 2024. SWE-bench: Can Language Models Resolve Real-World GitHub Issues? In The Twelfth International Conference on Learning Representations. OpenReview.net. Lewis, P.; Perez, E.; Piktus, A.; Petroni, F.; Karpukhin, V.; Goyal, N.; Küttler, H.; Lewis, M.; Yih, W.-t.; Rocktäschel, T.; Riedel, S.; and Kiela, D. 2020. Retrieval-Augmented Generation for KnowledgeIntensive NLP Tasks. In Advances in Neural Information Processing Systems, volume 33, 9459–9474. Curran Associates, Inc. Lin, H.; and Bilmes, J. A. 2011. A Class of Submodular Functions for Document Summarization. In Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies, 510–520. Association for Computational Linguistics. Liu, N. F.; Lin, K.; Hewitt, J.; Paranjape, A.; Bevilacqua, M.; Petroni, F.; and Liang, P. 2024a. Lost in the Middle: How Language Models Use Long Contexts. Transactions of the Association for Computational Linguistics, 12: 157–173. Liu, T.; Xu, C.; and McAuley, J. J. 2024. RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems. In The Twelfth International Conference on Learning Representations. OpenReview.net. Liu, W.; Yu, A.; Zan, D.; Shen, B.; Zhang, W.; Zhao, H.; Jin, Z.; and Wang, Q. 2024b. GraphCoder: Enhancing Repository-Level Code Completion via Coarse-to-fine Retrieval Based on Code Context Graph. In Proceedings of the 39th IEEE/ACM International Conference on Automated Software Engineering, 570–581. Association for Computing Machinery. Liu, Y.; Zhang, L.; Liu, F.; Wang, Z.; Wei, D.; Yang, Z.; Zhang, K.; Li, J.; and Shi, L. 2026. RepoScope: Leveraging Call ChainAware Multi-View Context for Repository-Level Code Generation.
In Proceedings of the 48th IEEE/ACM International Conference on Software Engineering. Oh, S.; and Lee, E. 2026. Late Code Chunking: A Code Chunking Strategy for Repository-Level Code Completion. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), 780–786. Association for Computational Linguistics. Ouyang, S.; Yu, W.; Ma, K.; Xiao, Z.; Zhang, Z.; Jia, M.; Han, J.; Zhang, H.; and Yu, D. 2025. RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graph. In The Thirteenth International Conference on Learning Representations. OpenReview.net. Shi, C.; Gao, M.; and Gao, Z. 2026. AIRCoder: Adaptive Integration of Multi-dimensional Retrieval for Repository-level Code Completion. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 25458–25470. Association for Computational Linguistics. Soni, A. B.; Li, B.; Wang, X.; Chen, V.; and Neubig, G. 2026. Coding Agents with Multimodal Browsing are Generalist Problem Solvers. In Findings of the Association for Computational Linguistics: EACL 2026, 6052–6069. Association for Computational Linguistics. Wang, X.; Li, B.; Song, Y.; Xu, F. F.; Tang, X.; Zhuge, M.; Pan, J.; Song, Y.; Li, B.; Singh, J.; Tran, H. H.; Li, F.; Ma, R.; Zheng, M.; Qian, B.; Shao, Y.; Muennighoff, N.; Zhang, Y.; Hui, B.; Lin, J.; Brennan, R.; Peng, H.; Ji, H.; and Neubig, G. 2025. OpenHands: An Open Platform for AI Software Developers as Generalist Agents. In The Thirteenth International Conference on Learning Representations. OpenReview.net. Wu, D.; Ahmad, W. U.; Zhang, D.; Ramanathan, M. K.; and Ma, X. 2024. Repoformer: Selective Retrieval for Repository-Level Code Completion. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, 53270–53290. PMLR. Yan, S.-Q.; Liu, Q.; and Ling, Z.-H. 2025. RPO: Retrieval Preference Optimization for Robust Retrieval-Augmented Generation. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 5228–5240. Association for Computational Linguistics. Zhang, S.; Ding, Y.; Lian, S.; Song, S.; and Li, H. 2025. CodeRAG: Finding Relevant and Necessary Knowledge for Retrieval-Augmented Repository-Level Code Completion. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, 23278–23288. Association for Computational Linguistics.