There is a number that explains why your agent gets worse the longer it works. It is not the context window filling up. It is what filled it.
A new paper defines Error Token Density as the share of an agent's interaction history occupied by execution-failure content. On natural ALFWorld rollouts from Qwen3-8B, success runs at 40.1 percent when that share is zero. It falls to 6.7 percent once the share reaches 40 percent. That is one sixth of the clean success rate.
Here is the part that stings. The authors did not stop at the correlation. They built controlled continuations that held environment state and remaining action budget fixed, then inserted failure turns. Success dropped 1.9 to 3.8 percentage points more than it did when they inserted neutral text of the same token length. The error text is the poison. The length is not.
Every engineer's instinct is to keep the error so the model learns from it. The measurement says it does not learn. It degrades.
Put plainly, LLM agent context management is not a tidiness routine. It is agent error handling treated as a performance control, with a number attached and a threshold you can alert on.
The work is "The Cost of Failure: Quantifying the Downstream Impact of Error Histories in LLM Agents," from Jiahao Wang and eight coauthors, posted to arXiv on November 26, 2026 as 2611.35727. It is the first paper I have seen that prices the cost of a retained failure turn instead of treating it as free history, and the price is measured in success rate, not vibes. The effect reproduces across planning, code execution, and visual tool use, which means it is a property of the loop, not a quirk of one benchmark.
THE METRIC: ERROR TOKEN DENSITY
What is Error Token Density? It is the share of an agent's context occupied by failure text, and it takes three steps to compute: add the tokens spent on failed actions to the tokens in the tool feedback returned for those failures, then divide that sum by the total tokens in the context window.
Written as a formula, ETD equals tokens in failed actions plus tool feedback for failed actions, divided by total tokens in context. That ratio is a measurable performance variable. It is not a style preference.
You already count tokens. You already watch the context bar. ETD is the one number that tells you whether the tokens you spent bought progress or bought contamination, and almost nobody tracks it. In the paper's natural rollouts the two move together until they do not: a session can sit comfortably inside its window and still be mostly scar tissue.
A metric that predicts a sixfold success collapse is not housekeeping.
THE CONTROLLED RESULT: IT IS THE CONTENT, NOT THE TOKENS
The neutral-token control is the whole argument, so walk it slowly. Two histories go into the model. Same environment state. Same remaining action budget. Same total length, because the second history is padded with neutral text that matches the failure insertions token for token.
One history carries failure turns. One carries filler. The failure history loses by 1.9 to 3.8 percentage points. Then the authors ran the deletion direction, removing failure turns that already existed, and got complementary gains.
That pair of results closes the escape hatch. If the problem were context length, the filler would hurt just as much. It does not. If the problem were the model being told that something failed, then removing that information should have hurt, and it helped. The model is better off not knowing what went wrong, which is the exact opposite of what your debugging habits tell you. It is the same thread I followed in "Your Evaluation Harness Moves Your Benchmarks 4.3 Times More Than Your Training Recipe": measurement beats plausibility every time.
I have written about the compression side of this problem before, in "The Compaction Cliff: Why Your Agent Forgets at the Worst Time." That piece is about what you lose when you summarize history. This one is about what you lose when you refuse to throw any of it away. Both roads lead to the same place, which is a context window that no longer describes the work accurately.
SCOPE, STATED PLAINLY
The 40.1 to 6.7 percent curve comes from natural ALFWorld rollouts with one 8B model, Qwen3-8B. The environment is a text household simulator, and the controlled continuations hold a fixed remaining action budget, so the curve describes sessions of that length rather than a multi-day coding run. The authors extend the test with failure-conditioned evaluations across planning, code execution, and visual tool use, which is what makes the finding general. The 40 percent figure is still an empirical inflection point measured there. It is not a law that a frontier model in a long-horizon harness reproduces at the same number. What transfers is the direction and the control: failure text costs more than neutral text of the same length, and deleting it helps.
WHY "LEARNING FROM ERRORS" FAILS IN CONTEXT
The second paper lands the matching blow. FINDER, from Yinxi Li and eight coauthors, is a process-level study on BrowseComp-Plus, posted the same day as 2611.35455. The authors took every incorrect trajectory from three frozen backbones and assigned each one a primary failure family. Then they asked what test-time learning actually changes.
General-purpose test-time learning raises accuracy. It does not reliably repair the dominant failure families, even though the learned artifacts already cover those families. The agent writes down the right diagnosis, in its own words, and then takes the same wrong action anyway.
That kills the justification you have been using. You keep the traceback because you believe the model will read it and do better next turn. The measurement says the artifact is written and not acted on, so you paid context for a lesson that never lands. Keeping errors fails as learning. The controlled experiment says it succeeds as poison. Both papers are describing the same loop from opposite ends.
To the authors' credit they do not stop at the diagnosis. FINDER organizes experience by the Find, Verify, and Decide stages of the search workflow, contrasts a failed rollout with a successful one, and curates a bounded playbook. It improves judged accuracy by 3.7 to 19.2 points across four frozen backbones, and repairs each backbone's own bottleneck with far fewer regressions than the baselines, without scaling search calls the way those baselines do. On DeepSeek that comes with about 2.44 fewer searches per query; on the other backbones it adds roughly 1.4 to 3.1, still below several of the baselines it beats. The gains are not bought with indiscriminate search bloat. The lesson is not that learning from experience is impossible. It is that unstructured experience dumped into context does not do it.
THE 40% POISON LINE AND A CONTEXT-HYGIENE DOCTRINE
Call the threshold the Context Poison Line. At 40 percent ETD the paper's rollouts run at one sixth of their clean success rate, so 40 percent is not a warning light you glance at. It is the point where you are paying full context price for a fraction of the capability.
The doctrine that follows is simple. Treat failure turns as cache to evict, not history to honor. When a retry succeeds, compress the failed attempt into one line: route X times out, do not retry. Keep the predicate. Drop the raw traceback.
Here is the swap in the concrete. Before: thirty lines of a Python traceback, a retry banner, and the full response body from the failed call. After: GET /orders/123 returned 404, the call is idempotent, do not retry with the same id. The second line carries the constraint that changes your next action. The first carries the mood.
Negative lessons are dense. Failed transcripts are not. One line survives compaction, survives summarization, and survives the model's attention. Forty lines of stack trace do none of those things, and the paper says they cost you percentage points on the way out.
| Metric or mechanism | Core finding | Engineering takeaway |
|---|---|---|
| Error Token Density | 40.1% success, 6.7% past the line | Log it beside success rate |
| Neutral-token control | Equal length, 1.9 to 3.8 less damage | Content poisons, not tokens |
| Test-time learning | Accuracy up, failures unrepaired | Audit what lessons target |
| Memory repair | Half the edges reach 95 to 100% | Follow used support only |
| Tool-Feedback Advantage Shaping | ETD down 26.5 to 67.7% | Reward execution validity |
The training-side version of the same idea is in the paper too. The authors built Tool-Feedback Advantage Shaping, which combines separately normalized task-success and execution-validity advantages. Across six model-environment settings it improved overall accuracy and held the lowest ETD of any policy compared, cutting ETD by 26.5 to 67.7 percent relative to outcome-only reinforcement learning. Read that as an argument about reward design: if you score only the outcome, you train a model that tolerates failure, and a model that tolerates failure accumulates it in context.
MEMORY SYSTEMS GET THE SAME LESSON
The third paper is about persistent memory, and it lands on the same principle at a slower timescale. In "When Does a Memory Descendant Need Repair? Structural Lineage vs. Stale State in Persistent Agent Memory," Joongwon Chae and six coauthors, arXiv 2611.35443, posted November 26, 2026, the question is how much lineage you need to repair a stored conclusion after its source fact changes.
The intuitive answer is all of it. Trace every structural descendant and fix each one. The measured answer is not that. In their controlled testbed, LLM material-support provenance reaches 95 to 100 percent of stale state while covering only about half of structural descendants at greater depth. Matched random graphs with identical edge budgets, precision, and recall reach about two thirds. Following what was actually used beats following everything that is connected.
Selectivity is what makes repair cheap enough to run live. A memory system that audits every dependency edge on every correction is a batch job nobody schedules. One that follows the support a conclusion actually rests on is a millisecond of work.
This is the same discipline as context hygiene, applied over months instead of turns. Both are asking which tokens earn their place, and both find that the answer is fewer than your instinct says.
WHAT TO DO TODAY
- Instrument ETD. After each session, compute the failure-token share of context the same way you compute cost. Log it beside success rate and watch the two curves together for one week.
- Set the poison line. Alert or summarize when ETD crosses 40 percent, because at that share the paper's rollouts run at roughly one sixth of their clean success rate.
- On a successful retry, replace the raw failure transcript with a one-line negative predicate. Keep the constraint, delete the theater.
- Stop quoting raw tracebacks into follow-up prompts. Compress, then cut. Your instinct will argue that the model needs the detail. The neutral-token control is the answer to that argument.
- If you run test-time learning, audit whether the learned lessons target your actual dominant failure family. FINDER's whole finding is that accuracy gains hide unrepaired failures, and the only way to see the gap is to classify your own errors and check what your lessons address.
For the record, the reading above is mine, not the authors'. They measured the effect. The doctrine is how I would spend it.
THE UNCOMFORTABLE QUESTION
If your context gets dirtier the harder your agent works, whose debugging instinct are you honoring, the model's needs or your own?
Get More Articles Like This
Getting your AI agent setup right is just the start. I'm documenting every mistake, fix, and lesson learned as I build PhantomByte.
Subscribe to receive updates when we publish new content. No spam, just real lessons from the trenches.
Build Real AI Infrastructure
PhantomByte teaches you to build real AI infrastructure yourself: local AI stacks, autonomous agents, multi-agent orchestration, web scraping, and custom tools. Step-by-step PDF tutorials you download, follow, and deploy. No subscriptions. No fluff. Just skills that ship.