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.
Figures & tables
Figure 1: Memory on the next task. A memory written at the end of one flake8-simplify task hands two anchors, a location ( WHERE ) and a check ( VERIFY ), to the next task on the same repository; the post-trained actor model acts on them at steps 1 and 6 and skips the exploration it would otherwise start with (step counts illustrative).
Figure 2: What crosses coding-task boundaries and where memory is valued and optimized. Existing settings keep memory within one task, transfer general experience across independent tasks, or carry memory while resetting the repository. Our setting carries both repository state and memory to unseen future tasks. The ↺ and ↓ symbols indicate whether memory is valued and optimized on its source task or on future tasks.
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.
Figure 4: Overview of CoReMem. (a) Prospective segment valuation of memory. A memory m written from the trajectory τk is valued by the change Δy(m∣bk) it causes on task k+1 , run from the inherited tree Sk with and without m . Removing each of the seven segments of τk gives its value νc , and the segments that pay are kept as anchors A(m) . (b) Cost-internalizing on-policy valuation. A group of G sessions mixes sessions with their own memory ( m ), no memory ( ∅ ) and a misplaced memory ( m~ ) under the reward Ri , and Vb=Rˉm−Rˉ∅ is the memory’s value on-policy. (c) Step-level provenance-gated value credit. Only the steps that the gate ωt marks as acting on an anchor from the memory receive the value credit.
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.
Memory layer
Linked
Unlinked
Overall
Tokens per session (K)
Res. per K tokens
Res. (%) ↑
Steps ↓
Res. (%) ↑
Steps ↓
Res. (%) ↑
Steps ↓
Actor ↓
Writer
Total ↓
Actor ↑
Total ↑
Qwen3.5-9B
No memory
9.7
98.4 (91.1)
19.4
98.1 (91.2)
14.0
98.2 (91.2)
98.3 (98.9)
–
98.3 (98.9)
0.152
0.152
Full history
11.4
70.0 (60.5)
17.9
76.4 (68.5)
14.2 +2%
72.8 (65.1) −26%
85.9 (79.9)
–
85.9 (79.9) −13%
0.156
0.156 +3%
Mem0
12.2
94.3 (86.0)
21.8
93.1 (85.2)
16.4 +17%
93.8 (86.0) −5%
96.5 (94.8)
14.9 (14.4)
111.4 (109.1) +13%
0.175
0.151 0%
MemOp
11.9
93.5 (85.8)
19.0
96.8 (86.3)
15.0 +7%
94.9 (86.1) −3%
99.3 (96.4)
32.4 (33.1)
131.7 (131.4) +34%
0.147
0.111 −27%
Table 1: Cost and outcome of each memory layer for the open-weight actor models on the test set. Resolve rate and steps on linked and unlinked boundaries (App. B ) and overall, cache-aware tokens per session of the actor model and of the memory module (Writer), and resolve per thousand actor or total tokens. Tags give the change against the no-memory row of the same actor model. Gray values in parentheses are medians over sessions. CoReMem w/o training is our memory on the frozen actor model and CoReMem the post-trained actor model with it; replay counts and tests are in App. B , with the definition of every column.
Figure 6: Steps, resolve per token and resolve per dollar against no memory for the API-served models. Top, each point is one memory layer on one model, and the shaded quadrant is where a memory lowers steps and raises resolve per thousand total tokens, which CoReMem w/o training reaches on all three models. Bottom, the change in resolve per dollar at list prices, with full numbers in Table 3 of App. D .
Figure 7: Evidence for M2 and M3. Top, steps per task and resolve rate of the with-memory arms in training order, where up and to the left is better and the larger marker is the full method. Bottom, paired differences in the memory benefit to resolve rate and in the step cost of a misplaced memory, blue for 27B and green for 9B as above, with 95% intervals.
Memory layer
Anchors per 1K chars
Used anchors per memory
Used anchors per 1K chars
Mem0
9.7 [9.4, 10.1]
0.15 [0.09, 0.21]
0.14 [0.08, 0.21]
MemOp
14.4 [13.6, 15.2]
2.06 [1.59, 2.51]
0.92 [0.72, 1.11]
ReasoningBank
8.5 [7.8, 9.1]
0.65 [0.51, 0.80]
0.19 [0.14, 0.24]
CoReMem w/o training
15.8 [15.0, 16.7]
2.24 [1.67, 2.87]
1.32 [1.00, 1.68]
Table 2: Anchors the next task can act on, per memory layer. 27B frozen actor model, test set; an anchor is used when it occurs only in the memory and appears in a message of the next task’s session; brackets give 95% intervals over the test chains.
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 8: Training dynamics of the 27B actor on the test sessions with the memory. Lines are means over three replays and bands their standard deviation. Update 0 is the untrained actor, also drawn as the dashed line. The number beside each panel is the paired difference at update 20 .
Memory layer
Outcome
Tokens per session (K)
Res. per K tokens
List price
Res. (%) ↑
Steps ↓
Actor ↓
Writer
Total ↓
Actor ↑
Total ↑
USD ↓
Res. per USD ↑
Claude Opus 5.5
No memory
38.5
12.6 (12.0)
21.5 (15.7)
–
21.5 (15.7)
1.791
1.791
0.2370
162
Full history
40.6 +5%
10.4 (9.0) −17%
27.0 (23.5)
–
27.0 (23.5) +25%
1.505
1.505 −16%
0.2384 +1%
170 +5%
Mem0
39.6 +3%
13.0 (12.0) +3%
18.7 (16.2)
16.6 (17.8)
35.4 (34.8) +64%
2.112
1.119 −37%
0.2893 +22%
137 −16%
MemOp
39.6 +3%
17.8 (12.5) +41%
21.7 (16.0)
14.4 (12.1)
36.1 (28.2) +68%
1.821
1.096 −39%
0.3630 +53%
109 −33%
Appendix
Table 3: Cost and outcome of each memory layer for the API-served models on the test set. Overall columns as in Table 1 , with the list-price cost per session and resolve per dollar.
Actor
Checkpoint
Resolve (%) ↑
Steps mean (med.) ↓
Actor tok (K) mean (med.) ↓
Raw tok (K) ↓
Limit hit (%) ↓
Res/Tok (actor) ↑
Qwen3.8-27B-FP8 ( Qwen Team, 2026b )
untrained
69.2 ± 1.9
28.3 ± 0.2 (21.2)
24.7 ± 0.6 (17.4)
383.0 ± 15.2
7.0 ± 0.4
2.80 ± 0.10
post-trained
73.7 ± 0.6 +7%**
26.2 ± 0.3 −7%** (20.5)
22.5 ± 0.2 −9%** (17.2)
313.7 ± 1.5 −18%**
2.5 ± 0.1 −64%**
3.27 ± 0.05 +17%**
Qwen3.5-9B ( Qwen Team, 2026a )
untrained
49.1 ± 2.2
90.1 ± 1.3 (86.2)
93.5 ± 0.4 (86.3)
2471.9 ± 20.6
7.1 ± 1.9
0.53 ± 0.03
post-trained
55.5 ± 0.3 +13%**
69.9 ± 1.4 −22%** (63.8)
72.9 ± 1.3 −22%** (64.1)
1586.1 ± 70.4 −36%**
0.1 ± 0.1 −99%**
0.76 ± 0.02 +43%**
Appendix
Table 4: The post-trained actor on SWE-bench Verified. All 500 instances, one task each, no memory, 3 replays per row. The untrained row serves the zero-update adapter on the same path, and tags give the change against it ( ∗∗ for a paired 99% interval that excludes zero). Raw counts tokens with no credit for caching, and Limit hit is the share of instances that end at the step limit.
Memory layer
Linked
Unlinked
Overall
Tokens per session (K)
Res. per K tokens
Res. (%) ↑
Steps ↓
Res. (%) ↑
Steps ↓
Res. (%) ↑
Steps ↓
Actor ↓
Writer
Total ↓
Actor ↑
Total ↑
Qwen3.8-27B-FP8, agent without network access ( n=4 replays)
No memory
31.6
59.2 (61.2)
19.6
44.6 (37.5)
28.1
54.9 (54.4)
89.4 (60.8)
–
89.4 (60.8)
0.340
0.340
No memory, post-trained actor
33.8
51.2 (48.0)
21.4
39.9 (34.4)
30.2 +7%
47.9 (44.8) −13%
76.2 (47.8)
–
76.2 (47.8) −15%
0.406
0.406 +19%
CoReMem w/o training
36.8
40.3 (36.4)
19.6
43.2 (39.1)
31.8 +13%
41.2 (39.1) −25%
61.5 (41.4)
5.2 (2.0)
66.7 (43.4) −25%
0.561
0.517 +52%
CoReMem
40.4
35.7 (32.0)
16.1
34.8 (29.9)
33.3 +19%
35.4 (30.4) −35%
57.6 (35.1)
4.0 (1.9)
61.6 (37.2) −31%
0.628
0.583 +71%
Appendix
Table 5: The memory layer off the training distribution: successive tasks of one repository on an external dataset. SWEContextBench (SCB) pairs are two-task chains of one repository in one image, the next task opening at an independent checkout from the first, so only memory crosses the border. CoReMem w/o training writes its memory under the instruction of Figure 11 ; we updated the writer instructions by adding that the next session starts from a new checkout without the earlier changes, that the memory should not include a summary of or reason for the changes, and that the memory should only include one clause per DID line. The adapted instructions were written after observing the first runs on the set, whose memories were getting cut off because of note length.
Memory layer
Resolve (%)
Steps
Tokens (K)
Resolve per M tokens
No memory
10.6
33.8
897
11.9
Full history
14.9
41.8
1704
8.8
Mem0
11.2
38.3
1176
9.5
MemOp
14.4
38.5
1273
11.9
ReasoningBank
21.8
48.0
1943
11.3
CoReMem w/o training
16.5
38.6
1240
13.3
Appendix
Table 6: Memory layers under the OpenHands harness. The 27B actor model on 94 of the 96 next tasks of the test split, mean of two runs, frozen in the upper rows and post-trained in the last row, where it is served through its LoRA adapter. Tokens are raw counts per session with no credit for prefix caching, memory module included, and do not compare with Table 1 .
Segment
What it holds
In the example session (Figure 9 )
Reasoning text
The actor’s own text in each step, outside the command
“Now let me verify the fix works with a test script.” (step 8)
Commands
Every command the actor ran, in order, with the shell exit code of its step ( 0 for success, nonzero for failure)
python -m pytest tests/ -k "sim102" -q [exit 0] (step 9); a grep on a file that does not exist [exit 2] (step 2)
Repository content
Output of commands that read or search the repository, and of any other command that is not a test
The file list of flake8_simplify/rules/ and the two lines of ast_if.py that mention SIM102 (step 3); the flake8 warning on the negative case (step 8)
Test output
Output of test runners, of scripts written in the session and of inline Python with an assert
The diff the task left in the tree, and output of commands that print a diff
23 added lines in ast_if.py that define is_main_check and call it (step 11)
Outcome
How the session ended, its exit status and step count
Submitted after 12 steps
Appendix
Table 7: The seven segments of a trajectory. The first five partition the transcript, and the last two come from the boundary.
Figure 9: A real trajectory split into segments (flake8-simplify, training split, frozen 27B actor). Verbatim except [...] cuts and the omitted command fences; segment labels and step numbers are ours.
Segment
Measurement on linked boundaries
Decision
Line of the memory
C1 reasoning
Deleting it costs no step (34 helped, 45 hurt) and saves 1.14K tokens ( p=.023 )
Step 3 kept a reason field; Step 4 dropped it
None; the instruction forbids reasons and summaries
C2 commands
Deleting it costs a median 2 steps (56/27, BH p∗=.0070 ); alone it carries the whole saving; the failing commands alone carry half
Kept; failed checks stay in it with their exit code
VERIFY exact command [exit N ] | COVERS paths
C3 repository content
Deleting it costs a median step (52/34, BH p∗=.0302 ) and saves 0.63K tokens
Kept as located facts
CONTEXT fact | WHERE path:lines, in the repository block
C4 test feedback
Test commands with exit codes beat the full test output by a median step (53/30, BH p∗=.045 )
A test result is the exit code of its command
TESTS last full test command [last exit N ]; no pasted output
C5 change
Deleting the diff body costs no step (47/44) and saves 0.94K tokens ( p=.021 ); the file list matches the full diff ( p=.097 )
Anchors only, body banned
DID one clause | WHERE path:lines (symbols); the change is committed and is not restated
C6 outcome
No effect overall (45/33); helps when the current task resolved (24/11)
Observable part kept, hidden-test verdict banned; Step 4 places it in the task block
STATUS submitted, stopped or no change, inside the task block
Appendix
Table 8: From segments to lines. Results of the segment study (App. I ). Counts are boundaries where the segment helped and hurt the next task. BH marks the multiplicity correction across segments.
Kind
Role
Rule
Example
File path
location
has a / and a letter, or a code extension
flake8_simplify/ rules/ast_if.py
Symbol
location
snake, camel, dotted or hyphenated, not all common words
is_main_check , ast.Constant
Test node id
check
contains :: , its path and name also count
tests/test_x.py:: test_y
Command token
check
non-flag token inside a command or a VERIFY / TESTS field
flake8 , sim102
Appendix
Table 9: The four kinds of anchor. Examples are from the memory in Figure 10 except the node id, whose form is shown.
Figure 10: A real memory and its anchors. The memory has 889 characters and 18 anchors.
Figure 11: The instruction under which the actor writes its memory, verbatim from the deployed file. It states what the next session can see, fixes the memory’s two blocks and five line types, sets the rules and shows the finished shape. Bold, shading and gray placeholders are ours.