Context Rot: Managing the Attention Budget in Million-Token Windows
As context windows grow to a million tokens, coding assistants often get worse rather than better over long sessions. This article explains context rot, why performance degrades gradually instead of failing outright, and how a limited attention budget makes longer context costly. It offers practical governance techniques—structured input, rolling summarization, retrieval augmentation, and context isolation—plus a sample strategy function and metrics for making degradation observable.
1. The Symptom: A Bigger Window Does Not Guarantee a Better Experience
As long-context capabilities advance quickly, the context windows of AI coding tools have reached the million-token scale. In Chinese, that is roughly 600,000 to 700,000 characters, close to the length of three full-length novels. Many people’s first reaction is: finally, we can dump all the material in at once.
In engineering practice, however, the opposite feeling keeps recurring. After dozens of turns, the model starts to miss earlier agreements, repeats problems that have already been fixed, or mixes concerns across multiple tasks. The industry calls this phenomenon context rot.
It is important to emphasize that this is not a broken feature waiting to be patched. It is more like gravity: as long as the session continues, it will inevitably happen.
2. Definition: Performance Slides Down, It Does Not Fall Off a Cliff
A widely accepted description is this: as the context grows, attention is spread across more and more tokens. Earlier, task-irrelevant content begins to interfere with judgment, and model performance degrades accordingly.
The most important distinction here is degradation rather than collapse. A collapse is noticed immediately; a degradation is not. It shows up as a gentle slope:
- Declining instruction following: output formats and naming conventions set early are ignored.
- Weaker associative ability: contradictions that only surface when three or more files must be referenced together get missed.
- Decision drift: the same question receives inconsistent answers across different turns.
- Increased redundancy: the same content is read repeatedly, and the same background is explained repeatedly.
Because the slope is gentle, teams often attribute the problem to the model “not being smart enough,” when the real cause is the absence of a context management strategy.
3. Mechanism: The Attention Budget Is a Hard Constraint
A fitting analogy is that human working memory has limited capacity, and a model faces a similarly limited “attention budget” when processing large amounts of context.
A bigger desk does not mean you can spread out more things and still find what you need. Every extra stack of paper adds a few seconds to finding an old notebook. The longer the context, the more each token takes a slice of the budget, and the more irrelevant content there is, the more the useful signal is diluted.
Three engineering conclusions follow from this:
- Context is not free. It has a hidden cost, and that cost rises non-linearly with length.
- Relevance matters more than completeness. Filling the window does not mean the information is sufficient.
- Context needs to be governed, not piled up indefinitely.
4. Decision: When to Compress, When to Retrieve, When to Start a New Session
What a million-token window truly changes is that every turn adds one more decision: is this history still worth carrying forward?
A simple strategy function can express this decision:
def should_compress(ctx):# Budget watermark: the higher the usage, the more governance is neededif ctx.token_usage / ctx.window_size > 0.6:return True# Task switch: after the goal changes, the marginal value of old history decays quicklyif ctx.task_changed and ctx.stale_turns > 3:return True# Signal density: the share of useful information in new content is too lowif ctx.recent_signal_ratio < 0.3:return Truereturn False
Thresholds should be tuned based on real measurements in your own workload. The point is to turn “compress / retrieve / restart” from intuition into observable, measurable rules.
5. Practice: Four Actionable Governance Techniques
Structured input. Split long documents into fragments with heading levels, and attach stable paragraph numbers so the model can precisely reference “section X, item Y” instead of searching vaguely within one large block of text.
Segmented summarization and rolling compression. After each stage is completed, fold the history into a structured summary: the goal, confirmed conclusions, pending tasks, and rejected options. Rejected items should be kept in particular; otherwise the model will repeatedly propose the same wrong direction.
Retrieval augmentation. Put large repositories and large documents into a vector or keyword retrieval pipeline, and inject only a few task-relevant fragments per turn, trading relevance for attention budget.
Context isolation. Open a new session for an independent subtask and pass along only the necessary conclusion-level summary. This is one of the most effective ways to counter degradation, because it directly resets budget consumption.
An illustrative session state:
{"goal": "Add unit tests for the order module","confirmed": ["Use a unified assertion library", "Coverage target of 80%"],"rejected": ["Introduce an additional mocking framework"],"next_actions": ["Fill in boundary cases", "Wire up pipeline checks"]}
6. Measurement: Making Degradation Observable
Governance starts with visibility. It is advisable to collect at least four metrics: context usage watermark, useful information gain per turn, instruction-following failure rate, and the number of repeated efforts. Combined with logging services and monitoring alerts to build a trend dashboard, degradation turns from “it feels dumber” into a curve you can locate and act on.
7. Conclusion
A million-token window solves “can it fit,” not “is it used well.” Fitting is a capacity problem; using it well is an attention allocation problem. Understanding the gravity-like nature of context rot and treating the budget as a finite resource to be managed is what turns long-context capability into stable output. For teams that want to build such a governance pipeline with Baidu AI Cloud engineering capabilities, starting with structured input and observable metrics is the lowest-cost entry point.
