pub enum CompactionState {
Ready,
CompactedThisTurn {
cooldown: u8,
},
Cooling {
turns_remaining: u8,
},
Exhausted {
warned: bool,
},
}Expand description
Lifecycle state of the compaction subsystem within a single session.
Replaces four independent boolean/u8 fields with an explicit state machine that makes invalid states unrepresentable (e.g., warned-without-exhausted).
§Transition map
Ready
→ CompactedThisTurn { cooldown } when hard compaction succeeds (pruning or LLM)
→ CompactedThisTurn { cooldown: 0 } when focus truncation, eviction, or proactive
compression fires (these callers do not want post-compaction cooldown)
→ Exhausted { warned: false } when compaction is counterproductive (too few messages,
zero net freed tokens, or still above hard threshold after LLM compaction)
CompactedThisTurn { cooldown }
→ Cooling { turns_remaining: cooldown } when cooldown > 0 (via advance_turn)
→ Ready when cooldown == 0 (via advance_turn)
Cooling { turns_remaining }
→ Cooling { turns_remaining - 1 } decremented inside maybe_compact each turn
→ Ready when turns_remaining reaches 0
NOTE: Exhausted is NOT reachable from Cooling — all exhaustion-setting sites in
summarization.rs are guarded by an early-return when in_cooldown is true.
Exhausted { warned: false }
→ Exhausted { warned: true } after the user warning is sent (one-shot)
Exhausted { warned: true } (terminal — no further transitions)turns_since_last_hard_compaction is a metric counter, not part of this state machine,
and remains a separate field on ContextManager.
Variants§
Ready
Normal state — compaction may fire if context exceeds thresholds.
CompactedThisTurn
Hard compaction (or focus truncation / eviction / proactive compression) ran this turn.
No further compaction until advance_turn() is called at the next turn boundary.
cooldown carries the number of cooling turns to enforce after this turn ends.
Cooling
Cooling down after a recent hard compaction. Hard tier is skipped; soft is still allowed.
Counter decrements inside maybe_compact each turn until it reaches 0.
Exhausted
Compaction cannot reduce context further. No more attempts will be made.
warned tracks whether the one-shot user warning has been sent.
Implementations§
Source§impl CompactionState
impl CompactionState
Sourcepub fn is_compacted_this_turn(self) -> bool
pub fn is_compacted_this_turn(self) -> bool
Whether hard compaction (or a compaction-equivalent operation) already ran this turn.
When true, maybe_compact, maybe_proactive_compress, and
maybe_soft_compact_mid_iteration all skip execution (CRIT-03).
Sourcepub fn is_exhausted(self) -> bool
pub fn is_exhausted(self) -> bool
Whether compaction is permanently disabled for this session.
Sourcepub fn cooldown_remaining(self) -> u8
pub fn cooldown_remaining(self) -> u8
Remaining cooldown turns (0 when not in Cooling state).
Sourcepub fn advance_turn(self) -> Self
pub fn advance_turn(self) -> Self
Transition to the next-turn state at the start of each user turn.
Must be called exactly once per turn, before any compaction, eviction, or
focus truncation can run. This guarantees that is_compacted_this_turn()
returns false when the sidequest check executes — preserving the invariant
that the sidequest only sees same-turn compaction set by eviction which runs
after this call.
Transitions:
CompactedThisTurn { cooldown: 0 }→ReadyCompactedThisTurn { cooldown: n }→Cooling { turns_remaining: n }- All other states are returned unchanged.
Trait Implementations§
Source§impl Clone for CompactionState
impl Clone for CompactionState
Source§fn clone(&self) -> CompactionState
fn clone(&self) -> CompactionState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactionState
impl Debug for CompactionState
Source§impl PartialEq for CompactionState
impl PartialEq for CompactionState
impl Copy for CompactionState
impl Eq for CompactionState
impl StructuralPartialEq for CompactionState
Auto Trait Implementations§
impl Freeze for CompactionState
impl RefUnwindSafe for CompactionState
impl Send for CompactionState
impl Sync for CompactionState
impl Unpin for CompactionState
impl UnsafeUnpin for CompactionState
impl UnwindSafe for CompactionState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request