False Proximity: Frozen Code Embeddings Invert Similarity on Behaviourally Divergent Mutant Pairs
This paper demonstrates that frozen CodeBERT embeddings systematically invert similarity signals for behaviorally divergent mutant pairs, incorrectly scoring them as more similar than genuinely equivalent code, thereby revealing that such embeddings reflect surface proximity rather than behavioral equivalence and necessitate contrastive fine-tuning or execution-based verification for reliable code analysis.
Original paper licensed under CC BY 4.0 (https://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
In the vast landscape of modern software, programs are often treated as if they speak a language that computers can instantly understand and compare. To make sense of this complexity, researchers have developed tools that translate lines of code into mathematical points in a high-dimensional space. Imagine these points as locations on a map; if two pieces of code are similar in what they do, their points should sit close together. This method, known as embedding, has become a standard way to search for code, find duplicate programs, or predict errors without running the software. The most popular tools for this task rely on models trained on massive amounts of text and code, learning to recognize patterns in how words and symbols are arranged. The prevailing assumption has been that if two programs look very similar on the surface—sharing the same words and structure—they must be doing the same thing. This belief underpins many automated systems that help developers manage their code, but it rests on a fragile intuition: that visual similarity always equals functional similarity.
A team of researchers set out to test this intuition with a rigorous experiment, asking a simple but dangerous question: what happens when two programs look almost identical but do the exact opposite? They constructed a controlled environment using thousands of real-world programming problems. From a collection of 800 distinct challenges, they gathered pairs of code that were known to be correct and functionally equivalent, meaning they solved the problem in the same way. Then, they created a second set of pairs by taking a correct program and making a tiny, single change to it—flipping a condition from "yes" to "no," swapping a "greater than" sign for a "less than" sign, or reversing the order of a list. These changes were small enough that the code looked nearly the same, but they were severe enough to make the program fail every single test case it was run against. The researchers then fed both sets of pairs into the standard code-comparison tools to see if the tools could tell the difference between a correct program and its broken, inverted twin.
The results were not just a failure to distinguish; they were a complete reversal of reality. When the tools compared the broken, inverted programs to their original versions, they rated them as more similar than they rated two completely different, independently written correct solutions to each other. In fact, the tools were wrong in more than nine out of ten comparisons. The mathematical score that was supposed to measure how well two programs matched was actually measuring how much they looked alike on the surface. Because the broken programs shared almost every word and line with the original, the tools saw them as perfect matches, completely missing the fact that their behavior was diametrically opposed. This phenomenon occurred consistently across different types of code changes and different versions of the comparison tools, suggesting that the problem is not a minor glitch but a fundamental flaw in how these models interpret code when they are not specifically trained to look for behavioral differences.
The researchers then investigated whether this error could be fixed by simple, low-cost adjustments that do not require retraining the massive models. They tried mathematical tricks designed to spread the code points out more evenly in their space, hoping this would make the differences more visible. They also tried combining the code comparison with a structural analysis that counts how many lines of the code tree are different. None of these methods worked. In fact, adding the structural analysis made the problem worse. Because the broken programs were structurally almost identical to the originals—differing by only a single line—the structural tool gave them a high similarity score, reinforcing the error rather than correcting it. The tools were so focused on the surface appearance of the code that they could not see the functional inversion, even when the researchers explicitly tried to force them to look deeper.
This study reveals a critical blind spot in the technology that powers modern code search and duplicate detection. The tools are excellent at finding code that looks the same, but they are dangerously misleading when asked to judge whether two pieces of code do the same thing, especially when one is a subtle, broken version of the other. The researchers found that for these specific types of errors, the standard approach of using frozen, pre-trained models is not just imprecise; it is inverted. To reliably tell the difference between a correct function and its behavioral opposite, developers cannot rely on these similarity scores alone. Instead, they must either retrain the models with specific examples of these errors or, more reliably, actually run the code to see what it does. The study concludes that until these changes are made, systems relying on these similarity scores will continue to mistake a broken program for a perfect match, potentially hiding critical bugs in plain sight.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.