fold Part 4 · Rotation and Retention

A session that outlives its context window is doing two jobs at once: rotating old material out, and retaining what it has learned. Eight sealed sessions worked the same long study of a real codebase, then sat the same surprise exam about their own conversation. This page is what each mechanism kept, what each lost, and the composition that closed the line: animated, question by question, from the sealed record.

Scroll to explore

← fold Part 4

The Question

The summary was the memory

At the end of a long study of a codebase, the campaign put sixteen questions to the native compaction session about its own conversation: which files traveled together? It answered four correctly. An audit of its final handoff summary, checked line by line against the exam, accounts for the whole score. Every question it got right was one its summary could answer. Its three wrong answers named file sets that sit in the summary in a misleading order, and it abstained on the rest. Nothing in its performance required memory beyond what the summary's structure supplied.

That is not an indictment of compaction. It is a precise description of what compaction is. When the window fills, the model writes a summary for its future self and starts again on top of it. That summary is durable context, and all of it lives in exactly one record: curated at handoff time by the model itself, permanent once captured, and bounded by the window it has to fit inside. It keeps exactly what the model thinks to write down, and on material shaped like what models write down, it is very good. The same session corrected every planted stale value that only memory could fix, perfectly. Its one record worked, for exactly what it captured, and not one question further.

The question this final part asks is what happens when that job is moved out of the record and into a store, and the window is left to do rotation alone. A store is many records rather than one, each at its own address, written as the work happens instead of in a single pass at eviction, and it outlives the session that wrote it. The previous parts built the pieces: Part 1 priced lossless folding against compaction, and Part 2 showed what a summary throws away. This is the capstone, and it measures the two jobs separately.

The window, breathing: every prompt of four sealed runs

Each run's context occupancy, request by request. Native compaction climbs in long ramps, peaks at 292.8 thousand tokens, over the 251.5 thousand token serving budget, and drops at each of its 23 stop-the-world summarization passes. fold deterministic saws inside its configured band: it commits folds near eighty percent of the budget and cuts to the floor, peaking at 224.7 thousand tokens and never reaching the wall. The store-carrying variants of both runs show the same two shapes.

Both mechanisms rotate; the shapes are their personalities. Compaction lets the window ride high and pays one big stop-the-world pass at each cliff. The fold is a thermostat: it trims the stalest material behind short placeholders whenever the band's top is crossed, and every trimmed byte stays one peek away. Rotation is the part both do well. The exam below is about everything rotation alone cannot do. Switch runs with the buttons; hover the trace for any request's true size. Served token counts from the sealed provider ledgers.

The Exam

Sixteen questions no summary transcribes

Eight sessions ran under seal: same frozen 64-stage plan over a pinned checkout of the curl repository, same model, same withheld exam. The conditions: native compaction alone and beside a memory store, four draws of fold with deterministic fold briefs, one fold run where the agent was invited to write its own briefs, and fold beside the same store. The exam arrives as one final message after all sixty-four stages, and it opens in plain conversational language: before we wrap up, a few loose ends. Which files came in just before the batch that had lib/altsvc.c in it? Sixteen of those, about the session itself, chosen because no summary transcribes conversational adjacency and no repository file contains it.

One design choice matters for reading every score. Each session's own transcript stays reachable, because a deployed agent can always consult its own transcript, and denying that here would have loaded the comparison against compaction, whose only recovery channel it is. It is deliberately unadvertised and costs real shell work to reach. So the exam measures the composed system: mechanism plus whatever recovery the session thinks to attempt, and every score below travels with its run's recovery record.

Every run: exam score against total cost

Fourteen correct: fold deterministic + store at $100.85, native compaction + store at $201.70, and two plain deterministic draws at $92.85 and $83.98. Nine and eight correct: the other two deterministic draws at $109.52 and $88.26. Four correct: native compaction at $151.24. Three correct: fold agent-guided briefs at $111.96.

The two gold-filled runs carry the store and tie at fourteen correct with no wrong answers, at a factor of two in price. The four deterministic draws are replicates of one condition, and their spread is a finding of its own. Hover any run for its full card. Scores and dollars from the sealed cost audit.

Question by Question

Where each mechanism's shape ran out

A single score hides the texture, so here is every answer. Native compaction abstains on every question about the older half of the run: its summary still names each of those files in its inventory, but no longer seats any of them beside the files that traveled with them, and abstaining was the honest move for a mechanism that knows its summary is all it has. Every answer it does give sits late in the run, where the raw transcript was still in its window. The oldest questions are visibly harder for everyone, and no run got two of them right.

The four deterministic draws split into two modes, and cost does not predict the mode: the cheapest draw tied the best score. Recovery predicts it. The two fourteen-scoring draws went and read their own transcript in the end block. The nine-scoring draw recovered from the wrong place, sorting the fold's on-disk evidence by file time to rebuild chronology. The eight-scoring draw never recovered at all, answering from its window and its briefs. A lossless record pays only when the reader goes and reads it, and reads the right part of it.

Every question, every run

Rows ordered by score: native compaction + store, fold deterministic #1, #2, and + store all at fourteen correct; fold deterministic #3 at nine; #4 at eight; native compaction at four; fold agent-guided briefs at three. Native compaction abstained on all nine questions about stages one through thirty-two and answered only at stage thirty-five and later. The bottom margin counts runs correct per question: five five four four zero five four six zero on the older half against seven six seven seven seven seven six on the newer, with stages sixteen and thirty-two at zero.

Green is correct, half-filled is a partial that scores zero, a dash is an honest abstention, and the crossed cell is a wrong answer. The two zero columns are the exam's hardest questions: nobody got them, which is what caps every good run at fourteen. Hover a cell for its question and outcome; hover a column to follow one question across all eight runs. Outcomes from the sealed adjudication.

The Attractor

Annotation pulled the answers toward the briefs

The campaign's worst score was not native compaction. Inviting the agent to write its own fold briefs, one flag moved from the deterministic condition, produced three correct and nine wrong. The mechanism is visible in the run's own brief store. Every correct answer sits on a question whose files one brief happened to list together. Nine questions are like that, and only three of them came back correct, while no question outside that set came back correct at all. Seven of the nine wrong answers name a pair of files that one brief lists together, in a brief that never names the file the question asked about. The briefs pulled thematically related names into the answer, and the model took them. The run recovered heavily and its recovery obeyed the same pull, peeking its own fold record twenty-four times and never touching the transcript.

The deterministic twin, the same condition one flag apart, was asked seven questions about files its own briefs never listed together, and got every one of them right, by treating briefs as a map rather than a memory: twenty peeks and three transcript reads in the end block. The same habit shows up wherever an agent-written record stands in for the source. Compaction's model trusted its checklist, the briefs run trusted its annotations, and pi-canon's write-desk study watched agents trust their own stale records. A model believes its own digest. The design answer is not to break that habit. It is to make the digest the model believes one you can vouch for.

Outcome against the run's own briefs

fold agent-guided briefs, 899 briefs minted, nine of sixteen questions co-seated: three correct, all on co-seated questions; nine wrong, seven of them naming a pair that rides in a brief without the asked-about file; recovery twenty-four peeks, zero transcript reads. fold deterministic #1, 770 briefs minted, the same nine of sixteen co-seated: fourteen correct including seven questions no brief co-seats, zero wrong; recovery twenty peeks and three transcript reads. The other deterministic draws scored fourteen, nine and eight.

The underline marks questions whose files sit together in one of the run's own briefs; the ring marks a wrong answer whose named pair rides in a brief that lacks the asked-about file. Same index shape, opposite relationships to it: one run read its annotations as memory and the other read its briefs as a map and went to the source. Hover any cell for its story; press the pull button to watch the wrong answers trace back to the briefs that supplied them. From the sealed brief stores and adjudication.

The Store

The memory store closes the gap, on both arms

Give either mechanism a canonical memory store outside the window and the correct and wrong counts stop distinguishing them: fourteen correct on each, not one wrong answer between them, and the two dropped questions are the same two that capped every good run. Both sessions built their stores unprompted, from the tool's own description, and converged on the same shape: one page per source file studied, filed under that file's own path. The store lives outside the window, so the oldest material is as close as the newest. Both store runs answered every question about the older half of the run correctly, stages one through thirty-two, save those two shared stumbles. That is exactly where native compaction alone had abstained on every question.

The offered notepad is this section's control. One deterministic draw carried an in-window notepad instead, a remember-and-recall scratchpad refreshed into the window every commit, and the model never called it once across sixty-four stages and the exam, with the offer provably in front of it on every request. Two things separate the two, and this campaign cannot say which one did the work. The notepad lived in the window and the store did not. And the store's tool prose commands a ritual, read before work and write after changes, which ran all session on both store arms, while the notepad's prose offers a capability, and the capability went untouched. The prose is the likelier cause, and a control that was never called cannot prove it. What the run does show is the structural cost: an in-window scratchpad competes for the space it exists to protect, and ages out with everything else.

Store calls across the run, against the untouched notepad

native compaction + store: 904 reads and 340 writes, plus 40 calls in the end block, 234 files, 1,700 provider requests. fold deterministic + store: 549 reads and 275 writes, plus 8 in the end block, 237 files, 916 provider requests. The offered notepad run: zero calls in 1,873 tool calls, 1,169 of them file reads, with the notepad served on every request.

Writing travels together: both arms built nearly the same store, an article per source file at the same addresses. Reading diverges, and that divergence is most of the cost story below. The flat line at the bottom is the notepad: zero calls, with its offer wire-proven on every request of its run. Hover the curves for running counts. From the sealed adoption audit.

The Bill

With correctness equalized, the fold halves it

The two store runs are the campaign's closest thing to a controlled comparison: same store, same plan, fourteen correct and none wrong on each. The fold delivered that at $100.85 and native compaction at $201.70. The interesting part is what the factor of two is made of. It is not fatter prompts: per provider request, the two arms paid within a tenth of a cent of each other. The driver is turns. Native compaction needed nearly twice the provider requests for the same sixty-four stages. More than half of that gap is its own heavier store reading. It paid its summarizer out of band on top of that. Wall clock ordered the same way: about five hours against about nine.

Two bills, one price per request

fold deterministic + store: 916 provider requests, $100.85 total. native compaction + store: 1,700 provider requests at the same per-request price, $186.97 of message spend, plus $14.73 of out-of-band summarization, $201.70 in all. Per request: 11.0 cents against 11.0 cents.

Every dot is twenty-five provider requests, and every request cost about eleven cents on both arms. The gap is the number of dots, not their size, plus the summarizer's separate bill at the end of the native row. Same store, same score, twice the turns. Watch the rows fill; hover a row for its exact ledger. From the sealed cost audit.

The Shape

What to build, and what stays open

The shape this campaign recommends is the one its composed runs support: deterministic rotation beside durable retention. Every fold carries the runtime's own brief, built from the exact bytes it hides, and the knowledge worth keeping lives in a store outside the window. The store is named generically on purpose. The campaign ran canon because it is the store this line built, but the fold asks only for a place where durable knowledge can live and an address the agent can follow back. A store with those two properties should compose the same way, though only that one was tested here.

The two halves cover each other's exposure, which is the argument for pairing them. Rotation is the cheap half: deciding what has gone stale needs no judgment, only a rule, so it runs constantly and mechanically and costs close to nothing. What makes mechanical eviction safe is that the knowledge worth keeping is already filed somewhere with an address on it. And an addressed store is a better thing to read than a raw transcript, which is where the fold alone is exposed: the two weak draws had every byte they needed still sitting in the session and never went to get it.

One question the campaign sharpens rather than settles: every fold announces itself with a standing invitation for the agent to improve its brief, and an agent's note can augment the deterministic head but never replace it. The winning draws ran with that announcement silenced, and the campaign is why the switch is now public. Whether the invitation should stay the default is the open question, because the one run that leaned into annotation produced the campaign's worst score, with the errors tracking the annotations.

What This Does Not Show

A case series, and the claim that survives it

One model, one provider, one repository, one workload family. It is a sequential case series, with the adaptive changes disclosed in the paper's methods. The fold condition's four draws split into two modes, and that spread rides every single-run comparison here. The composed conditions are one run each, so the store's zero-wrong is two for two and suggestive, not established. Dollar ratios depend on this provider's price tiers, though the ratio survives a flat-rate counterfactual outright. Exam scores are the composed system's, mechanism plus recovery, with per-run recovery attribution published beside them. These cases motivate replication. They do not estimate population rates. The claim that survives the limits is narrow and, within them, exact: rotation and retention are different jobs, and the campaign's best result came from giving each to the component built for it.

The Paper

Sealed, hashed, and recomputable

The full report is published as Rotation and Retention, Zenodo, August 2026. The campaign is sealed under a hash-pinned manifest: one frozen plan, eight graded runs with hash-chained ledgers, and every model-written byte captured. Every scored number on this page is derived by a checked-in builder reading sealed artifacts, the figure data regenerates byte-identically, and a verification script re-runs the chain and refuses drift. The deposit beside the paper carries the plan, the manifests, the builder outputs, and the figure sources.

Citations

The trail behind this page

This paper. Shane Conner, "Rotation and Retention", Zenodo, August 2026. DOI: 10.5281/zenodo.22142456.

The line it closes. Part 1, "pi-fold: Agent-Governed Lossless Context Folding", DOI: 10.5281/zenodo.21856873; Part 2, "pi-fold: Working Memory Under Context Shedding", DOI: 10.5281/zenodo.21980746; Part 3, "Ephemeral Retrieval", DOI: 10.5281/zenodo.22142454.

The store's own line. canon, four papers measuring the memory store the way this line measures the fold, from canonical memory through durable retention: shaneconner.com/projects/pi-canon.

The narrative version. Shane Conner, "A Compaction Summary Is One Record Doing a Store's Job", Medium, August 2026: medium.com/@shane.conner/a-compaction-summary-is-one-record-doing-a-stores-job.

fold. The runtime, its gate suite, and the experiment harness that produced every number above: github.com/shaneconner/fold. On npm as pi-fold, MIT licensed.

Pi. The coding agent this runtime lives inside: github.com/badlogic/pi-mono.

curl. The studied codebase, hash-pinned in the sealed plan: curl.se.

Tech Stack

TypeScript D3.js Pi canon Context Management Benchmark Design
View Source → ← All Projects