CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation

Peiwen Li, Harshit Verma, Sophia Zhou, Haiwen Wang, Ngoc Bui, Heng Chang, Fei Fei, David van Dijk, Rex YingarXiv 2026 · arXiv

TL;DR

CoReMem is a novel framework for coding agents that optimizes memory based on its actual "prospective value"—the effort it saves on future, unseen tasks. By focusing on "anchors" like specific repository locations and test commands, it enables agents to skip redundant exploration, increasing success rates while significantly reducing the computational cost (steps and tokens) of solving successive tasks.

What Problem Does This Paper Address?

In real-world software engineering, developers don't just solve one isolated bug; they work on a sequence of tasks within a single, evolving repository. Each task inherits the state left by the previous one. Ideally, a coding agent should "remember" what it learned during one task to work more efficiently on the next.

However, existing memory methods for AI agents often fail in this "successive-task" setting. They either focus on compacting context for the current task or distilling general insights across different repositories. Crucially, they rarely account for the cost of memory. If an agent spends more tokens reading a long memory than it saves by skipping exploration steps, the memory is a net negative. The core challenge is determining what information is actually worth carrying over when the future task is unknown, and training the agent to use that information to save effort.

Figure 2 illustrates how CoReMem differs from existing within-task and cross-task memory settings by carrying both repository state and memory to future tasks.

Methods

The authors introduce CoReMem (Coding-Repository Memory), which uses two key innovations:

  1. Prospective Segment Valuation: To decide what to store, the authors ran "ablation" experiments. They took a completed task's trajectory, split it into segments (e.g., reasoning, commands, test output), and measured how much effort was saved on the next task when each segment was provided as memory. This revealed that "anchors"—specific file locations and executable test commands—are the most valuable pieces of information.
  2. On-Policy Adaptation with Provenance-Gated Value Credit: Even with good memory, an agent needs to be trained to use it efficiently. CoReMem uses a reinforcement learning (RL) approach with a "cost-internalizing" reward that penalizes the number of steps taken. To ensure the agent learns specifically from the memory, they use a provenance gate: only steps that actually utilize an "anchor" from the memory receive a "value credit" based on the overall effort saved.
Figure 4 provides an overview of the CoReMem framework, showing how prospective valuation guides memory design and how provenance-gated credit adapts the actor.

Datasets

The researchers evaluated CoReMem across several benchmarks:

  • ChainSWE: A newly introduced benchmark consisting of 100 chains of successive real-world GitHub issues, where each task inherits the repository state from the previous one.
  • SWE-bench Verified: A standard benchmark for evaluating AI agents on software engineering tasks.
  • SWEContextBench & SWE-Bench-CL: Used to test the model's ability to handle cross-task dependencies and continual learning.
  • OpenHands: An open-source platform for AI software developers used for additional cross-harness validation.

Key Insights and Ideas

  • Anchors > Narratives: One of the most striking findings is that an agent's internal reasoning or detailed "scratchpad" notes are almost worthless for future tasks. What actually saves time are "anchors": where the relevant code is and what command verifies the fix.
  • Internalizing the Cost of Thinking: By explicitly penalizing step counts in the RL reward, the agent learns to treat its own "thinking time" and exploration as a cost to be minimized, leading to more direct and efficient problem-solving.
  • Traceable Memory Use: The "provenance gate" solves a common credit assignment problem in RL. Instead of giving a generic reward for a successful session, it specifically rewards the agent for using the provided memory to skip steps, making the training much more stable and effective.
Figure 5 shows that segments like 'Commands' and 'Repo content' provide the most step savings, leading to a memory design built around anchors.

Key Results

CoReMem demonstrated significant improvements across multiple models (including Qwen, Gemma, and Claude):

  • Efficiency Gains: On the ChainSWE benchmark, a 27B parameter actor model using CoReMem solved 22% more tasks while using 17% fewer steps and 11% fewer total tokens compared to a baseline without memory.
  • Resolve per Token: The "resolve per thousand tokens" metric—a measure of how much "work" the model gets done per unit of compute—increased by 41% on average across three different actor models.
  • Outperforming Baselines: CoReMem was the only method tested that consistently landed in the "ideal" quadrant of reducing both steps and total token usage while improving success rates.
Figure 3: Steps and tokens of each memory form against no memory. Hollow marks count only the acting model’s tokens, and the arrows add the tokens of the memory module. Parentheses give the relative change in resolve rate. The star is CoReMem w/o training (§3.1), the one form near the shaded quadrant where steps and total tokens both fall.

Limitations and Future Work

  • Language Specificity: The primary experiments were conducted on Python repositories. While the "anchor" concept is general, its effectiveness in other languages remains to be fully explored.
  • Long-term Scaling: The study focused on relatively short chains of tasks. How memory should be managed, refreshed, or "forgotten" over very long repository histories (hundreds of tasks) is an open question.
  • Hardware Metrics: The paper measures effort in terms of steps and tokens but does not report wall-clock latency or actual energy consumption, which are important for real-world deployment.

Summary updated

Abstract

Coding agents tackle successive tasks on an evolving repository, carrying forward edits and writing memory before the next task is known. Selecting memory for unknown next tasks requires balancing future usefulness against the costs of writing and reading it. The actor must also decide when acting on available memory saves effort as the task unfolds. We introduce Coding-Repository Memory (CoReMem), a cost-internalizing framework that guides memory design and actor adaptation through measured memory value on the next task. Prospective segment valuation compares runs of the next task with and without individual trajectory segments from the same inherited repository state, guiding a compact memory built around anchors: repository locations and executable checks. Actor adaptation estimates on-policy memory value within rollout groups with and without memory, using a reward that prioritizes resolution and penalizes step count in successful runs. Provenance-gated value credit assigns the additional value term to steps identified as using memory-supplied anchors, while every step retains outcome credit. On ChainSWE, CoReMem raises the 27B actor's resolve rate from 21.0% to 25.7%, with 17% fewer steps and 11% fewer total cache-aware tokens, including memory-module calls, relative to the untrained actor model without memory.
BibTeX
@misc{li2026coremem,
  author = {Peiwen Li and Harshit Verma and Sophia Zhou and Haiwen Wang and Ngoc Bui and Heng Chang and Fei Fei and David van Dijk and Rex Ying},
  title = {{CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation}},
  year = {2026},
  eprint = {2611.17316},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.17316},
}
Figure