OpenRouter Finds Context Rot in Million-Token Coding Agents—and a Cheaper Fix
Summary:OpenRouter evaluated five models with roughly 1M-token windows using identical synthetic coding-agent sessions. Single-fact recall, latest-value tracking, and early-rule compliance stayed at 100% to roughly 900K tokens, but counting three failed test runs fell from 67% near 20K tokens to 40% at 80K and 27% at 600K. The results separate context capacity from usable context: the window can accept the transcript while the model still fails to aggregate evidence across it. Naively dropping old turn
OpenRouter tested five models with identical synthetic coding-agent sessions and found that performance can degrade before a transcript reaches the advertised context limit. Chunked summarization increased aggregate accuracy at 2M characters from 49/60 to 54/60 while reducing the average prompt from 605K tokens to 112K.
Key findings
- Single-fact retrieval, latest-value tracking, and compliance with an early instruction remained at 100% to roughly 900K tokens. The models did not simply become uniformly less capable as context grew.
- Counting three failed test runs degraded much earlier: accuracy fell from 67% near 20K tokens to 40% at 80K and 27% at 600K. Finding a record was substantially easier than aggregating records across the transcript.
- Naively dropping old turns was the most destructive intervention. At 2M characters, accuracy collapsed from 49/60 with full history to 9/60, and one response fabricated a ticket ID,
SEC-8492, that appeared nowhere in the session. - Chunked compaction through
scaledown/summarizeraised the score to 54/60. Average prompts fell from 605K to 112K tokens, a reduction of about 81.5%, while average request cost dropped from $0.224 to $0.041, or about 81.7%. The compaction service was listed at $0.04 per million input tokens.
How the test was constructed
OpenRouter generated synthetic coding-agent sessions in OpenAI Chat format. Each session began with a system prompt and a task involving a flaky refund-rounding test and an ingest worker configuration. Hundreds of tool calls and results followed, including TypeScript file reads, grep output, environment files, and test logs.
Four facts with unique answers were planted at fixed positions:
- A target ticket ID was placed near a similar distractor to test precise retrieval.
- A worker setting was updated several times, with another service using the same variable name, to test whether the latest value superseded earlier values.
- An early instruction prohibited edits to a billing directory, testing long-range constraint retention.
- Three test runs failed at different points in the session, testing whether the model could count events rather than merely locate one of them.
The sessions ranged from 64K to 3.2M characters. Each model received only three random seeds at each length. The route identifiers recorded in the article were anthropic/claude-haiku-5.5, openai/gpt-6-luna, google/gemini-3.8-flash, deepseek/deepseek-v4.1-flash, and minimax/minimax-m3.1-flash, all run with a low reasoning.effort. Final answers were scored by exact JSON match, meaning formatting deviations also counted as failures.
Character counts are not interchangeable with token budgets. At 2M characters, the same session ranged from roughly 518K to 806K tokens depending on the tokenizer. The article reports that Claude Haiku 5.5 counted about 1.5 times as many tokens as GPT-6 Luna for the same text. A character-based context threshold therefore assigns radically different attention and cache loads to different models.
Why fitting in the window is not the same as using it
A context window specifies how much material can be submitted in one request. It does not guarantee uniform access quality across that material. Because the main degradation occurred within the advertised limits, the experiment is closer to a usable-context problem than an overflow or straightforward positional-extrapolation failure.
Three mechanisms can contribute:
- Attention competition and interference: Tool logs, file contents, and repeated test output consume large portions of the context, reducing the relative signal of the facts that matter. A model may still locate one record but become more susceptible to nearby or repeated distractors.
- An asymmetry between retrieval and aggregation: Finding a ticket ID is a local match. Counting three failed runs requires recognizing event boundaries, excluding successful runs, and maintaining a count across turns.
- Declining signal density: Agent histories contain repetitive logs and tool output. As nominal context grows, constraints, changes, and failure evidence may occupy a smaller share of the prompt.
Long prompts also impose direct compute and cache costs. For standard dense self-attention, full prefill compute scales approximately as O(N²d). FlashAttention reduces intermediate-memory traffic and I/O pressure, but it does not remove the quadratic arithmetic. KV-cache memory is approximately 2 × L × H_kv × d_h × N × b bytes, where L is the number of layers, H_kv is the number of KV heads, d_h is the head dimension, N is the token count, and b is the element size in bytes. GQA reduces H_kv, but million-token sessions still increase memory bandwidth, time to first token, and concurrent scheduling pressure.
The reported results are therefore consistent with reduced context utilization, although the experiment does not isolate the causal contributions of attention dilution, position bias, or training-distribution mismatch.
Two ways to shorten the history
| Strategy | Aggregate accuracy at 2M characters | Average prompt | Average request cost | Main risk | |---|---:|---:|---:|---| | Full history | 49/60 | 605K tokens | $0.224 | Long-context degradation and high cost | | Drop old turns | 9/60 | Not disclosed | Not disclosed | Lost constraints and evidence, followed by hallucination | | Chunked compaction and summarization | 54/60 | 112K tokens | $0.041 | Omitted details or accumulating summary errors |
Simple truncation performs worse because it does more than reduce the token count. Old turns contain system-level constraints, prohibited paths, early failure records, and task identity. Once they disappear, the model must infer state that no longer exists. The fabricated SEC-8492 ticket is consistent with that failure mode: missing information was replaced by a plausible token sequence rather than an abstention.
OpenRouter described the alternative as chunked compaction using scaledown/summarize. The chunked designation implies that the implementation did not rely on a single tail truncation, while summarize indicates that large portions of the original turns were replaced by condensed representations. The results suggest that this path retained enough information about the early rule, latest setting, and failed runs to answer the final questions while reducing noisy material in the prompt.
The article does not disclose chunk size, summarizer model, summary prompt, trigger threshold, proportion of raw recent turns retained, or repeated-compaction policy. The 54/60 result therefore validates one implementation direction rather than a reproducible general-purpose recipe.
Engineering trade-offs and failure modes
Chunked summarization is not lossless. Production systems need to guard against four classes of failure:
- Stale state: A summary may preserve an old configuration value while missing the final update. Mutable configuration, paths, owners, and deadlines should live in a structured state store rather than only in prose.
- Loss of exact counts: Summaries often preserve the meaning of a failure without preserving event boundaries or exact counts. Counters, monetary values, version numbers, and test outcomes should remain in dedicated fields.
- Constraint omission: An early prohibition may be downweighted through several summarization rounds. Security boundaries, permissions, and immutable paths should be injected at high priority on every request.
- Error accumulation: If each new summary is produced from the previous summary, errors can be rewritten repeatedly. Systems should retain source events, summary versions, and provenance, then validate critical decisions against the raw records.
Cost savings also have a price. Compaction introduces one or more model calls, queueing delays, and summary-output tokens. The published price of $0.04 per million input tokens does not by itself establish an end-to-end SLA because the material does not fully account for output cost, compaction latency, or repeated compression. A system can reduce main-model input cost while transferring cost to the summarizer and creating state-fidelity risks.
Benchmark credibility and limitations
The experiment has useful controls: identical sessions across five model families, several context lengths, and four qualitatively different capabilities. It cleanly distinguishes finding a fact from counting repeated events, which is more informative than a single aggregate long-context score.
The results should nevertheless be treated as directional evidence:
- There were only three samples per model and length, with no confidence intervals or significance tests. A few seeds could materially shift the averages.
- The sessions were synthetic and fact-injected. They do not measure dependency discovery, merge conflicts, tool-failure recovery, or actual software delivery in real repositories.
- JSON exact match cannot represent partial correctness in open-ended answers and may penalize semantically correct but differently formatted responses.
- A unified OpenAI Chat format and low reasoning effort improve experimental control but may not reflect each provider's native tool protocol or default inference configuration.
- The 3.2M-character tier had models that exceeded the limit or were not run, so cross-model coverage was incomplete.
- The compression implementation, random seeds, complete item-level results, and independent reproduction artifacts were not provided.
- Sliding windows, structured memory, external retrieval, and event ledgers were not included as direct baselines, so summarization is not necessarily the optimal design.
Deployment guidance for coding agents
- Budget by provider tokenizer: Do not use character counts to manage context. Track input, cached, and compaction tokens separately for each provider.
- Use layered memory: Retain recent raw turns, maintain a rolling summary, store structured state separately, and retrieve historical evidence only when needed. The observed 112K-token average is not a universal optimum.
- Keep invariants in a state table: Ticket IDs, current configuration, prohibited paths, failed-test counts, and budget limits should be maintained by code. Summaries should support explanation and retrieval rather than serve as the only source of truth.
- Compact at semantic boundaries: Trigger compression when tool output approaches the budget, the task changes phase, or a critical constraint is about to leave the window, rather than truncating mechanically after every turn.
- Validate summary fidelity: Automatically check critical fields, counters, and constraints after compaction. If a discrepancy appears, recover from the original event log instead of asking the model to repair its own hallucination.
- A/B test real traces: Compare full history, tail truncation, rolling summaries, structured state, and retrieval-based memory. Record task success, summary errors, time to first token, total tokens, and end-to-end dollar cost.
- Redact sensitive logs first: The test sessions include
.envfile content. Production systems should remove credentials before sending logs to a summarization model or external service.
Million-token windows increase how much an agent can carry, but they do not eliminate the need for long-session state management. The strongest engineering conclusion from this test is that chunked summaries can replace destructive truncation, preserving critical task information while sharply reducing prompt size and request cost. The remaining question is not whether compression helps, but which state representation gives the best accuracy-latency-cost balance for a particular workload.
— END —Source: OpenRouter Blog (2026-12-01)
Tags: #OpenRouter #Context Rot #Long Context #Context Compaction #Coding Agents
Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.
Community Comments