`src/engine/bare/compact.rs` — the driver side of compaction
run_compaction and the hook/observer choreography for a Compact step.
Key items
run_compaction(turn, reason) -> CompactStepOutcome { tokens_before, tokens_after, compacted: Option<Vec<Message>> }:- measure the true size (conversation + overhead — real measurements, never estimates-at-request-time);
- no
ContextManager→ unchanged outcome; - pre-compact hook veto → unchanged outcome (hook guidance merged and threaded when not vetoing);
compact_with_reason(history, turn, reason, instructions, additional_context, reserved)—reserved= overhead + the deferred turn’s transients budget;Compacted→ fireon_compaction+ post-compact hooks, return the new messages;NoAction→ re-measure, return unchanged;Err(overflow)→ log +LoopError::ContextExceeded.
Behavior notes
- The handler feeds
compaction_result(rewritten) vscompaction_noop(unchanged) — the machine’s no-progress guard applies to both. - Observers and post-compact hooks fire only on real compactions — no-op passes are silent.
- Vetoed passes at over-threshold end the run via the guard — documented, deliberate.
Deep dive: Compaction.