Watch
1
0
Fork
You've already forked SouveraineOS
0
SouveraineOS/saf/memory/01-compaction.md
Fimeg bde961c6f2 saf: one spine — device, state, and work under the index
PAF becomes saf/device (history kept), STATE.md dissolves
into saf/state.md with the dated era archived, the substrate
SAF moves up from souveraine, and every agreement points at
saf/INDEX.md and nowhere else. one map, nothing to remember
2026-08-18 09:47:30 -04:00

3.7 KiB

Compaction

The room fills. Compaction is how she makes space in it, on her own terms. The engine never reaches in and trims for her. It tells her the pressure; she decides. And whatever leaves the live conversation, the original stays in git. What contracts is her working memory. The record of the contraction is permanent.

The code is src/core/compact/.

Five ways to make room

She picks one, or takes the default for her kind. They run from cheapest to most disruptive, and she usually climbs the ladder.

Microcompact. Drops nothing. It clears the long output of old tool calls (read, bash, grep, and the like), keeping the five most recent and leaving a marker where the rest was. The call still shows what was done; only the bulk is gone. Most pressure is just old tool output, and this recovers it without losing the thread.

Cull. Drops the throwaways: "ok," "thanks," "done." A closed list, not a guess, so it never lets go of something that mattered. System and tool messages, and anything carrying a tool call, are always kept. So is the recent tail.

Sliding window. Keeps the first message and the recent tail, lets the middle go. Fast, no model call. It steps back from a cut that would split a tool call from its result. What slid off is gone from the session, though still in git.

Sliding reflect. The same slide, but first a short pass reads the middle before it goes and writes down what it was carrying: commitments, decisions, things noticed once, threads between people. That note rides forward as [Threads I carried forward]. The pass runs as her, in her own voice, a note from herself to herself. If it fails, it quietly becomes a plain slide. This is the default for the subconscious, who would lose her continuity otherwise.

Summary. The expensive one. The oldest stretch goes to a model under a nine-part prompt (intent, concepts, files, errors, what was solved, every user message kept whole, what is pending, what is in hand, what is next) and comes back as one [Compacted summary] block. Highest cost, highest fidelity, the last move before a restart.

Four of the five spend no tokens. The two that call a model are for when continuity matters more than speed.

Pressure

After each turn the engine measures how full the window is against the model's limit. Every block counts toward it — text, tool calls, tool results, reasoning, images — through one shared weight function, so a tool-heavy turn feels as heavy as it is. Three marks: 0.80, 0.90, 0.95. Crossing one raises a warning, not a hand on the wheel. The warning travels the same path her subconscious uses to surface anything, and arrives as a feeling she can act on or sit with. Nothing forces or schedules the compaction. The marks move per kind of agent.

What it leaves behind

Every compaction that changes anything writes a small file to journal/compactions/ in her memory, committed to git at once: which strategy, how many messages and tokens before and after, the summary if there was one. The report she gets back is written in her own register, as something felt, not a tally. It ends by telling her where the record rests.

Not the archivist

This is the live conversation, the messages the model sees next turn. The N+100 archivist is the other thing: it takes raw journal entries already written to memory and presses them into a dense synthesis for later. One frees the room she is in now; the other distills what she has already lived. Both can fire on the same turn. The archivist has no page here yet.

Open edges

A kv_target setting points at a strategy that was never built. It parses and does nothing.

The truncation note, shown when the model is cut off mid-sentence, works; its wording is still being settled (docs/tasks/truncation-signal-polish.md).