record_in_budget appends a turn and, when the context then runs past
its budget, summarizes the oldest items (turns and earlier summaries)
into one summary that stands for them in the context; the session keeps
every turn. A pinned turn, the person's instruction, is never covered;
the most recent turns up to a stated size are kept as they were. A
later compaction folds an earlier summary in and marks it superseded,
so every summary the context held stays on record. Each summary's
joules count in the session's total. A fork keeps its prefix's pins
and the compactions made wholly of it, recomputing which are
superseded, so one superseded only past the fork point is live there.
A session saved before compaction existed loads unchanged.
Falsified, each turns a test red: pins summarized, summary energy
dropped, earlier summaries never superseded, a fork keeping the source's
superseded flag, and the recent tail not kept.
Co-Authored-By: Claude Opus 5.5 <[email protected]>