CodeCrash: Exposing LLM Fragility to Misleading Natural Language in Code Reasoning

Man Ho Lam, Chaozheng Wang, Jen-tse Huang, Michael Lyu

TL;DR

The CodeCrash benchmark reveals that Large Language Models (LLMs) are surprisingly fragile when code logic is paired with misleading natural language comments. Even advanced reasoning models can suffer from "Reasoning Collapse"—a state of pathological overthinking and "cognitive dissonance" where the model hallucinates for thousands of tokens trying to reconcile a plausible lie with the actual code.

What Problem Does This Paper Address?

While LLMs are increasingly capable of writing and explaining code, it remains unclear whether they truly "reason" through execution logic or merely act as sophisticated pattern matchers. Real-world codebases are messy, often containing outdated comments, misleading variable names, and dead code.

Existing benchmarks typically present "clean" code, failing to test a model's ability to prioritize executable semantics over distracting text. The authors of CodeCrash set out to determine if LLMs can maintain their reasoning integrity when the natural language (NL) context—such as a comment stating # This function returns 0—explicitly contradicts the actual code execution.

Methods: The CodeCrash Framework

To evaluate this, the authors developed a stress-testing framework that applies three distinct types of functionally equivalent perturbations to existing code samples:

Overview of CodeCrash Perturbations
  1. Aggregated Structural Perturbations (PSC-ALL): Modifies the "skeleton" of the code without changing its output. This includes renaming variables to unintelligible strings, reformatting conditional logic, and injecting "garbage code" like dead loops or unexecutable segments.
  2. Contextual-Level Misleading (MCC & MPS): Injects shallow, obviously incorrect NL cues via comments (#) or print statements. For example, a comment might claim a loop is skipped when it clearly isn't.
  3. Reasoning-Level Misleading (MHC): The most deceptive tier. The authors used GPT-4o to generate plausible but incorrect hints about the program's output, strategically injecting them as comments to see if the model would rationalize the error.

The study evaluated 17 different LLMs (including the GPT, Claude, LLaMA, and Qwen families) and 3 "Large Reasoning Models" (LRMs) like OpenAI’s o3-mini and DeepSeek-R1.

Datasets

The CODECRASH benchmark consists of 1,279 questions derived from two primary sources:

  • CRUXEVAL: 800 synthetic Python snippets focused on basic logic.
  • LIVECODEBENCH (LCB): 479 real-world, complex coding problems sourced from LeetCode.

The authors also translated the LCB problems into JavaScript to ensure their findings weren't just an artifact of Python's specific syntax.

Key Insights: The "Rationalization" Trap and Reasoning Collapse

When faced with a misleading hint, models don't just get the answer wrong; they often perform "post-hoc rationalization." They will correctly trace the code execution for several steps, but then suddenly flip their conclusion at the very end to align with the misleading comment.

Stages of Reasoning Collapse
  • Reasoning Collapse: This is the paper's most striking discovery. Advanced "Reasoning Models" (LRMs) are trained to be cautious and self-reflective. When they encounter a plausible hint that contradicts their internal logic, they can enter a loop of catastrophic cognitive dissonance.
  • The "Hmm" Loop: In a case study of QwQ-32B, the model spent 20,000 tokens reasoning correctly, hit a misleading comment, and then spent the next 12,000 tokens repeating words like "Hmm" and "wait" in a quadratic growth of confusion before ultimately failing.
  • Shortcut Reasoning: Models frequently use NL cues as shortcuts. If a comment says a variable is for debugging only, the model might ignore it entirely, even if that variable is actually critical to the final result.

Key Results

  • Performance Degradation: On average, models saw a 23.2% drop in accuracy under direct inference when perturbations were introduced.
  • CoT is a Partial Shield: Chain-of-Thought (CoT) reasoning reduced the degradation to 13.8%, but it couldn't eliminate the distractibility caused by misleading comments.
  • MHC is the Killer: Plausible hints (MHC) caused the most significant damage, particularly on complex real-world problems (LCB), where models were more likely to trust the hint over their own struggling logic.
  • Scaling Doesn't Solve It: While larger models (like GPT-4o and Claude 3.5 Sonnet) are more robust than smaller ones, they still exhibit the same fundamental tendency to rationalize incorrect NL cues.

Limitations and Future Work

The authors acknowledge several constraints in their study:

  • Language Scope: The study primarily focuses on Python and JavaScript; results might differ for declarative languages like Prolog or low-level Assembly.
  • Model Selection: Due to budget and timing, the very latest models (like GPT-4.5 or Claude 3.7) were not included.
  • Lack of Mitigations: The paper serves as a diagnostic tool rather than a cure. It identifies how models fail but doesn't offer a definitive training or prompting strategy to fix this fragility.

Future research should focus on making models "reason-faithful"—ensuring that their internal logic is prioritized over external, potentially adversarial, natural language context.

Summary updated

BibTeX
@inproceedings{lam2025codecrash,
  author = {Man Ho LAM and Chaozheng Wang and Jen-tse Huang and Michael Lyu},
  title = {{CodeCrash: Exposing LLM Fragility to Misleading Natural Language in Code Reasoning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=CAB0EjD9EK},
}
Figure