You just upgraded to the latest coding agent, hyped by the promise of 200,000 or 1,000,000 token context windows. In a fit of engineer efficiency, you dump your entire repository into a single text file, attach 500 lines of error logs, and hit Enter, assuming the AI will now understand your project like a Staff Engineer. Fifteen minutes later, the agent is modifying legacy files from three quarters ago, calling non-existent utility functions, and ignoring your explicit instruction not to touch the database schema. Welcome to Context Rot.
The Myth of the Infinite Context
For years, AI labs touted context window size using the Needle in a Haystack (NIAH) test, hiding a random fact in massive amounts of noise to see if the model could retrieve it. Frontier models scored near-perfectly, creating a false sense of security that LLMs handle long contexts flawlessly. However, a July 2025 report by Chroma Research, titled Context Rot: How Increasing Input Tokens Impacts LLM Performance, shattered this illusion. By testing 18 leading LLMs (including GPT, Claude, Gemini, and Qwen) across 195,000 API calls, researchers found that accuracy degrades consistently as input tokens increase, long before the hard context limit is reached.
Why Soft Failures Are Dangerous
The most insidious aspect of Context Rot is the Soft Failure. Unlike a token overflow error (HTTP 400), which clearly tells you to cut your input, Context Rot is silent. The model consumes hundreds of thousands of tokens, reports no errors, and returns confidently wrong code. This happens because NIAH tests rely on lexical matching—finding a specific string like Password is 42. Real-world coding requires multi-hop semantic reasoning: linking an interface in File A to business logic in File B while avoiding side effects in File C. As context bloats, this reasoning capacity collapses.
Attention Dilution and the Lost Middle
Three technical mechanisms drive this degradation. First, Attention Dilution: Self-Attention mechanisms must calculate relevance between every token pair. When you flood the context with webpack configs and old migrations, the attention weights spread thin, diluting the signal like dropping an espresso shot into a swimming pool. Second, the Lost in the Middle effect, documented by Nelson F. Liu et al. (TACL 2024), shows a U-shaped performance curve. Models remember the start (primacy) and end (recency) of a prompt but fail to retrieve information buried in the middle 30-70% of the context. In multi-document tests, placing the answer in the middle reduced accuracy to levels lower than closed-book answering.
Distractor Pollution and Context Poisoning
Chroma’s research also highlights Distractor Pollution, where coherent but irrelevant text confuses the model more than random noise. In a real repo, this means deprecated files like auth_v1.ts sitting next to auth_v2.ts, or mock data using identical function names to production code. Worse is Context Poisoning during long debug sessions. If an agent fails three times in a row, the chat history fills with wrong hypotheses and failed diffs. By the fifth attempt, the agent is fighting its own bad history, unable to distinguish current truth from past mistakes. Common symptoms include the Regression Loop (fixing bug A breaks feature B repeatedly), Internal Hallucination (inventing methods that don't exist in the provided code), and forgetting explicit instructions after 12+ turns.
Strategies to Stop the Rot
To combat this, stop Repo Dumping. Use targeted retrieval: run rg or grep to find specific symbols and call sites before feeding them to the agent. Filter your logs; use tail -n 60 or --tb=short to strip verbose build noise. Implement a Clean-Room Restart strategy. If a session gets poisoned, don’t argue with the agent. Create a structured handoff summary with the goal, relevant files, and excluded paths, then start a new chat. This resets the context window and removes the regression loop. Additionally, arrange your prompt according to the U-curve: put critical constraints at the start (Primacy Zone) and the immediate task at the end (Recency Zone). For large features, use external memory by having a subagent write a plan.md file, then execute in a fresh session to keep the context window light.
Key Takeaways
- Context Rot causes silent soft failures where accuracy drops as input length increases, well before hitting the hard token limit.
- The Lost in the Middle effect means models struggle to retrieve information placed in the middle 30-70% of a long prompt.
- Effective mitigation requires targeted retrieval (using tools like rg), clean-room restarts via structured handoffs, and strict codebase hygiene to remove distractors.
- Large context windows are not magic; they are like a larger desk. If you pile old invoices and junk on it, processing speed and accuracy still suffer.
The Bottom Line
Stop treating context windows as infinite storage bins. Mastering Context Engineering—curating signal over noise and resetting poisoned sessions—is the only way to keep your coding agent sharp.