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

Peiwen Li, Harshit Verma, Sophia Zhou, Haiwen Wang, Ngoc Bui, Heng Chang and 3 more · arXiv · 2026-11-12

- **Problem** Memory for coding agents is usually valued on the task that produced it, but successive tasks need memory valued by its effect on an unseen task that inherits the repository.
- **Method** Values each segment of a finished trajectory by the effort it saves on the next task, keeps the segments that pay as anchors, and trains the actor on paired memory and no-memory rollouts with provenance-gated value credit.
- **Results** On ChainSWE, the post-trained 27B actor with CoReMem reached a 25.7% resolve rate against 21.0% for the untrained actor without memory, with 17% fewer steps and 11% fewer total cache-aware tokens.

![Figure 5: From segment values to the memory design. The median change in steps (νc) and in thousand actor tokens ( κc) when one segment is removed from the cur…](https://refivu.com/papers/e104c90e-8d89-4dc7-99ab-fd5ebe5db15e/figures/figure-5769622cf0389c1652fa1b072efdcda5.png?thumb=512)

**Figure 5** :From segment values to the memory design. The median change in steps (νc) and in thousand actor tokens ( κc) when one segment is removed from the current task’s trajectory (Eq.(3); 27B actor model). Blue bars mark segments whose removal adds steps. The right columns give the field each segment becomes in the memory design, kept as a main field (blue), in reduced form (light blue) or dropped (gray), and what the next task gets from each of them.

[Original paper](https://arxiv.org/abs/2611.17316v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Peiwen Li, Harshit Verma, Sophia Zhou, Haiwen Wang, Ngoc Bui, Heng Chang, Fei Fei, David van Dijk, Rex Ying · CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation · Original paper figure · Extracted the figure area from page 4 of the original PDF.

## Why unseen next tasks need a different memory target

Coding agents increasingly work through a chain of tasks on one repository. Each task opens the tree that the previous task left, and the later tasks are not known in advance.

Existing memory methods were built for other settings. Within-task methods compact the context of a task whose goal is already known, while cross-task methods distill general lessons across independent tasks or reset the repository before each task.

The comparison in Figure 2 shows which parts cross the task boundary in each setting, and where memory is valued and optimized.

Two questions follow. The first is what information from a finished task is worth carrying to a task that has not been issued yet. The second is how an actor should use an inherited memory during execution. Existing coding memory methods mostly change what is stored or retrieved and leave the model that reads the memory unchanged. An agent's information needs also shift as a task unfolds, so choosing memory only at the start of a task is not enough.

## Valuing a memory before the next task is known

When a task ends, its repository state persists while its trajectory is discarded. A memory \\(m=\\pi\_{\\mathrm{write}}(\\tau\_k)\\) is written once, before the next task is issued, and it is the only text that crosses the boundary.

Because the state is inherited, a memory cannot be checked on the task that produced it, since that task's answer already sits in the repository. Its value is therefore measured on the next task, as the change in an outcome y caused by running with the memory compared with running without it. \\\[\\Delta y(m\\mid b\_k)=\\mathbb{E}\[y(m)\]-\\mathbb{E}\[y(\\varnothing)\]\\\] The outcome y can be resolution, steps or actor tokens of the next task's session, and the expectation is over the actor's sampling.

The expectations are estimated from mean outcomes of sampled runs, so the value is the difference of two means. The candidate memories at one boundary share a single no-memory arm, which means n candidates need n+1 arms instead of 2n.

With the form of the memory fixed, training adapts the actor from \\(\\theta\_0\\) to \\(\\theta=\\theta\_0+\\Delta\\theta\\). The aim is fewer steps on the next task without resolving less often than the base actor. \\\[\\min\_{\\Delta\\theta}\\ \\mathbb{E}\_{\\theta}\[n(\\tau)\]\\quad\\text{s.t.}\\quad \\mathbb{E}\_{\\theta}\[\\mathrm{res}(\\tau)\]\\ \\ge\\ \\mathbb{E}\_{\\theta\_0}\[\\mathrm{res}(\\tau)\]\\\]

## Segments, anchors and the kept memory

Each segment is valued by removing it from the current trajectory and replaying the next task. The removal changes the median steps and the thousand actor tokens of the next task, and a segment whose removal adds steps is one that pays.

Each kept segment becomes a field of the memory. Verification commands become VERIFY lines, located facts become CONTEXT lines with WHERE, test results are merged into the STATUS line, and the change becomes DID and FILES. The reasoning segment carried no step value, so its reason field was dropped.

On linked boundaries, deleting the commands costs a median of 2 steps (56/27, BH p\*=.0070), and deleting the repository content costs a median step (52/34, BH p\*=.0302). Deleting the reasoning text costs no step (34 helped, 45 hurt) and saves 1.14K tokens (p=.023). On the training half alone, the Shapley values for the commands, the repository content and the tests are +3.09, +2.67 and +2.40 steps, and the reasoning text takes a negative value.

Anchors are the references in the kept memory, namely repository locations and executable checks. Four kinds are recognised: file paths, symbols, test node ids and command tokens. A string matcher finds these kinds, and filters drop tokens shorter than six characters, common words and scaffolding names. A path reference is matched on its path, so its line range guides the next task without being needed for a match.

The memory is written by the acting model in a final turn, under an instruction that limits the note to at most 10 lines and 1200 characters, and forbids reasons, summaries and quoted test output.

## Training the actor on paired memory conditions

Each training group draws eight sessions at one boundary: four without memory, three with memories of that boundary written by the frozen base actor, and one with a misplaced memory taken from another repository. For the 27B actor the pool holds three memories per boundary, and for the 9B actor twelve.

The on-policy value of the memory is the difference between the mean reward of the own-memory sessions and the mean reward of the no-memory sessions, \\(\\hat V\_b=\\bar R\_m-\\bar R\_\\varnothing\\).

The reward prioritizes resolution and penalizes the step count of successful runs. Its constants are W=250, n\_max=100 and alpha=50 for the 27B actor, and n\_max=200 and alpha=16 for the 9B actor.

Advantages are divided by a fixed scale s=100 instead of the group's standard deviation. This keeps the value term in one unit across groups, so the value credit stays comparable between boundaries, and the standard deviation is dropped following Dr. GRPO.

The actor is a LoRA adapter on the frozen base actor, trained by policy gradient with a KL penalty of weight 0.2 to the base actor. For session i, the loss is given by the expression below, in which the sign of the leading minus matters. \\\[\\ell\_i(\\theta)=-\\frac{1}{N}\\sum\_{t\\in\\tau\_i}A\_{i,t}\\sum\_{j\\in t}\\log \\pi\_\\theta(x\_j\\mid \\mathrm{prefix}\_j,c\_i)\\\]

## Crediting the steps that act on memory

Outcome credit spreads one reward over every step of a session. The steps that use the memory are only about three percent of the steps, so a signal aimed at memory use is weak in outcome credit alone.

For own-memory sessions the step advantage combines the session's own outcome with the gated value term. \\\[A\_{i,t}=\\frac{R\_i-\\bar R\_m}{s}+\\omega\_t\\,\\frac{\\hat V\_b}{s}\\\] Memory-free and misplaced-memory sessions receive their session advantage on every step, as in the expression below. \\\[A\_i=\\frac{R\_i-\\bar R\_\\varnothing}{s}\\\]

Because the value term is multiplied by \\(\\omega\_t\\), only gated steps receive it, and every step keeps its outcome term. The authors argue that paying the same value to every step acts as a baseline, whereas paying it through the gate pushes how often the actor acts on the memory, in the sign of the on-policy measurement.

## Main ChainSWE comparison for the 27B actor

The evaluation runs ChainSWE in mini-swe-agent. Its 100 chains are split by repository into a training half of 52 chains and a test half of 48 chains. The test half has 96 boundaries, of which 54 are linked to earlier gold patches and 42 are unlinked.

Against the untrained 27B actor without memory, CoReMem raises the resolve rate from 21.0% to 25.7%. It uses 17% fewer steps and 11% fewer total cache-aware tokens, counting the calls of the memory module.

Steps count the assistant turns of a session, each being one command. Tokens are split into actor calls and writer calls, with a total, and resolve per token divides the overall resolve rate by the thousands of actor or total tokens.

With the actor frozen, the memory alone lowers steps on all six actor models. Three of them show significant step reductions of 9% to 13%, and total tokens lie between -7% and +5% of no memory on five of the six.

After post-training, the three open-weight actors resolve 22% to 27% more often and use 9% to 19% fewer total tokens. Resolve per total token rises by 38% to 46%, which is 41% on average across three actor models.

Figure 6 shows the same comparison for the three API-served models. CoReMem without training is the only memory form that reaches the shaded quadrant where steps and resolve per thousand total tokens both improve on all three models.

## Existing memory forms against no memory

Full history, Mem0, MemOp and ReasoningBank are each run on the ChainSWE test set. The tokens of the acting model and of each memory module are counted separately.

The authors report that no existing form reaches that quadrant. Some forms buy resolution rather than effort, and each one spends more tokens on its memory than it saves.

## Anchors the next task acts on

CoReMem without training packs 15.8 anchors per thousand characters, and the next task uses 1.32 of them per thousand characters. The comparison values are 0.92 for MemOp, 0.19 for ReasoningBank and 0.14 for Mem0.

The memory of CoReMem without training is written by the frozen actor, so this comparison concerns the memory form, not the post-trained actor.

## Value credit and misplaced memories

A misplaced memory from another repository is the control. Without the value credit, the misplaced memory costs the 27B actor 2.1 steps, while with it the cost is +0.3 steps.

The ablation arms differ in replays. On 27B, the w/o training arms average 18, 18 and 6 replays for with-memory, no-memory and misplaced-memory conditions, the M1+M2 arms 18, 9 and 6, and the full method 6, 6 and 3.

## Training dynamics on held-out sessions

At update 20, the full method uses 2.0 fewer steps than resolve-only RL (95% CI -4.1 to +0.4), 6.9K fewer actor tokens (CI -11.2 to -3.1), and resolves 1.0 points more (CI -2.4 to +4.5).

## Limitations

The main experiments use Python repositories in mini-swe-agent, and post-training covers only the three open-weight actor models. Other programming languages and larger actor models were not tested.

Effort is measured by steps and cache-aware tokens, and wall-clock latency and energy use are not reported.

The test comparisons rest on 48 chains and 96 boundaries. The Opus rows are read from a single replay, and the frozen 9B rows from 12.

At update 20, the step and resolution differences against resolve-only RL have intervals that include zero, so only the token difference excludes zero.

## Paper info

- **Authors**: Peiwen Li, Harshit Verma, Sophia Zhou, Haiwen Wang, Ngoc Bui, Heng Chang, Fei Fei, David van Dijk, Rex Ying
- **Venue**: arXiv · Preprint
- **First published**: 2026-11-12
- **Added**: 2026-11-14
- **Updated**: 2026-11-12
- **Version**: v1
- **arXiv**: 2611.17316
- **Category**: cs.AI · cs.CL · cs.SE
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2611.17316v1) · [PDF ↗](https://arxiv.org/pdf/2611.17316v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## 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.

## Quote from the paper

Peiwen Li, Harshit Verma, Sophia Zhou, Haiwen Wang, Ngoc Bui, Heng Chang, Fei Fei, David van Dijk, Rex Ying (2026). CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation. arXiv:2611.17316v1. https://arxiv.org/abs/2611.17316v1

**BibTeX**

```
@misc{li2026coremem,
  title = {{CoReMem: Cost-Internalizing Memory for Successive Coding Tasks with Prospective Valuation}},
  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},
  year = {2026},
  eprint = {2611.17316},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.17316v1}
}
```

## Other paper commentary

- [Hierarchical Neural Story Generation](https://refivu.com/en/papers/90786984-6cb5-4a01-ba2e-d107890942b5-hierarchical-neural-story-generation.md)
- [GQA: A New Dataset for Real-World Visual Reasoning and Compositional Question Answering](https://refivu.com/en/papers/d0afea32-dc3f-4529-bea4-dbdd41e95856-gqa-a-new-dataset-for-real-world-visual.md)
- [How to Fine-Tune BERT for Text Classification?](https://refivu.com/en/papers/b42bc4b9-8309-43db-89e9-41cd1d0ec800-how-to-fine-tune-bert-for-text-classification.md)
- [Text Classification Algorithms: A Survey](https://refivu.com/en/papers/5134d426-2cd3-4691-aeff-cf1fc4cb8d39-text-classification-algorithms-a-survey.md)
- [Reading Wikipedia to Answer Open-Domain Questions](https://refivu.com/en/papers/0abc2d22-75a1-4c4d-91be-624a590aabec-reading-wikipedia-to-answer-open-domain-questions.md)
- [A Neural Conversational Model](https://refivu.com/en/papers/2838569c-2f3a-45e5-86e6-549de8737d24-a-neural-conversational-model.md)
- [Consistent Video-to-Video Translation via Explicit Correspondences](https://refivu.com/en/papers/8f234337-14fe-441f-a784-559f1cd4304b-consistent-video-to-video-translation-via-explicit.md)
- [Negative-Only Policy Optimization for One-Sided Verifiable Rewards](https://refivu.com/en/papers/75703081-c2a7-460f-8f67-70f70b2f4385-negative-only-policy-optimization-for-one-sided-verifiable.md)
- [TTB: Test-time Baking for Efficient Rendering of Decoder-only View Synthesis Models](https://refivu.com/en/papers/f34fe5c7-9006-4cfd-9121-be1fdd53118f-ttb-test-time-baking-for-efficient-rendering-of.md)
- [Ballad: Bandit-Based LLM Routing for Automated Heuristic Discovery](https://refivu.com/en/papers/8235a1af-2f08-4cce-82f5-6886ad0fb161-ballad-bandit-based-llm-routing-for-automated-heuristic.md)
- [eDMD: Endpoint Distribution Matching for Few-Step Diffusion Distillation](https://refivu.com/en/papers/039e2f7f-dc99-4e6c-b431-a68221cbbfc2-edmd-endpoint-distribution-matching-for-few-step-diffusion.md)
- [Maximizing Capacity Utilization of LoRA Adapters for Mitigating the Learning-Forgetting Trade-off](https://refivu.com/en/papers/911a8326-f128-4cba-a0a4-26e3e558c34d-maximizing-capacity-utilization-of-lora-adapters-for.md)

## Terms in this paper

- [LoRA](https://refivu.com/en/terms/bee764895c36-lora)
- [anchors](https://refivu.com/en/terms/82b92d483f18-anchors)
- [Mem0](https://refivu.com/en/terms/cad97cd9c87b-mem0)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e104c90e-8d89-4dc7-99ab-fd5ebe5db15e-coremem-cost-internalizing-memory-for-successive-coding)
