← Latest papers
💬 NLP

Sense and Sensitivity: Examining the Influence of Semantic Recall on Long Context Code Reasoning

This paper reveals that while large language models excel at verbatim lexical recall in long code contexts, their ability to understand operational semantics severely degrades when relevant code is centrally positioned, indicating that current benchmarks largely rely on pattern-matching shortcuts rather than true semantic reasoning.

Original authors: Adam Štorek, Mukur Gupta, Samira Hajizadeh, Prashast Srivastava, Suman Jana

Published 2026-04-21
📖 5 min read🧠 Deep dive

Original authors: Adam Štorek, Mukur Gupta, Samira Hajizadeh, Prashast Srivastava, Suman Jana

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a massive library containing millions of books (a huge codebase). You ask a super-smart librarian (a Large Language Model, or LLM) to find a specific page in one of those books and tell you what happens if you read it.

This paper asks a very important question: Is the librarian actually reading and understanding the story, or are they just memorizing the book's title and guessing the ending based on patterns they've seen before?

The researchers discovered that while these AI librarians are incredible at finding the right page, they often fail to understand what's actually written on it when the book is very long.

Here is a breakdown of their findings using simple analogies:

1. The Two Types of "Memory"

The authors distinguish between two ways an AI can "remember" code:

  • Lexical Recall (The Photocopier): This is the ability to find a piece of text and copy it down word-for-word.

    • Analogy: Imagine you ask the librarian to find a specific paragraph about "how to bake a cake." The librarian instantly points to the exact page and recites the ingredients perfectly. They didn't need to understand baking; they just needed to find the words.
    • The Finding: The AI is perfect at this. No matter where the paragraph is in the library (beginning, middle, or end), the AI can find and copy it flawlessly.
  • Semantic Recall (The Chef): This is the ability to understand what the code actually does when it runs.

    • Analogy: Now, you ask the librarian, "If I use these ingredients, will the cake burn?" To answer this, the librarian must actually understand the recipe, not just read the words. They need to simulate the baking process in their head.
    • The Finding: This is where the AI breaks down. When the recipe is hidden in the middle of a massive library, the AI forgets how to bake. It starts guessing or hallucinating, even though it could still find the page if asked to copy it.

2. The "Lost in the Middle" Problem

The researchers found a strange phenomenon they call the "Lost in the Middle" effect.

  • The Setup: They gave the AI a long story with a specific instruction hidden somewhere inside.
  • The Result:
    • If the instruction was at the very start or very end of the story, the AI understood it perfectly.
    • If the instruction was in the dead center of the story, the AI's understanding dropped dramatically.
    • Metaphor: Imagine reading a long novel. If the plot twist is on page 1 or page 300, you remember it. But if the plot twist is on page 150, your brain seems to "glaze over," and you forget the details, even though you read the whole book.

3. The "Shortcut" Trap (Why old tests failed)

The paper explains why previous tests didn't catch this problem.

  • The Old Test (CRUXEval): Imagine a test where the AI has to guess the output of a standard sorting algorithm (like organizing a deck of cards).

    • The Loophole: The AI didn't need to read the specific code provided. It just recognized the pattern "Oh, this is a sorting algorithm!" and said, "The result will be sorted cards." It took a shortcut using its pre-training memory.
    • The Sensitivity: This test had low sensitivity. It allowed the AI to cheat by guessing based on patterns rather than reading the specific code.
  • The New Test (SemTrace): The researchers created a new, "uncheatable" test.

    • The Setup: They gave the AI a function that does random, unpredictable math (e.g., "Take the number 81, subtract 43, then add 88, then subtract 74...").
    • The Trap: There is no pattern to memorize. The AI must read the specific lines of code provided to get the answer.
    • The Result: When they used this test, the AI's performance in the "middle" of the context collapsed. Accuracy dropped by 92%. The AI couldn't do the math if the instructions were buried in the middle of the text.

4. The "Counterfactual" Experiment

To prove the AI was cheating, the researchers played a game of "remove the lines."

  • They took a piece of code and deleted 50% of the lines.
  • Real Understanding: If you delete half the instructions for a recipe, the cake will be ruined. A real chef (or a Python interpreter) would fail immediately.
  • The AI's Reaction: Even with half the code missing, the AI still got the answer right about 60% of the time!
  • Conclusion: This proved the AI wasn't actually reading the code; it was just guessing based on the idea of what the code usually looks like.

5. The GPT-4.1 Surprise

One model, GPT-4.1, seemed to ace the new "uncheatable" test. The researchers dug deeper and found a trick:

  • The test used simple 2-digit math (like 15 + 23).
  • GPT-4.1 had memorized so much math from its training that it didn't need to read the code; it just knew the answer to "15 + 23" from memory.
  • When the researchers made the math harder (using 6-digit numbers), GPT-4.1 suddenly failed in the middle of the text, just like all the other models.

The Big Takeaway

Current AI models are amazing at finding information (Lexical Recall) but are surprisingly bad at understanding complex instructions buried deep inside long documents (Semantic Recall).

If you deploy these AIs in the real world to fix bugs or analyze massive codebases, they might look at the middle of a file and miss critical details, thinking they understand the code when they are actually just guessing. We need better tests that force them to actually "read" and "think," rather than letting them take shortcuts.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →