

Context Rot: Why Your AI Agent Gets Worse in Long Sessions
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 |


































































