NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Evaluating Long Range Dependency Handling in Code Generation LLMs

Yannick Assogba, Donghao Ren

Abstract

As language models support larger and larger context sizes, evaluating their ability to make effective use of that context becomes increasingly important. We analyze the ability of several code generation models to handle long range dependencies using a suite of multi-step key retrieval tasks in context windows up to 8k tokens in length. The tasks progressively increase in difficulty and allow more nuanced evaluation of model capabilities than tests like the popular needle-in-the-haystack test. We find that performance degrades significantly for many models (up to 2x) when a function references another function that is defined later in the prompt. We also observe that models that use sliding window attention mechanisms have difficulty handling references further than the size of a single window. We perform simple prompt modifications using call graph information to improve multi-step retrieval performance up to 3x. Our analysis highlights ways that long-context performance needs deeper consideration beyond retrieval of single facts within a document.

Introduction: Beyond the Needle-in-a-Haystack

Modern Large Language Models (LLMs) now boast context windows exceeding 128k tokens, yet their ability to utilize this space for complex reasoning remains under-scrutinized. The industry-standard "needle-in-a-haystack" test—finding a single fact buried in a large document—is a low bar for code generation. Real-world programming is inherently non-linear; understanding a single function often requires resolving a chain of dependencies across a codebase. This paper investigates how code LLMs handle these long-range, multi-step dependencies and identifies specific architectural and positional factors that lead to performance "cliffs."

Methodology: The Multi-Step Retrieval Benchmark

To systematically evaluate long-range dependency handling, the researchers designed four synthetic tasks of increasing indirection complexity. These tasks use randomized, nonsensical function names (e.g., zcxjdz_309521) and random return strings to prevent models from relying on training data patterns.

  1. One-step: Direct retrieval where key() returns a string.
  2. Two-step: key() calls value(), which returns the string.
  3. Three-step: A chain of three function calls leading to the final value.
  4. Concatenation: key() calls two different functions and joins their outputs, requiring the model to track multiple dependency paths simultaneously.
Examples of the four synthetic retrieval tasks of increasing complexity.

To simulate realistic conditions, the "haystack" was filled with irrelevant but syntactically correct Python code from the HumanEval dataset, expanding the context window up to 8,000 tokens.

Architectural and Positional Challenges

The study identified two primary factors that degrade performance beyond simple distance:

  • The Forward Reference Penalty: Models struggle significantly more when a dependency is a "forward reference" (the called function appears after the caller in the prompt). This suggests that causal (left-to-right) attention mechanisms bias models toward backward-looking retrieval.
  • The Sliding Window Cliff: Models utilizing sliding window attention, such as Mistral-7B and StarCoder2-7B, exhibit a massive performance drop-off once a dependency spans beyond their specific window size (e.g., 4k tokens). This indicates that these models lose precise detail once information slides out of the immediate attention window.

Results and Analysis

The evaluation revealed a sharp decline in model performance as the number of "hops" or steps in the dependency chain increased. While most models performed well on the one-step task, accuracy dropped precipitously for the concatenation task.

Model performance (Accuracy@3) across tasks of increasing complexity.

As shown in Figure 2, for the hardest task (concatenation), most open-source models fell below 20% accuracy at 8k context. In contrast, frontier models like GPT-4o remained robust, maintaining accuracy above 90%. Furthermore, in two-step tasks, swapping function order to create forward references caused performance to drop by as much as 2x for many models.

Mitigation: Structural Prompting with Call Graphs

To address these failures, the researchers tested a mitigation strategy: Call Graph Comments. By injecting comments above functions that explicitly map their dependencies (e.g., "# This function is called by..."), they provided a structural roadmap for the model. This simple prompt modification improved performance on the three-step task by 1.6x and the concatenation task by 1.5x on average. For certain models, the improvement reached as high as 3x, suggesting that LLMs are far better at following explicit structural hints than navigating raw code logic over long distances.

Conclusion

Long-context capability in code LLMs is not just a matter of token capacity but of reasoning across non-linear dependencies. The findings suggest that future RAG systems and IDE integrations should consider re-ordering code snippets to minimize forward references and utilize structural metadata like call graphs to assist model retrieval. Future research will explore if encoder-decoder or prefix-LM architectures, which lack the causal bias of standard decoders, handle these long-range dependencies more effectively.

Summary updated

BibTeX
@article{assogba2025evaluating,
  author = {Yannick Assogba and Donghao Ren},
  title = {{Evaluating Long Range Dependency Handling in Code Generation LLMs}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=yzACI2vFaX},
}
Figure