Imagine you’re a senior engineer reviewing a pull request from an AI agent. The code looks clean, the syntax is perfect, and it passes the initial linter. You merge it. But a week later, that same code is causing strange production bugs—specifically, it’s trying to call methods that don't exist.
This is the "uncanny valley" of AI-generated code: it looks right, but it feels fundamentally fragile. In his research program, Musfiqur Rahman moves beyond just observing these quirks to asking the ultimate question: Why does the AI make these specific mistakes, and can we fix the "brain" of the model rather than just patching its output?
TL;DR
LLMs are transforming coding, but they produce "syntactically plausible" code that harbors deep structural defects, often failing 84% of the time on real-world tasks despite acing synthetic benchmarks. This research uses mechanistic interpretability—essentially "brain-mapping" the transformer—to identify the specific internal circuits responsible for these errors, paving the way for AI that repairs its own causal flaws rather than just masking symptoms.
What Problem Does This Paper Address?
We are currently in an era of "observation without explanation." We know LLMs are good at coding, but we don't know why they fail in such specific, repetitive ways.
Rahman identifies three major gaps:
- The Stability Gap: While industry rumors suggest AI code is "disposable" and quickly replaced, data shows it actually sticks around—but autonomous agent code requires significantly more corrective fixes than human code.
- The Evaluation Gap: LLMs that look like geniuses on synthetic benchmarks (scoring 85%+) turn out to be mediocre (scoring ~30%) when faced with complex, real-world class-level code.
- The Detection Gap: We can detect AI code, but our methods are inconsistent. Why is GPT-3.5 incredibly easy to spot (AUC-ROC 0.96) while newer models are stealthier, even when they use similar structures?
The core problem is that we treat LLMs as "black boxes." If we don't understand the causal reason for a hallucination, we can't build truly reliable software agents.
Methods
The research triangulates evidence across three layers:
- Longitudinal Analysis: Using survival analysis (Kaplan-Meier and Cox Proportional Hazards) to track how long AI-generated code survives in the wild across 156 open-source repositories.
- Empirical Benchmarking: Testing models on "unseen" real-world code to rule out memorization.
- Mechanistic Interpretability: This is the "neurosurgery" part. Rahman uses techniques like:
- Logit Lens: Watching how a specific word (token) "crystallizes" as it moves through the model's layers.
- Activation Patching: Swapping internal signals between a "clean" prompt and a "corrupted" one to see which specific circuit causes a mistake.
- Linear Probing: Training tiny classifiers to see if a model's internal state already "knows" it's about to generate a bug.
Datasets
The study introduces and utilizes several high-scale datasets:
- AIDev: 223,997 line-level units from 156 repositories to study code stability.
- RealClassEval: A new benchmark of 400 real-world Python classes, specifically designed to test models on code they haven't seen in their training data.
- OpenClassGen: A massive corpus of 324,843 real-world Python classes with 27 static metrics.
- SIEVE: A custom infrastructure for sourcing "contamination-free" data from GitHub, ensuring the models aren't just reciting code they've already memorized.
Key Insights and Ideas
- The "AttributeError" Paradox: LLMs almost never make syntax errors (they know the "grammar" of Python perfectly), yet they routinely hallucinate object attributes. This suggests that "syntactic knowledge" and "object knowledge" live in entirely different circuits in the model's brain.
- The GPT-3.5 Anomaly: GPT-3.5 is 27 percentage points more detectable than modern models. The research suggests this is due to extreme brevity and documentation sparsity—a "stylistic signature" that modern models have evolved away from.
- Granularity Dominance: Detecting AI at the "function" level is a completely different task than at the "class" level. The features that give away a single function don't work for a whole class, indicating that AI "style" changes depending on the scope of the task.
Key Results
- Autonomous Agent Fragility: Code from agents like Devin attracts corrective modifications 49.1% of the time, compared to 37.9% for humans. It looks stable syntactically, but it's structurally "rotten."
- The Performance Collapse: Models that hit 84–89% correctness on synthetic tasks drop to a mere 24–35% on real-world code.
- Semantic vs. Functional: As shown in Table 2, models achieve high semantic similarity (they "get" the gist) but fail miserably on functional correctness (the code doesn't actually run).
Limitations and Future Work
The author acknowledges that findings on small, open-source models (like Qwen or DeepSeek) might not perfectly translate to giant, proprietary "black boxes" like GPT-4. To mitigate this, the research triangulates across different model families.
The final "boss" of this thesis is Interpretability-Informed Agentic Repair. Instead of a model just guessing how to fix a bug, it will use these "circuit maps" to intervene at the causal source. If the model knows why it hallucinated a variable name, it can steer its own internal activations to produce the correct one.
Summary updated