Folio — Recoverable context folding vs lossy compaction — What does it mean?
The news. On November 12, 2026, the Folio paper was posted to arXiv. With DeepSeek-V4-Pro behind every system, Folio solved 66 of 75 LOCA-bench tasks (a benchmark of tool-using tasks whose context keeps growing), against 54 for the same runtime with model-written compaction and 49–59 for Claude Code, Codex and SoL-Pi. It took about 10.2 minutes per task against 16.3–21.0, cost about 2.4× less than the same runtime with model-written compaction, and each fold took a median 0.6 seconds. Read the paper →
Two clerks, one overflowing case file
Picture a court clerk whose desk is full. The first clerk reads every page, writes a two-page memo, and shreds the originals. The memo is probably good. But if the judge later asks for row 102 of exhibit 12, and the memo did not mention it, the answer is gone for good. The second clerk keeps a short index on the desk and moves every exhibit into a locker under its tag number. The desk is just as clear, and any exhibit can be fetched back exactly.
Model-written compaction is the first clerk. When the context window fills, the harness sends the history to a model and replaces it with the summary it returns. Each compaction rereads everything it replaces, so it costs a full model request and minutes of wall-clock time, and the link between the summary and the original text is whatever the summary happened to say.
Folio is the second clerk. While the agent runs, it records the history at three levels at once: a turn note the model writes as part of its normal reply (L1), an event manifest row the runtime writes for each call (L2), and the full source records of every tool result (L3). Because all three views already exist, a fold is just a choice of which view to show for each old turn. By default the newest closed turn keeps its manifest rows, the two before it keep their full notes, and older turns shrink to a goal and an outcome; the planner then demotes or upgrades turns to fit the budget. Every row still prints its handle, such as t3.12.
Reading an exhibit back, without re-running the tool
An index is only useful if the locker opens. Folio gives the agent three tools that all take the handles the outline prints. scan reads a bounded page of one call's output, by line range or by search, capped at 200 lines and 8K tokens. ctx binds the full text of a call to a file, runs a shell or Python command the agent writes over it, and returns only the answer. dossier keeps findings, each stored with the handle it came from, and every later fold carries the dossier forward.
The paper's case study shows why ctx matters. An exam-scheduling task fetched course announcements across a range of calls totalling 793 KB. After a fold, the agent ran one ctx command over that whole range and received 6.4K tokens back; the 793 KB never re-entered the context window.
Why not just call the tool again, the way some compaction schemes keep a tool-call signature to re-run later? Because the history is a record of what was observed, not of the world now. A database query run again may return different rows, and a write run again may repeat its side effects — the idempotency problem. Folio's recovery reads what was captured, so the agent can check the captured value it based its earlier decision on. If the runtime cut a large result before routing it to the model, the complete output may be available in a separate file; if that file is missing or too large, scan returns the cut copy and says so.
When to fold is a cache-pricing question
Every request re-sends the history, and the provider bills most of it at the cheap cached-read rate. A fold breaks that cache: everything above the fixed prefix (system prompt and tool definitions) must be written again at a higher price. So a fold is worth doing only when carrying the extra history has cost more than rebuilding. Folio's trigger adds up the cached tokens each request carried above the landing point, and folds when that total reaches the price of rebuilding the landing point. The landing point includes the kept outline and the dossier, which a plain restart model treats as zero.
This is the opposite of the common rule in the baseline, which compacts at 90% of the window. With a 1M-token window, that baseline's requests carried up to about 900K tokens before each compaction, and it read 3.5× as much input as Folio over the same tasks.
Worked example (illustrative). Hold three things fixed: a landing point of 64K tokens, of which 4K is the fixed prefix, so a fold rewrites 60K tokens; a rewrite price of 10× a cached read; and a context that grows by 8K tokens per request. One cached-read token is 1 unit. A fold costs 60K × 10 = 600K units. After the fold, request 1 carries 8K above the landing point, request 2 carries 16K, request n carries 8K × n, so the running total is 4K × n × (n + 1). That reaches 600K at n = 12 (4K × 12 × 13 = 624K). The trigger folds after 12 requests, when the context is about 64K + 96K = 160K tokens — not at 900K. In the paper's real runs, the median fold took the context from 242K to 64K tokens (about 7.3× compression of the folded history) in a median 613 ms, with no model request.
| Per fold or compaction (medians) | Folio fold, 1M window | Model-written compaction, same runtime |
|---|---|---|
| Model requests | 0 | 1 per compaction (24 total) |
| Latency | 613 ms | 101 s |
| Context before | 242K tokens | 908K tokens |
| Context after | 64K tokens | 58K tokens |
| Exact original still readable? | Yes, through the handle | No, only the summary remains |
What the evidence does and does not show
The ablations (runs with one part of Folio removed) point at the outline, not the extras. Removing the multi-level outline, so the fold keeps only raw recent results, made the context refill faster: 31 folds instead of 16 and 63% higher cost per task on one 15-task chain. Removing the dossier or the turn notes changed success by one to three tasks out of 75, which the authors say is within run-to-run variation. Removing scan and ctx dropped one chain from 13 to 8 successes, but three of those failures were timeouts or agent errors in a run with many provider retries.
There is also a real dial here. Sweeping the landing budget from 10K to 70K tokens cut folds per chain from 49 to 13 and reads of folded content from 144 to 12: a smaller desk means more trips to the locker. Cost was lowest near 30K. Two limits to keep in mind: every result uses one model and one benchmark, and the recoverability guarantee covers only what the runtime captured — it says nothing about whether the agent asks for the right exhibit.
Goes deeper in: AI Agents → Context Engineering → The 4 Fixes
Related explainers
- CliffCompaction — the other non-model compactor: it drops long tool results and keeps call signatures to re-run, where Folio keeps the captured output itself.
- KVMem — the same never-delete idea one level down, keeping old context as paged KV blocks instead of text.
- AutoCompact — a different answer to when to compact: a trained policy instead of a cost rule.