Documentation / guides
Automatic Compaction
Describe automatic compaction triggered by context pressure and reported by exact compaction events.
Automatic compaction is a context-pressure response. The Loop measures the complete request, records the basis and fingerprint, and coordinates one automatic attempt only when policy and pressure allow it.
Trigger sequence
- Resolve model context limits using
ReservedOutputandSafetyMargin. - Count the complete inference request with the policy timeout.
- Compute occupancy and pressure against
CompactAtand full scale. - If eligible at a safe boundary, coalesce the automatic request with any
current waiters and publish
CompactionStarted. - Run the registered blocking current-Loop Hustle and validate its result.
- Append
CompactionCommittedorCompactionRejected, then waiter replies.
PressureHardLimit without a new eligible attempt is a typed context-limit
failure. Automatic pressure never bypasses a pending interrupt or shutdown.
Proof: automatic context tracking, control loop, and automatic tests.
One attempt per basis
The context tracker stores the automatic basis that has already been exhausted.
Repeated measurements at or above CompactAt join the pending attempt or wait
until RearmBelow is crossed. Manual compaction does not consume this
automatic-basis marker.
%%{init: {"theme":"dark"}}%%
sequenceDiagram
participant L as Loop actor
participant C as context counter
participant K as compaction control
participant H as compaction Hustle
L->>C: count complete request
C-->>L: measurement and basis
L->>K: automatic request at boundary
K->>K: coalesce waiters and freeze basis
K->>H: exact input after Started
H-->>K: validated output or typed rejection
K-->>L: durable terminal and rearm state
Proof: automatic basis tracking and automatic/manual interaction tests.
Event observation
Automatic attempts use event.CompactionReasonAutomatic. CompactionStarted is
public and ephemeral; CompactionCommitted or CompactionRejected is public
and enduring. A caller waiting on a compact command receives the deterministic
waiter reply after the terminal event is durably appended.
Proof: compaction events and publication tests.