Developer tools · Research feature

Study Benchmarks Agentic Code Reasoning in Real-World Repositories

A new benchmark evaluates how well AI agents reason across entire code repositories, focusing on logical consistency and integration depth.

Adapted from research by Jia Li, Yuxin Su, Michael R. Lyu.

arXiv preprint revision · 2026-05-03 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

The study introduces RepoReason, a white-box benchmark that assesses agentic code reasoning by verifying abductive assertions within real codebases. It uses an execution-driven mutation framework where the runtime environment acts as a semantic oracle to generate accurate ground-truth states, ensuring tasks reflect authentic code behavior. The system measures reasoning through three metrics: reading load, simulation depth, and integration width. Evaluations of frontier models show a consistent deficit in integration width, indicating a key limitation in how agents handle interdependent code components. The benchmark is currently focused on Python, though its architecture supports extension to other languages via standard profiling interfaces, enabling broader applicability in future work.

Introduction

The paradigm of software engineering is undergoing a fundamental shift: from human-centric coding to agentic autonomous development. As Large Language Models (LLMs) evolve into autonomous software agents, the core competency required has escalated from performing localized execution reasoning within isolated code snippets—akin to controlled laboratory exercises—to maintaining logical consistency across extensive, interdependent file systems—a capability we define as Repository-Level Reasoning. This capability imposes profound challenges on LLMs, demanding not only code synthesis but also the agency to explore vast contexts to pinpoint target definitions, aggregate multi-source information across complex dependencies, and perform long-chain reasoning to accurately track and compute state mutations.

However, a critical gap exists between this growing demand and current evaluation methods. Existing benchmarks largely fall into two extremes. On one side, function-level reasoning datasets, such as CRUXEval and REval, study code execution reasoning within isolated snippets. While these provide analytical rigor, they operate in a laboratory setting that lacks the cross-file dependencies and complex architectural contexts found in real-world software engineering. On the other side, frameworks like SWE-bench evaluate agents in wild repository environments but function as black-boxes: they check whether a problem is solved but offer little insight into why an agent fails. Without detailed diagnosis, the path to improving agent reasoning remains unclear.

To address this gap, we introduce RepoReason, a repository-level code reasoning benchmark designed as a white-box diagnostic tool. Unlike traditional generation tasks, RepoReason shifts to a verification-centric approach: “Given the complex execution history of this repository, what is the current system state?” By requiring models to derive deterministic values that satisfy assertions rather than writing implementation logic, we separate core logical reasoning from syntactic noise (e.g., formatting errors, indentation slips, or API name hallucinations). This ensures that every failure reflects a genuine deficit in reasoning rather than superficial coding errors.

To ensure the benchmark reflects real-world complexity, we extract task instances from a curated set of mainstream Python repositories (e.g., toolz, sympy, jinja2 ), challenging models with authentic, deep logic. Beyond static code extraction, we perform concrete execution of the repositories’ built-in unit test suites to capture granular runtime traces. By designing structural metrics based on these traces—such as stack depth, function call density, and cross-file dependency breadth—we quantitatively filter and retain only the most complex reasoning tasks.

Code Generation

Existing code benchmarks have evolved from function-level synthesis (e.g., HumanEval, MBPP ) to class-level and repository-level completion (e.g., ClassEval, RepoBench ). While these frameworks increasingly reflect real-world complexity, they primarily target syntactic completion—the ability to produce correct code text. In contrast, RepoReason shifts the focus to semantic reasoning. By requiring the deduction of deterministic system states via assertion verification, it isolates core logical reasoning from the syntactic noise and hallucination risks inherent in code generation.

Code Reasoning

Recent benchmarks like CRUXEval and REval pioneered execution reasoning but are largely confined to isolated, lab-scale code snippets. While tools like CORE incorporate static analysis tasks to evaluate reasoning, they lack the structural depth and code breadth (e.g., deep inheritance, cross-module imports) characteristic of large-scale projects. RepoReason bridges this gap by applying deep execution simulation to massive repository scopes, challenging models to maintain logical consistency across extensive file systems.

Agentic Software Engineering

At the highest level, SWE-bench evaluates agents on resolving GitHub issues. However, as an end-to-end evaluation, it acts as a black-box indicator of success or failure. RepoReason complements this by targeting the cognitive root causes of failure. By decoupling reasoning from code editing and utilizing fine-grained metrics (ESV, MCL, DFI), it provides the white-box diagnostic insights required to pinpoint an agent’s specific bottlenecks in context handling or multi-source integration.

Design Philosophy: Assertions as Semantic Anchors

I/O Prediction Inefficiency: The traditional I/O Prediction paradigm, while effective for isolated algorithmic puzzles, is fundamentally ill-suited for repository-level reasoning. In authentic software ecosystems, runtime data structures, such as SymPy’s symbolic expression trees or NetworkX’s graph topologies, are often voluminous and complex, lacking the clear, concise boundaries found in synthetic tasks. Consequently, verifying the entire output state is inherently inefficient and noise-laden, as a significant portion of the data consists of dynamic metadata or irrelevant state rather than the target logic.

Repository Selection

We selected mature, actively maintained, and predominantly pure Python open-source projects from PyPI and GitHub. Our selection specifically targets libraries where the core logic is implemented in Python, enabling complete line-level tracing via sys.settrace. Libraries with substantial C/C++/Cython extensions (e.g., NumPy, Pandas, PyTorch, scikit-learn) were explicitly excluded, as their core computational routines remain opaque to Python-level instrumentation.

File-Level Semantic Filtering

Test selection prioritizes cases requiring multi-step semantic reasoning over superficial pattern matching. We manually review source code at the file level to screen all test modules. This initial stage aims to filter out low-value assertions and ensure Deterministic Verifiability. We systematically excluded test files falling into three specific categories: (1) Trivial API Validation, comprising simple attribute access (e.g., assert url.scheme == ’http’), direct dictionary operations without cross-module dependencies (e.g., assert d.get(’key’) == ’value’), and metadata introspection lacking computational reasoning (e.g., assert num_required_args(lambda x: None) == 1); (2) Shallow Computation Patterns, including direct formula application or lookup tables (e.g., assert quote(’a b’) == ’a%20b’), simple string manipulation without state complexity, and local transformations requiring no cross-module reasoning (e.g., assert x + 0 == x); and (3) Non-deterministic or External Dependencies, such as tests relying on randomness (e.g., assert random.choice(seq) in seq) or external timing or system state (e.g., assert time.time > start).

Countering Memorization: The Execution-Driven Mutation Engine

The second line of defense addresses Rote Memorization. Since powerful LLMs have likely memorized public codebases, using raw GitHub code leads to data contamination. Our Execution-Driven Mutation framework serves as an Anti-Contamination Engine, creating parallel reasoning realities that preserve logic but alter facts.

Unified Semantic and Logic Mutation. We employ a unified mutation strategy utilizing a teacher LLM. In a single step, the model performs both visual changes (e.g., renaming variables, restructuring code, and removing comments) and logic changes (e.g., modifying constants, input data, and parameters). This combined approach ensures the mutated code is correct and readable, while effectively removing visual clues and invalidating memorized answers. Crucially, it strictly preserves the original API call sequence to the target library to maintain invariant reasoning complexity.

Execution-Driven Ground Truth Regeneration. To ensure the correctness of mutated tests and avoid LLMs hallucinations, we designed an Execution-Driven Assertion Reconstruction framework. First, we use Probe Injection, where the LLMs converts original assertions into print statements formatted as DEBUG_RESULT, turning the test into code that outputs its internal state. Next, we run this code in a controlled environment to capture the actual Runtime Values produced by the logic changes. These values serve as the ground truth, derived directly from code execution rather than model guessing. Finally, we perform Style-Consistent Assertion Generation. Using the captured values and the original code’s style as guides, the LLMs reconstructs the assertions. It mimics the original writing patterns, for example, keeping is for object identity checks instead of changing to ==, or using specific constructors like FiniteSet(1, 2) instead of native sets like {1, 2}. This ensures the new ground truth is mathematically accurate and matches the original codebase’s style.

Strict Validation Gate. We enforce a strict validation process. A mutated test is considered valid only if it meets three criteria: (1) Executability, where the code runs without errors; (2) Assertion Validity, ensuring new assertions pass against the mutated logic; and (3) API Preservation, where the API call sequence matches the original test. Any variant failing these checks is discarded, ensuring all tasks in RepoReason are solvable, deterministic, and maintain original reasoning depth.

Countering Superficiality: Trace-Based Structural Filtering

Trace Collection. With the mutated test cases ready, we capture their runtime behavior using a lightweight tracing system based on Python’s built-in sys.settrace function, which enables line-level execution tracking. Our system records the complete sequence of function calls during the execution of the mutated tests, capturing granular details including function names, module paths, line numbers, call order, call stack depth, function source code, input arguments, return values, and executed lines within each function. Critically, to eliminate noise, we automatically identify the test function as the entry point and focus strictly on the target library’s execution path. Furthermore, to prevent infinite recursion and ensure data manageability, we enforce a maximum call depth of 3, where the test function itself is defined as depth 0.

Cognitive Diagnostic Framework

To quantify the intrinsic reasoning complexity of a task, we perform dynamic program slicing rooted at the assertion to obtain the minimal causal computational subgraph along the actual execution path. Dynamic cross-function backward slicing is obtained by tracing back from the assertion along data and control dependencies within a recorded execution trace to isolate the minimal set of statements that causally influence the observed result. Based on this subgraph, we characterize reasoning intensity using three mutually orthogonal metrics rooted in cognitive load theory.

Experimental Setup

Agent Framework. We utilized OpenHands (version 0.60.0) as our evaluation platform. Specifically, we configured the ReadOnlyAgent for all tasks. This agent configuration is restricted to file system exploration and code reading operations, preventing any modification to the repository. This setup perfectly aligns with the verification nature of RepoReason, isolating the model’s ability to “read, navigate, and reason” from its ability to “edit or plan.”

Model Selection. We evaluated a diverse set of frontier models representing the latest advancements in code reasoning: the Claude Family (claude-sonnet-4.5 ), the GPT Family (gpt-5.2 ), the DeepSeek Family (deepseek-3.1-terminus ), the Kimi Family (Kimi-K2 ), and the Qwen Family (qwen3-coder-480b-a35b ).

Inference Configuration. To ensure reproducibility and eliminate generation randomness, we set the temperature to 0 for all model evaluations. Additionally, to accommodate the potentially lengthy reasoning chains required for repository-level tasks, we set the maximum generation length (max_tokens) to 8192 for each inference step.

Diagnostic Analysis via Cognitive Metrics

A comparative analysis of the decline slopes identifies DFI as the primary cognitive bottleneck for next-generation software agents. The slope of performance degradation is steepest along the DFI axis across all models. When DFI exceeds 20 independent upstream sources, accuracy for most models, with the exception of Claude, falls below the 40% threshold, revealing an Aggregation Deficit: agents struggle to parallelly hold and synthesize constraints from multiple disparate logical sources.

Regarding context processing, we identify a clear “Cliff Effect” in ESV. Performance remains relatively stable in lower context ranges but exhibits a sharp decline once the volume of causally relevant computational units exceeds 600 LoC. This threshold marks the transition into Context Overload, where agents fail to maintain semantic focus across the sliced causal chain. Similarly, for MCL, we observe a significant deterioration in logical consistency beyond 100 execution steps.

To concretize this finding, we examine two representative high-DFI failures in detail (full cases in Appendix G). In Jinja2’s test_groupby_default (DFI=16), the agent correctly inferred the default parameter semantics but failed to integrate the implicit sorting step of groupby, producing two disjoint groups instead of one merged group. In NetworkX’s test_all_simple_paths (DFI=10), the agent accurately constructed the graph topology and enumerated paths but completely ignored the cutoff=2 constraint, returning paths with 3–4 edges. Both cases exhibit a common partial integration followed by breakage pattern: agents successfully process initial information layers but systematically drop final constraints as the number of independent sources grows. This mechanistic evidence corroborates the statistical finding that DFI is the primary cognitive bottleneck.

Conclusion

We presented RepoReason, a white-box diagnostic benchmark for evaluating repository-level code reasoning in LLM agents. By centering on Abductive Assertion Verification and leveraging an Execution-Driven Mutation framework that treats the runtime environment as a Semantic Oracle, we ensure that tasks are both logically authentic and resistant to data contamination. Our fine-grained diagnostic system, built on dynamic program slicing, quantifies reasoning complexity through three orthogonal cognitive metrics: Reading Load (ESV), Simulation Depth (MCL), and Integration Width (DFI). Comprehensive evaluations of frontier models reveal a prevalent Aggregation Deficit, where integration width serves as the primary cognitive bottleneck, alongside a Cliff Effect in reading comprehension beyond 600 lines and significant consistency loss beyond 100 execution steps. These findings provide actionable insights for the next generation of agentic software engineering systems.

Limitations

Language Scope: Currently, RepoReason focuses primarily on Python. Although Python remains the de facto standard for AI-native development and LLM research, extending this benchmark to languages such as Java, C++, and Rust is a priority for future work. We address this potential limitation by ensuring that our system architecture is built on standard profiling interfaces, which are conceptually portable to other language ecosystems, thereby enabling our white-box diagnostic paradigm to cover a broader range of programming environments.

Logical Depth Relative to Base Tests: The reasoning depth of the generated tasks is partially limited by the complexity of the original repository’s test suites. We ensure foundation quality by curating mature projects with exceptionally high test coverage and complexity. The mutation engine then evolves these human-written fixed tests into vast permutations of reasoning scenarios, significantly enhancing task diversity. Incorporating adversarial test generation techniques to augment the source test pool is a promising future direction.

Trace Depth Optimization: We employ a maximum call depth limit (max_call_depth=3) during dynamic trace extraction. Our analysis reveals that removing this limit inflates trace volume by 6.2x overall, predominantly introducing low-level infrastructure functions (e.g., AST traversers, magic methods) that contribute minimally to semantic understanding. Thus, the depth limit serves as a crucial signal-to-noise ratio optimization rather than an artificial restriction on reasoning capacity.

API-Call Sequence Preservation Mechanism

Validation Phase. During validation, we check that each recorded call signature appears in the mutated code as a callable occurrence. The system constructs a regex pattern for each call (matching the function/method name followed by an opening parenthesis) and verifies its presence. Any candidate that removes, substitutes, or reorders these calls is rejected.

D.4.1 Stage 1: Comprehensive Mutation with Probe Generation

In a single LLM call, the system performs both visual/logical mutations and probe injection simultaneously. The LLM is instructed to generate mutated code that directly replaces all original assertions with DEBUG_RESULT print statements, combining mutation and probe generation in one unified step.

D.4.2 Stage 2: Execution-Driven Value Capture

After generating the mutated code with embedded probes, we execute it in a controlled environment and parse the stdout stream to extract DEBUG_RESULT payloads. This execution step captures the actual runtime values produced by the mutated logic, which serve as ground truth for assertion reconstruction.

Artifacts and Input Contracts

Trace Record. Each JSONL entry represents a single test execution with function_calls (array of call_order, function_name, file_path, function_source_code, executed_lines), a condensed execution_flow, and assertion metadata (assert_line counted from the dedented body, line_offset for the absolute first line).

Case 1: Jinja2 test_groupby_default (DFI=16)

Failure Mechanism: The agent correctly inferred the default=’SF’ semantics (tagging cora as SF) but produced two disjoint SF groups. Jinja2’s groupby filter sorts elements before grouping (sorted(value, key=expr)), which merges all SF entries. Although the agent’s trajectory showed it read the documentation for sync_do_groupby specifying this sorting behavior, it failed to integrate this third logical layer. The aggregation chain broke after successfully integrating the first two layers.

Case 2: NetworkX test_all_simple_paths (DFI=10)

Failure Mechanism: The agent correctly built the graph topology and enumerated paths but failed to integrate the cutoff=2 constraint, returning paths with 3 and 4 edges. This exemplifies partial integration followed by breakage: as DFI increases, agents correctly process initial information layers but increasingly drop final constraints.