Context Rot: Why Your AI Agent Gets Worse in Long Sessions
OpenRouter ·


In an AI agent, the session history fills with tool calls, file reads, and logs over dozens of turns, and the model gets worse at using what’s already in its window. Late in a long session, the model can lose count of how many times a test failed, even though the question it’s asked stays the same. Models now advertise 1M-token windows, so the question has moved from whether a session fits to whether the model still works once it does. We wanted to know where current models break down and whether there’s a cheap fix, so we ran the same long coding-agent session on five models from five labs through OpenRouter and tested two ways of shortening the history. If you only want the fix, skip to how to fix context rot with compaction.
Tl;dr
- Context rot means a model gets worse at using its prompt as the prompt grows, even well inside its context window.
- In our October 22, 2026 run on five 1M-context models, finding one fact, tracking a setting’s latest value, and following an early rule stayed at 100% up to about 900K tokens. Counting three failed test runs spread across the session fell from 67% correct at about 20K tokens to 40% at about 80K and 27% at about 600K.
- Dropping old turns to fit a smaller token budget cut accuracy at 2M characters from 49/60 to 9/60, and one run invented a ticket ID (SEC-8492) that appeared nowhere in the session.
- Chunked compaction with scaledown/summarize ($0.04 per million input tokens) raised accuracy at 2M characters from 49/60 to 54/60. The average prompt fell from 605K tokens to 112K, and the average request cost fell from $0.224 to $0.041.
What is context rot in AI?
Context rot is the drop in how well a language model uses the information in its prompt as the prompt gets longer, even when the whole prompt fits inside the context window. The window sets how many tokens a model can read in one request. It doesn’t promise that the model uses all of them equally well. Agents run into it because their prompts grow with every turn. The user’s first instructions and the early test failures end up under hundreds of thousands of tokens of tool output. Chroma’s research report on context rot measured the effect on earlier models with retrieval-style tasks. Current 1M-context models recalled single facts perfectly up to about 900K tokens, but accuracy dropped early on questions that required counting events across the whole session.
How we built the test
We generated a synthetic coding-agent session in the OpenAI chat format. Each session opens with a system prompt and a user task (“fix the flaky refund rounding test in src/orders and tidy up the ingest worker config”). Hundreds of tool calls and results follow, filled with TypeScript file reads, grep output, .env files, and test logs. We planted four facts in every session, each at a fixed point and each with one exact answer. The percentages show how far into the session each fact appears.
- Ticket ID. At 27%, the user gives the ticket OPS-4471 and mentions an unrelated OPS-4417. The answer is OPS-4471.
- Latest value. The ingest worker’s MAX_WORKERS starts at 4 and changes to 8, then 16, and finally 14 at 83%. At 66%, another service sets MAX_WORKERS=6 as a distractor. The answer is 14.
- Early rule. At 4%, the user says not to touch src/billing. We ask whether the agent may edit src/billing/invoice.ts. The answer is false.
- Count across the session. Three full test runs, at 18%, 45%, and 74%, each report one failing test, and every other run passes. We ask how many runs failed. The answer is 3. At the end of the session, the user asks all four questions and requests a JSON reply, which we scored by exact match. We built five session lengths (64K, 256K, 1M, 2M, and 3.2M characters) with three random seeds each. Then we sent the same sessions to five models, each with a window of about 1M tokens and reasoning.effort: “low”:
- anthropic/claude-haiku-5.5
- openai/gpt-6-luna
- google/gemini-3.8-flash
- deepseek/deepseek-v4.1-flash
- minimax/minimax-m3.1-flash With three sessions per model per length, the samples are small, so read the results as a direction rather than as precise rates. The same text turns into a different number of tokens on each tokenizer. Claude Haiku 5.5 counted about 1.5 times as many tokens as GPT-6 Luna for the same session. | Session length | Claude Haiku 5.5 | GPT-6 Luna | Gemini 3.8 Flash | DeepSeek V4.1 Flash | MiniMax M3.1 Flash | | --- | --- | --- | --- | --- | --- | | 64K chars | 27K | 17K | 20K | 19K | 18K | | 256K chars | 105K | 67K | 78K | 74K | 70K | | 1M chars | 405K | 260K | 299K | 286K | 270K | | 2M chars | 806K | 518K | 596K | 571K | 537K | | 3.2M chars | Too long (1.28M to 1.29M) | 828K | Not run | 913K | 859K |
At 3.2M characters, Claude Haiku 5.5 rejected the request with a 400 error (prompt is too long: 1294690 tokens > 1000000 maximum). We didn’t run Gemini 3.8 Flash at that length.
Results by question type
The results split by question type. Each cell counts correct answers out of 15 (five models × three seeds), or out of 9 at 3.2M characters, where only three models ran.
| Question | 64K chars (~20K tokens) | 256K (~80K) | 1M (~300K) | 2M (~600K) | 3.2M (~870K) |
|---|---|---|---|---|---|
| Ticket ID, latest MAX_WORKERS, and early billing rule (each) | 15/15 | 15/15 | 15/15 | 15/15 | 9/9 |
| Count of failed test runs | 10/15 | 6/15 | 5/15 | 4/15 | 4/9 |
The three single-fact questions were right every time, at every length. Only the count fell, from 67% correct at about 20K tokens to 40% at about 80K and 27% at about 600K. At 3.2M characters it scored 4/9, but nine answers from three models are too few to read as a recovery. Most wrong answers at long lengths were 2, which means the model missed one of the three failures. At short lengths, most wrong answers were 4. A needle-in-a-haystack test on its own would say long context is fine on these models. Agents, though, often need answers that depend on the whole session, such as how often a test has failed or which files they’ve already touched. That’s the kind of question that rotted. Scores fell for four of the five models. MiniMax M3.1 Flash stayed at 10 or 11 out of 12 at every length. Here are the correct answers per model, out of 12 (four questions across three sessions):
| Model | 64K chars | 256K | 1M | 2M | 3.2M |
|---|---|---|---|---|---|
| anthropic/claude-haiku-5.5 | 12 | 11 | 9 | 10 | Too long |
| openai/gpt-6-luna | 11 | 11 | 11 | 10 | 10 |
| google/gemini-3.8-flash | 10 | 9 | 9 | 9 | Not run |
| deepseek/deepseek-v4.1-flash | 12 | 9 | 11 | 10 | 11 |
| minimax/minimax-m3.1-flash | 10 | 11 | 10 | 10 | 10 |
At 2M characters, every model scored 9 or 10 out of 12, and every missed point was on the count question.
Why do long sessions cost more?
An agent resends the whole history on every turn, so a long prompt costs you on every step, not once. Here’s the average cost and time of one request (the final question) on October 22, 2026:
| Model | 64K chars | 1M chars | 2M chars |
|---|---|---|---|
| anthropic/claude-haiku-5.5 | $0.0038, 14 s | $0.206, 15 s | $0.404, 22 s |
| openai/gpt-6-luna | $0.0015, 2 s | $0.033, 9 s | $0.130, 15 s |
| google/gemini-3.8-flash | $0.0155, 21 s | $0.225, 12 s | $0.447, 32 s |
| deepseek/deepseek-v4.1-flash | $0.0016, 3 s | $0.030, 9 s | $0.058, 17 s |
| minimax/minimax-m3.1-flash | $0.0020, 8 s | $0.041, 12 s | $0.081, 17 s |
At 2M characters, one request on Claude Haiku 5.5 or Gemini 3.8 Flash cost $0.40 to $0.45, so ten more turns at that size add about $4. Some models also charge more per token once a prompt is long. On every provider listed for Claude Haiku 5.5 in our endpoints API on October 22, 2026, it cost $0.10 input and 0.50 input and $2.50 output) above 100,000. That’s why its request at 1M characters cost about 54 times its request at 64K, even though the prompt was only 15 times longer. Prompt caching lowers the cost of resending an unchanged prefix, but the model still reads the full history, so caching doesn’t help with context rot.
Why dropping old messages makes it worse
The obvious way to shrink a prompt is to drop the oldest turns. That also deletes the facts, edits, and failures the agent recorded early in the session. We tested this at 2M characters (about 520K to 810K tokens). We kept the system prompt, the first user message, and only the most recent ~120K characters of history (about 31K to 48K tokens). Across the five models and three seeds, accuracy fell from 49/60 with the full history to 9/60. Truncation lost the ticket ID, the latest MAX_WORKERS value, and every failed test run (0/15 each). The billing rule scored 9/15, but only because the models answered false without ever seeing the rule. Several answers came back null, and one run invented a ticket, SEC-8492, that appears nowhere in the session.
How to fix context rot with compaction
Compaction replaces the older turns with a summary and keeps the recent ones word for word. Done in chunks, it kept every planted single fact in our test and cut prompt tokens by about four fifths.
We followed our cookbook on compacting long agent sessions with ScaleDown Summarize and compacted each 2M-character session in four steps:
- Keep the system prompt and the last 8 messages as they are. Move the cut back if needed, so the kept messages never start with a tool result whose call was summarized away.
- Render the older messages as text and split them into chunks of about 16,000 characters.
- Summarize the chunks in parallel with scaledown/summarize. Tell it to keep the goal, decisions, files, commands, failures, and confirmed facts, and to copy IDs, paths, and numbers exactly.
- Join the chunk summaries into one message and place it right after the system prompt, before the last 8 messages. Here’s how the full history, truncation, and compaction compared at 2M characters: | History sent | Correct (5 models × 3 sessions × 4 questions) | Count question | Avg prompt tokens | Avg cost per request | Avg time | | --- | --- | --- | --- | --- | --- | | Full | 49/60 | 4/15 | 605K | $0.224 | 20.4 s | | Truncated to recent turns | 9/60 | 0/15 | 36K | $0.009 | 5.6 s | | Compacted | 54/60 | 9/15 | 112K | $0.041 | 6.5 s |
Compaction kept the ticket ID, the latest MAX_WORKERS value, and the billing rule every time (15/15 each). It also raised the failed-run count from 4/15 to 9/15, and every wrong count after compaction was 2. Four of the five models scored the same or better. Claude Haiku 5.5 and DeepSeek V4.1 Flash rose from 10 to 12 out of 12, while GPT-6 Luna went from 10 to 9. Cost per request fell on every model, from $0.404 to $0.076 on Claude Haiku 5.5 and from $0.130 to $0.012 on GPT-6 Luna. The compaction itself is cheap. One 2M-character session took 124 to 128 calls to scaledown/summarize, which cost $0.04 per million input tokens and nothing for output in our catalog on October 22, 2026. Each session cost $0.023 to compact and took 88 to 124 seconds with 8 calls in parallel. The summary came to 273K to 341K characters, about a sixth of the original. You pay that once per compaction, and every later turn sends the smaller history.
How to keep an agent working in long sessions
Compact early. In our test, the count question was already down to 40% at about 80K tokens (256K characters), far below any model’s limit. Trigger compaction on a token threshold in your agent loop rather than waiting for a context-length error. Keep the facts the agent must not lose, such as user rules and current settings, in the system prompt or in a running state note that survives every compaction. Track counts in state. Compaction raised the count question to 9/15, not 15/15. If your agent needs answers that depend on the whole session, such as a running tally of failed runs or a list of edited files, keep them in state instead of asking the model to rebuild them from the history. Use the context-compression plugin for overflow, not for rot. We also offer a context-compression plugin (plugins: [{“id”: “context-compression”}]), documented in the message transforms guide. It removes or truncates messages from the middle of a prompt until it fits the model’s window, which suits cases where exact recall isn’t required. It only acts when a prompt is longer than the window, so it doesn’t fix context rot inside the window.
Next steps
Add chunked compaction to your agent loop before the history gets long. The Compact Long Agent Sessions with ScaleDown Summarize cookbook has the TypeScript recipe. It covers splitting on tool boundaries, carrying the summary forward across compactions, folding it when it grows, and keeping the history unchanged if a summarize call fails. You can also check the scaledown/summarizemodel page or browse long-context models on the models page.
Frequently asked questions
What happens when the context window is full?
When a prompt is longer than a model’s maximum context length, the request fails with a 400 error. In our test, Claude Haiku 5.5 returned prompt is too long: 1294690 tokens > 1000000 maximum at 3.2M characters. To avoid it, compact old turns in chunks with scaledown/summarize, or turn on the context-compression plugin in message transforms when exact recall doesn’t matter.
How big is a 200K context window?
It depends on the model’s tokenizer. In our coding-agent session, 200K tokens held roughly 490K characters of code and logs on Claude Haiku 5.5 and about 770K characters on GPT-6 Luna.
How do I reset the context window?
Chat completion requests are stateless, so the model only sees the messages you send. To reset the window, send a shorter messages array on the next turn. In an agent loop, replace the older turns with a chunked summary message after the system prompt and keep the last 8 messages unchanged.
What is context collapse?
Context collapse is when repeatedly rewriting a context into a shorter version erodes its details over time. The term comes from the Agentic Context Engineering paper by researchers at Stanford, SambaNova, and other institutions. It’s a risk with compaction too, because each pass summarizes the one before it. In our test, telling the summarizer to copy IDs, paths, and numbers exactly kept the ticket ID, the latest value, and the billing rule through one round of compaction.