Robustness and Reasoning Fidelity of Large Language Models in Long-Context Code Question Answering
Organizations: IBM Research
Abstract
Large language models (LLMs) increasingly assist software engineering tasks that require reasoning over long code contexts, yet their robustness under varying input conditions remains unclear. We conduct a systematic study of long-context code question answering using controlled ablations that test sensitivity to answer format, distractors, and context scale. Extending LongCodeBench Python dataset with new COBOL and Java question-answer sets, we evaluate state-of-the-art models under three settings: (i) shuffled multiple-choice options, (ii) open-ended questions and (iii) needle-in-a-haystack contexts containing relevant and adversarially irrelevant information. Results show substantial performance drops in both shuffled multiple-choice options and open-ended questions, and brittle behavior in the presence of irrelevant cues. Our findings highlight limitations of current long-context evaluations and provide a broader benchmark for assessing code reasoning in both legacy and modern systems.
Figures & tables
| Model | Method | 32k | 64k | 128k | 256k | 512k |
|---|---|---|---|---|---|---|
| Mistral-Small-24B | With Options | 64.6% | 71.1% | - | - | - |
| Mistral-Small-24B | Without Options | 45.1% | 36.8% | - | - | - |
| Gemini-2.5-Flash | With Options | 74.3% | 68.4% | 72.8% | 66.2% | 68.1% |
| Gemini-2.5-Flash | Without Options | 47.8% | 51.3% | 54.3% | 49.2% | 40.4% |
| GPT-4o | With Options | 61.9% | 72.4% | 72.5% | - | - |
| GPT-4o | Without Options | 45.1% | 50.0% | 41.7% | - | - |
| Model | Method | 32k | 64k | 128k | 256k | 512k |
|---|---|---|---|---|---|---|
| Mistral-Small-24B | With Options | 95.1% | 90.7% | 95.7% | - | - |
| Mistral-Small-24B | Without Options | 55.7% | 50.0% | 47.1% | - | - |
| Gemini-2.5-Flash | With Options | 98.4% | 92.6% | 98.6% | 91.1% | 94.0% |
| Gemini-2.5-Flash | Without Options | 67.2% | 68.5% | 54.3% | 69.6% | 38.0% |
| GPT-4o | With Options | 96.7% | 92.6% | 87.1% | - | - |
| GPT-4o | Without Options | 49.2% | 57.4% | 50.0% | - | - |
| Model | Method | 32k | 64k | 128k | 256k | 512k |
|---|---|---|---|---|---|---|
| Mistral-Small-24B | With Options | 73.1% | 68.9% | - | - | - |
| Mistral-Small-24B | Without Options | 46.2% | 35.6% | - | - | - |
| Gemini-2.5-Flash | With Options | 76.9% | 77.8% | 88.0% | 85.7% | 90.9% |
| Gemini-2.5-Flash | Without Options | 50.0% | 42.2% | 38.7% | 52.1% | 50.3% |
| GPT-4o | With Options | 80.8% | 82.2% | 85.3% | - | - |
| GPT-4o | Without Options | 38.5% | 51.1% | 54.7% | - | - |
| Model | Method | 32k | 64k | 128k | 256k | 512k | 1024k |
|---|---|---|---|---|---|---|---|
| Qwen2.5-72B | With Options | 83.3% | - | - | - | - | - |
| Qwen2.5-72B | Without Options | 78.1% | - | - | - | - | - |
| GPT-4o | With Options | 81.6% | 89.5% | 82.5% | - | - | - |
| GPT-4o | Without Options | 77.2% | 74.6% | 78.1% | - | - | - |
| Llama-3.3-70B | With Options | 89.5% | 85.1% | 65.8% | - | - | - |
| Llama-3.3-70B | Without Options | 57.9% | 59.5% | 59.6% | - | - | - |
| Model | Method | 32k | 64k | 128k | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Start | Middle | End | Start | Middle | End | Start | Middle | End | ||
| Language: Java | ||||||||||
| Llama-3.1-405B | With Options | 87.72% | 85.96% | 85.96% | 83.33% | 85.09% | 85.09% | 73.68% | 79.82% | 83.33% |
| Without Options | 62.28% | 62.28% | 65.79% | 60.53% | 62.28% | 63.16% | 52.63% | 58.77% | 64.04% | |
| Granite-4-8B | With Options | 77.19% | 82.46% | 84.21% | 69.30% | 72.81% | 79.82% | 71.05% | 76.32% | 78.07% |
| Without Options | 57.02% | 58.77% | 64.91% | 42.98% | 54.39% | 56.14% | 39.47% | 53.51% | 64.04% | |
| Model | Method | 32k | 64k | 128k | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Start | Middle | End | Start | Middle | End | Start | Middle | End | ||
| Language: Java | ||||||||||
| Llama-3.1-405B | With Options | 86.84% | 86.84% | 86.84% | 84.21% | 80.70% | 78.07% | 76.32% | 78.07% | 77.19% |
| Without Options | 66.67% | 64.04% | 63.16% | 59.65% | 59.65% | 57.89% | 54.39% | 50.00% | 49.12% | |
| Granite-4-8B | With Options | 75.44% | 71.05% | 75.44% | 70.18% | 69.30% | 74.56% | 71.93% | 71.05% | 72.81% |
| Without Options | 59.65% | 56.14% | 57.89% | 45.61% | 46.49% | 51.33% | 47.37% | 42.98% | 39.47% | |
Long-Context Language Model Evaluation
Long-context language model evaluation measures how reliably models find, reason over, and use information across extended inputs.
See all 66 papers