Module: Xeno::Compaction
- Included in:
- TurnRunner
- Defined in:
- lib/xeno/compaction.rb
Overview
Summarize-and-replace compaction, mixed into TurnRunner and executed as a claimed turn (kind: "compaction"). Riding the turn machinery buys the hard properties for free: the claim CAS makes it exclusive, session ordering queues it behind an active or parked turn, the heartbeat covers the summary model call, and a crash replays it (the applied result is recorded on the turn row, so replay never compacts twice).
Shape: the system prompt survives untouched; the most recent
compaction_tail_turns user-anchored turns survive verbatim (a tail cut
at a user row can never separate an assistant's tool calls from their
results); everything between is summarized by a throwaway model call
(the active model, never persisted) and REPLACED — the summary is
written into the earliest compacted row so both id- and created_at-
ordering keep it in place, and the remaining rows are destroyed
newest-first (results before the tool_calls they reference).
Constant Summary collapse
- SUMMARY_PREFIX =
"[Conversation summary — earlier messages were compacted]".freeze
- COMPACTION_PROMPT =
<<~PROMPT.freeze You are compacting an agent conversation to reclaim context space. Write a dense summary of the transcript below; it will REPLACE those messages permanently. Separate completed work and decisions from remaining or open work. Retain every constraint, preference, fact, identifier, amount, and reference a future turn could need. Output only the summary text. PROMPT