arXiv:2610.34967cs.SEOct 2026

Manuscript Offprint

arXiv:2610.34967

Rivet: Utility-Preserving Context Control for Repository-Level Coding Agents

Ruwei Pan, Linhao Wu, Yakun Zhang, Zixiong Yang, Lu Zhang, Hongyu Zhang

RUWEI PAN*, Peking University, China

LINHAO WU*, Peking University, China

YAKUN ZHANG, Harbin Institute of Technology (Shenzhen), China

ZIXIONG YANG, Peking University, China

LU ZHANG, Peking University, China

HONGYU ZHANG †^{\dagger}, Chongqing University, China

Repository-level code generation asks an agent to implement a task requirement inside an existing repository. To produce code that works in the repository, the agent needs repository evidence, such as target locations, helper definitions, caller usages, and configuration constraints, which determine how the code should be located, integrated, and executed. Because the context budget cannot hold the entire repository, existing retrieval, compression, and structure-aware methods select context by task similarity, context length, or structural proximity, but these criteria do not directly measure whether the selected context contains this evidence. As a result, the selected context can appear relevant to the task yet miss the evidence that the implementation depends on. We call this failure mode context utility dilution. In this paper, we propose Rivet, a context control framework that preserves repository evidence for coding agents under a fixed context budget. Rivet first uses Signal Grounding to select task-related code anchors by fusing lexical, semantic, and structural signals. Utility Linking then expands these anchors through dependency, usage, and configuration relations to collect repository evidence. Finally, Budget Shaping packs the evidence by priority and, when the budget is tight, reduces snippets to signatures or summaries before dropping them. We evaluate Rivet on two executable repository-level benchmarks, DevEval and RepoExec, with four backbone models, two context budgets (4K and 8K tokens), and eight baselines. Rivet achieves the highest Pass@1 in all 16 settings and improves over the strongest baseline by 3.73–5.15 percentage points on average. Moreover, GPT-5-mini with Rivet outperforms GPT-5 without Rivet on both benchmarks while reducing inference cost by 73.3%–84.5%.

CCS Concepts: • Software and its engineering → Automatic programming.

Additional Key Words and Phrases: Code Generation, Large Language Models

1 Introduction

Given a task requirement and an existing repository, repository-level code generation asks an agent to produce code that satisfies the requirement within that repository [2, 23, 38, 40]. Unlike isolated programming tasks, the produced code must work with existing files, definitions, dependencies, and configurations in the target repository [16]. To produce code that works in the repository, the agent needs repository evidence, i.e., repository information that constrains the implementation, such as target locations, helper definitions, caller usages, and configuration constraints. Repository context is therefore useful only to the extent that it contains such evidence.

However, a repository rarely fits into the context budget of a coding agent, so the agent can only see a selected part of it [33]. Existing context-control methods address this constraint through retrieval-based selection, compression-based shortening, and structure-aware selection [14, 18, 19,

∗^{*}Both authors contributed equally to this research.

†^{\dagger}Corresponding author.

Authors' Contact Information: Ruwei Pan, panruwei666@gmail.com, Peking University, Beijing, China; Linhao Wu, wulin-hao26@stu.pku.edu.cn, Peking University, Beijing, China; Yakun Zhang, zhangyk@hit.edu.cn, Harbin Institute of Technology (Shenzhen), Shenzhen, China; Zixiong Yang, zixiongyang02@gmail.com, Peking University, Beijing, China; Lu Zhang, zhanglucs@pku.edu.cn, Peking University, Beijing, China; Hongyu Zhang, hongyujohn@gmail.com, Chongqing University, Chongqing, China.

Pan et al.

23, 27, 36, 37]. Retrieval-based methods select code snippets according to their similarity to the task requirement [19, 23]. Compression methods shorten retrieved repository context or agent observations to fit the context budget [27]. Structure-aware methods use code structure, such as dependencies or call relations, to retrieve context connected to the task [7, 14, 18]. These criteria provide useful signals for context construction, but a high relevance score, a compact representation, or structural proximity alone does not ensure that the context includes the helper definitions, caller usages, and configuration constraints needed for a particular implementation. We call the resulting failure mode context utility dilution: the selected context appears relevant to the task but lacks the evidence needed to implement the required code correctly in the repository (Section 2).

In this paper, we propose Rivet, a context control framework that preserves repository evidence for repository-level coding agents. Our key observation is that much of this evidence is reachable from the code that the task touches, through static relations such as imports, symbol references, call sites, and configuration links. Therefore, instead of ranking snippets independently by their similarity to the task, Rivet first locates where the task lands in the repository and then follows these relations to collect evidence. Following this observation, Rivet constructs repository context in three stages. ① Signal Grounding first uses lexical, semantic, and structural signals to identify task-related code anchors that indicate where the required code is likely to be implemented or what existing snippets it may depend on. ② Utility Linking then expands these anchors through dependency, usage, and configuration relations to collect helper definitions, caller usages, and configuration constraints. ③ Budget Shaping finally packs the evidence by priority tiers and, when the budget is tight, reduces snippets to signatures or summaries before dropping them. In this way, Rivet spends the budget on evidence that constrains the implementation rather than on text that merely resembles the task.

We evaluate Rivet on two executable repository-level coding benchmarks, DevEval [20] and RepoExec [12]. Across four backbone models and two context budgets, 4K and 8K tokens, we compare Rivet against retrieval, compression, and structure-aware baselines under the same agent scaffold. Rivet achieves the highest Pass@1 in all 16 settings and improves over the strongest baseline by 3.73–5.15 percentage points on average. With a 4K budget, it outperforms the strongest baseline given an 8K budget on DevEval for all four backbone models, and GPT-5-mini with Rivet outperforms GPT-5 without Rivet while reducing inference cost by 73.3%–84.5%. Ablation studies further show that all three stages contribute, with Signal Grounding and Utility Linking accounting for the largest gains.

In summary, this paper makes the following contributions:

  • We identify and characterize context utility dilution, a failure mode of context construction for repository-level coding agents. This failure mode occurs when the selected context appears relevant to the task but lacks the repository evidence needed to locate, integrate, and execute the required code in the target repository. We illustrate this failure mode with a motivating example (Section 2) and a qualitative case study (Figure 4).

  • We propose Rivet, a context control framework that preserves repository evidence under constrained context budgets. Rivet locates task-related code anchors, follows static repository relations from them to collect dependency, usage, and configuration evidence, and packs this evidence under the budget with a representation ladder. This design helps coding agents keep target locations, helper definitions, caller usages, and configuration constraints within the context budget.

  • We evaluate Rivet on two repository-level coding benchmarks, DevEval and RepoExec, with four backbone models and two context budgets, 4K and 8K tokens. The results show

Figure

(a) Repository-level Task

(b) Relevance-oriented Context

(c) Utility-Preserving Context

Fig. 1. Motivating example of context utility dilution. (b) Relevance-oriented retrieval returns keyword-matched snippets but misses helper definitions, caller usages, imports, and configuration. (c) Utility-preserving context retains this evidence under the same budget.

that Rivet achieves an average Pass@1 of 55.74 across all settings and consistently outperforms retrieval, compression, and structure-aware baselines under the same agent scaffold. With half the context budget or a cheaper backbone, Rivet still matches or exceeds stronger configurations at a fraction of the inference cost.