Editor’s introduction
The study focuses on StateTape, a framework designed to manage context in coding agents over extended tasks. It compares traditional history-based context pruning—where old records are discarded based on text content—to a method that tracks actual code changes. By modeling code as a symbol-level graph and recording changes as a ‘tape’ of diffs, StateTape identifies which parts of the codebase are affected by each edit. This approach allows the system to detect falsified records more accurately than text-based methods, which cannot see the interdependencies between code changes. Findings are attributed to the framework’s ability to maintain relevant context through write-level tracking rather than time-based pruning.
Introduction
Coding agents built on large language models have shown promising results on real software engineering work, running for hundreds of steps on a single task where they read files, run tests and edit code. Despite their great promise, these agents meet significant challenges on long-horizon coding tasks that require many edits. On benchmarks built from such tasks, the resolve rate declines as the task grows longer, even when every individual step lies within the model’s ability. Part of this difficulty is mechanical: every observation is appended to the context and a long context costs tokens and degrades the model’s use of what it already holds. To tackle this challenge, context management, which decides what an agent carries from one request to the next, has attracted fast-increasing attention and has become standard practice in agent harnesses.
A key challenge in context management lies in retaining the observations that later steps depend on while keeping the context small enough to stay affordable and usable. On the one hand, carrying the entire history preserves every observation the agent has made, whereas the agent pays for that history on every later request and the cost grows without bound as the task proceeds. On the other hand, trimming the history bounds the context, while it can discard evidence the agent still needs and force the agent to recover that evidence through additional steps. More recently, deciding what to keep directly from the recorded history has been widely adopted and achieved strong results in long-horizon coding agents. Specifically, by masking or collapsing observations older than a window, summarizing the history once it passes a size limit, or prompting a model to read each record and discard the ones it judges useless or expired, such methods, which we call history-based maintenance, bound the context at a cost small next to the agent’s own.
Closing this gap means deciding, at every write, what to drop and what to add, which is hard for two reasons: 1). Deciding staleness from writes rather than from text. A write and a held record have to be comparable at the same granularity. Rewriting load_config should mark its held copy as stale, but it should not mark every definition in the same file, and no stale record should be missed. 2). Adding the evidence the next edit needs but the agent has not read. What is missing is rarely the edit site itself but a definition it calls, a caller that must change with it, or a contract it must meet, all of which lie along dependency edges that a keyword search cannot enumerate. In the example, the task never mentions start_server, so a search over it misses this caller.
Our Contribution. To jointly address all challenges above, we propose StateTape, a context maintenance framework towards the trade-off between the cost and quality of the context. In StateTape, we design a symbol-level code graph of definitions and call edges that is updated at every write, so that writes, held records and the dependencies among them are comparable in the same granularity. Based on this graph, we use tape to formulate context maintenance as a write-conditioned procedure, where what leaves the context and what enters it are both decided by the symbols the current write changed. Building on the tape, we further propose a lightweight manager that removes what is stale and useless in the context, and retrieves what the task needs by walking the code graph outward from the changed symbols. In the example, the tape marks load_config as changed and refreshes its held copy. The manager then drops _read_json, which has lost its caller, and retrieves start_server and yaml_io.load, which lie one call edge from the write. Finally, we perform extensive evaluations over five comparison methods on three edit-heavy benchmarks with six coding agents, where StateTape attains the best resolve rate in every case at few computational overhead.
Context management for coding agents
Coding agents act on a repository through tools, and on benchmarks that need many edits resolve rate falls with horizon even when each step is within the model’s competence. Their context is managed by age or by a model: collapsing or masking old observations, summarizing past a size threshold, or pruning what a model judges useless or expired, with AdaCoM and ContextCurator training a second model to edit a frozen agent’s context, the same two-model split as our manager. CORVUS re-injects registered files’ on-disk contents every cycle, but unconditionally, whole-file, and for file reads alone; coherence-debt measurements name the missing invalidation bit, and CoAgent supplies it only when another agent writes the object. None of them reads the event that falsifies a record: the agent’s own write. StateTape takes that write as its signal and resolves it to the symbols it changed, so falsified records are named rather than inferred, and the same symbols seed retrieval for the next edit.
Repository structure for retrieval and localization
Repository-level code models bring in cross-file context through structure: iterative retrieval, cross-file dependencies, and graphs over definitions, references and dependencies, which an agent may traverse to localize code and which benchmarks score against one gold context per task. On the evaluation side, Slipstream derives what a compaction must preserve from the agent’s next few steps, the nearest existing per-step target. These works decide what to evict and what to retrieve from text or from a graph fixed at task start, and none of them measures what the agent holds against what it still needs. StateTape instead keeps that graph updated at every write, so that the symbols a write changed decide both what leaves the context and what enters it, and TraceBench measures both sides of that gap at every decision point.
Most of what the edit needs is not held
In TraceBench, 58.5% of gold tokens are not in the context when the edit that needs them is made, and the context covers 41.5% of the gold context on average. What is missing is rarely the edit site itself but the definitions, callers, and contracts a call edge away from it. Retrieval therefore has a starting point that a query over the task description does not give it, namely the symbols the agent is about to change.
Together, the three observations point at a single signal. The unneeded side grows with the agent’s writes and is mostly stale. The missing side lies along the call and dependency edges of the code that those writes touch. §3.2 formulates the gap as two optimization objectives and turns this into the requirements a context management policy must meet.
Staleness is action-conditioned and monotone
The gap between what the agent believes and what the repository holds therefore never shrinks on its own, and it grows with the number of writes. A run with few writes builds up almost none of it. This is the precise sense in which evidence lifecycle is a long-horizon problem rather than ordinary context management, and it is why the effects in §4 follow the number of edits rather than of steps.
A Symbol-Level Code Graph
Requirement 1 decides staleness from writes, and Requirement 3 finds missing evidence along dependencies. Both need writes, records and dependencies in shared units, so a write can be matched against the records it affects and the code depending on it; the code graph provides them.
The Tape: Action-Conditioned Staleness Checker
The tape decides which held records are stale (Requirement 1). At every write, it compares the code graph before and after the write, logs the symbols that changed, and nominates every held record that covers one of them. Because it only compares two graphs, it makes no model call.
A write can change a symbol in two ways. It can edit the symbol’s body, or it can leave the body untouched and change which definition one of the symbol’s calls reaches. Suppose the agent has read read_config, which calls load. If the agent then changes the import from json_io.load to yaml_io.load, the body of read_config stays the same, but the record of read_config no longer describes what the code does. The tape detects the first through symbol bodies and the second through call edges; a symbol changed either way has drifted (Appendix C).
The tape nominates by rule, not by a model, for two reasons. First, the rule is exact. The code graph expresses writes and held records in the same symbols, so each write is matched directly against the records that cover what it changed. Second, it costs no inference (Theorem 2).
The Manager
In the running example, the body of read_config is unchanged, so refreshing it would restore the same text. The manager drops it instead, and the tombstone tells the agent that the call now resolves elsewhere. It also evicts an old test output on an unrelated module, and retrieves the new callee yaml_io.load with a caller of read_config that indexes the returned dictionary.
Conclusion
Context management is a natural remedy for running coding agents over long horizons, since it bounds what the agent carries across requests. However, a coding agent falsifies its own evidence at every write, and history-based maintenance cannot tell from the text alone which records are stale and which code is needed. In this paper, we present StateTape, a novel and scalable framework that rewrites a coding agent’s context at every write rather than by age or size. We model the repository as a symbol-level code graph and build a tape of graph diffs upon it, which turns staleness from an inference about text into an observation of the agent’s writes. At each write, the tape nominates the records the write could have falsified, and a manager subagent built on a small LLM settles what the write log alone cannot. We also analyze StateTape theoretically and build TraceBench, a benchmark that labels what an agent holds against what it needs. Extensive experiments with six coding agents on three edit-heavy benchmarks demonstrate that StateTape clears falsified records and retrieves needed code effectively. It thus attains the highest resolve rate in every setting at marginal cost.
AI use statement
In this work, we used generative AI tools solely to polish the writing of the manuscript: grammar and spelling correction, minor rewording for concision, and LaTeX formatting fixes. We did not use generative AI tools for research ideation, method design, theoretical analysis, implementation of StateTape or of the baselines, experiment design or execution, data analysis, or literature search and citation generation; all such contributions are the authors’ own. All AI-assisted edits were made at the sentence level on text the authors had already written, and every suggestion was reviewed and accepted or rejected by the authors, who verified that no claim, number, or citation was altered. Large language models otherwise appear in this work only as the systems under study, i.e., the coding agents and the manager model evaluated in our experiments. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.
Maintaining the code graph
The graph is maintained per write rather than rebuilt per task. A write changes bytes only in the files it touches, and whether a symbol exists and what its body is are functions of its own file, so only the written files are re-parsed. Call edges are re-resolved only after a write, and the edge comparison is restricted to edges incident to a symbol in a written file, so nondeterminism in call resolution, which lives in files nothing touched, cannot register as change. Appendix D gives the per-symbol index that answers every query of the tape exactly from these incremental updates, without materializing the graph at each write.
Retrieval labels
The manager ranks graph candidates, checks the ones it keeps against source, and labels each retrieval with the rule that admits it: the edit site, a definition the edit references, a site that must stay consistent with the change, or a contract the change must satisfy. These are the rules G1 to G4 under which TraceBench labels gold regions (Appendix E).
Execution environment
Each instance runs in its own Docker container with a 90-minute limit (30 minutes per SlopCodeBench checkpoint) and no turn limit. All runs use a single host with an Apple M5 Pro (18 CPU cores) and 48 GB of memory.
Annotation protocol
The needed pass runs a per-file sweep over the repository at the base commit, reading files until every outstanding gold file is covered and emitting regions with a rule and a justification; the orchestration around it is deterministic rather than model-chosen, so coverage of the gold files is guaranteed rather than hoped for. The stale pass is trajectory-framed and works from the item record inventory with deterministic supersession flags pre-attached. Reproducibility is pinned throughout: endpoint, deployment, model version, prompt version and seed are echoed in the manifest, the request cache is content-addressed and authoritative so replay needs no key, and a prompt change re-namespaces the cache. Labels carry the transcript hash and are byte-reproducible.


