Skip to main content

CompactionState

Enum CompactionState 

Source
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.

Fields

§cooldown: u8

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.

Fields

§turns_remaining: u8

Remaining cooling turns before returning to Ready.

§

Exhausted

Compaction cannot reduce context further. No more attempts will be made. warned tracks whether the one-shot user warning has been sent.

Fields

§warned: bool

Whether the user has already been notified of context exhaustion.

Implementations§

Source§

impl CompactionState

Source

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).

Source

pub fn is_exhausted(self) -> bool

Whether compaction is permanently disabled for this session.

Source

pub fn cooldown_remaining(self) -> u8

Remaining cooldown turns (0 when not in Cooling state).

Source

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 }Ready
  • CompactedThisTurn { cooldown: n }Cooling { turns_remaining: n }
  • All other states are returned unchanged.

Trait Implementations§

Source§

impl Clone for CompactionState

Source§

fn clone(&self) -> CompactionState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompactionState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CompactionState

Source§

fn eq(&self, other: &CompactionState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for CompactionState

Source§

impl Eq for CompactionState

Source§

impl StructuralPartialEq for CompactionState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more