Language-model agents that write unit tests now run in a loop. They write tests, run them, read the failure messages and the coverage report (which lines and branches the tests actually executed), then edit and try again. These loops clearly help. Recent agents roughly double the bug-catching power of a single-shot attempt. Yet the gains flatten after a few rounds, and the hardest branches, the ones that need an object built in a precise state, stay uncovered. The usual way to run such a loop makes the prompt grow every turn: old tracebacks, old coverage reports and old versions of the test file pile up. Separate work shows that language models neglect information buried in the middle of long prompts. Nobody has checked whether the agent's own history is what is getting lost.
We propose to test this directly and then to fix it the right way. The fix is not to make the model read long histories better. The prompt should be rebuilt from scratch each turn. It holds the current test file, the target branches with their dependency code, and a short ledger for each branch recording what was tried and how close each attempt got. The claim is two-sided and falsifiable. Accumulated history actively hurts later turns, mostly through position effects. But simply throwing history away, which is the obvious cheap fix, discards the record of failed attempts that steers the model toward new tests. A compact attempt ledger keeps that record and drops the clutter. It should beat both full history and a stateless restart on hard-to-cover branches and on mutation score.
What is known and where the gap sits
Three bodies of work motivate the proposal. On the coverage side, TELPA (also Enhancing LLM-based Test Generation for Hard-to-Cover Branches via Program Analysis) shows that over 60% of branches in 27 Python projects are hard to cover. It reaches them by feeding the model statically extracted object-construction sequences and branch-dependency methods. It also feeds back "counter-examples": earlier tests that ran but missed the target branch. TELPA rebuilds its prompt per attempt, but it never asks how much history to keep or where to place it. TestForge runs GPT-4o in a file-level, multi-turn loop that reads pytest tracebacks and line-coverage reports. It does nothing to prune the growing conversation. CodeTransOcean documents the plateau directly: compiler-feedback debugging gains about 3 points in round one and little afterwards.
On the long-context side, Serial Position Effects of Large Language Models finds U-shaped accuracy over prompt position, with primacy dominant in 73 of 104 model-task settings. It also argues the bias is tied to architecture and resists prompt-level steering. This constrains us: we should expect rearranging prompts to be a partial cure at best. Mitigating Posterior Salience Attenuation shows that the correct token usually stays in the model's top 8 candidates while nearby tokens crowd it out, and proposes a decoding correction. It was tested on synthetic retrieval only. CLOVER shows open models collapsing past 8k–16k tokens on repository test generation. It is one-shot, so it says nothing about contexts that grow from the agent's own turns.
On the noise side, Less is More shows that stripping narrative clutter from problem statements improves code synthesis. Characterizing Prompt Compression Methods finds that keeping whole 128-token chunks chosen by a reranker beats token-level pruning, which breaks code syntax. Both supply methods we reuse or compare against. Neither touches execution feedback.
The gap, then, is a missing link: the refinement plateau and the positional decay results have never been connected by a controlled experiment. The closest system, TELPA, keeps counter-examples but treats prompt layout and history length as fixed design choices rather than objects of study.
Core Claim
In multi-turn test generation, the feedback a model saw several turns ago is used less well than identical feedback placed fresh at the end of a short prompt. This loss explains a measurable share of the plateau. The useful content of that history is small. For each uncovered branch, it is the list of attempts and the furthest point each attempt reached on the path toward the branch, a distance we can compute from coverage traces. Keeping exactly this, in a fixed layout with targets last, should recover the lost performance and keep the exploration benefit of counter-examples.
Research Program
The work has three parts.
Diagnosing whether history hurts. We take a TestForge-style agent and run it on TestGenEvalLite. At a chosen turn $k$, we fork the run into two continuations that share the same current test file and the same latest coverage report. One continuation keeps the full accumulated conversation. The other receives a freshly built prompt containing only the current state. We define the history effect at turn $k$ as
$$\Delta_k = C(\text{fresh}_k) - C(\text{full}_k),$$
where $C$ is the line coverage after one further turn, averaged over files. A positive $\Delta_k$ that grows with $k$ is evidence that history harms. To attribute that harm to position rather than to sheer length, we run a position sweep. The same uncovered-line report is placed at the start, middle or end of a length-matched prompt padded with the agent's own earlier turns. We then measure how often the next test executes the reported lines.
We also log a behavioural signature of forgetting, the repeat rate. This is the fraction of new tests whose covered-line set duplicates an earlier failed attempt on the same target.
Building the attempt ledger. For each uncovered branch, the ledger stores three things. The first is the branch condition together with TELPA-style construction and dependency snippets, extracted by static analysis. The second is a record of up to $m$ prior attempts. Each attempt is shown as its call sequence plus the deepest branch it reached along the path to the target, which the coverage trace gives us. The third is the current failure message for that branch only.
The prompt is rebuilt every turn in a fixed order: dependency code first, then the current test file, then ledgers, with the target branches last. This places the most needed text in the high-recency slot. We treat $m$ and the choice of which attempts to keep (most recent versus "closest-reaching") as experimental variables. That directly addresses the question TELPA left open: when do counter-examples stop guiding the model and start distracting it?
Generalizing across models. We run all of this on GPT-4o and on two open RoPE-based models. The open models are where CLOVER saw collapse, and they are also where decoding-level fixes such as positional contrastive decoding can be applied at all.
Baselines
The naive reference point is single-shot generation with the same file context and no feedback. This is the baseline against which TestForge reports its gains.
The strongest existing method is a TestForge-style full-history loop with the same model, the same per-file turn budget and the same tools. TestForge reports 84.3% pass@1, 44.4% line coverage and 33.8% mutation score on TestGenEval with GPT-4o, against an 18.4% mutation score for one-iteration generation (TestForge). We will rerun it in our harness rather than rely on those numbers, because the sandbox and model version will differ. Beating it means higher mutation score and hard-branch coverage at equal or lower total input tokens per file, with the improvement holding across three seeds.
For hard branches, we compare against a TELPA-style loop that uses the same static analysis and counter-example sampling. TELPA reports 25.93% average branch-coverage gains over CODAMOSA on its 27-project benchmark (TELPA); no absolute coverage number appears in our file. We will run it with the same model and number of attempts per branch.
The key ablation isolates the ledger. It is a stateless restart: the same rebuilt layout and dependency code, with all attempt records removed. If the stateless restart matches the full ledger, the contribution reduces to "drop history," and we will report it as such.
A second ablation keeps the ledger contents but puts them in the middle of the prompt. This separates the value of the content from the value of its placement.
All arms get identical turn budgets, model temperature and per-file token caps. Every report includes cost per file.
Why not just…?
Why not just restart from a clean prompt every turn? This is the most serious threat. Since TELPA rebuilds prompts per attempt anyway, a stateless restart may be most of the win. The evidence against it as a complete answer is indirect: TELPA found that counter-examples help, and a stateless restart throws them away. Our stateless-restart ablation settles the question directly. The prediction is that it matches the ledger on easy lines but loses on hard branches and shows a higher repeat rate. If it does not, we adopt it and the paper becomes a diagnosis of why histories hurt.
Why not just keep the history and put the coverage report at the end? Placing the targets last addresses recency but leaves earlier attempts in the middle. Vosoughi et al. find that the positional bias is architectural and resists prompt steering (Serial Position Effects). The "full history, targets last" arm, compared against the position sweep, will show how much of $\Delta_k$ placement alone recovers.
Why not compress the history with a reranker? Chunk reranking was the best compressor on LongBench, gaining 7.89 points on 2WikiMultihopQA. However, it was untested on code and fragile on structured inputs (Characterizing Prompt Compression Methods). A reranker scores relevance to a query. It cannot know which attempt got closest to a branch, which is information only the coverage trace holds. We include reranker compression of the full history at the ledger's token budget as an arm.
Why not fix it at decoding time with positional contrastive decoding? That method raised InfiniteBench 8k key-value retrieval from 72.0% to 79.0% on Llama-3-8B-262k (PCD). It corrects token-level retrieval, whereas a test agent has to synthesize a new call sequence, not copy a distant token. It also works only on open models. We run it on the open models over full history, alone and combined with the ledger.
Proposed Experiments
Development and the diagnostic experiments use TestGenEvalLite (160 files). Final results use the full TestGenEval set of 1,210 files, reporting pass@1, line coverage and mutation score. Hard-branch results use TELPA's 27-project Python benchmark (3,979 hard branches), with branch coverage restricted to that set. Long-context stress tests use CLOVER Task III, where the best reported one-shot success is 32.7% for GPT-4o at 64k with oracle context (CLOVER). There we test whether looping with a ledger lifts open models off their reported floor of under 10%.
Three decisive checks determine the outcome. The first: if $\Delta_k$ is not positive and growing with $k$, history is not the cause of the plateau. In that case we stop the positional story and report the negative finding. The second: the ledger must beat the stateless restart on hard-branch coverage and on repeat rate. Otherwise the attempt memory adds nothing. The third: the ledger-in-the-middle ablation should lose part of the gain, which would confirm that placement still matters even in short prompts. Throughout, mutation score rather than coverage is the headline metric, because TestGenEval shows coverage and mutation score can diverge sharply, at 35.2% versus 18.8% for GPT-4o (TestGenEval).
References
- Advancing Code Coverage: Incorporating Program Analysis with Large Language Models
- Enhancing LLM-based Test Generation for Hard-to-Cover Branches via Program Analysis
- TestForge: Feedback-Driven, Agentic Test Suite Generation
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- Serial Position Effects of Large Language Models
- Mitigating Posterior Salience Attenuation in Long-Context LLMs with Positional Contrastive Decoding
- CLOVER: A Test Case Generation Benchmark with Coverage, Long-Context, and Verification
- Less is More: Summary of Long Instructions is Better for Program Synthesis
- Characterizing Prompt Compression Methods for Long Context Inference
- TestGenEval: A Real World Unit Test Generation and Test Completion Benchmark