Skip to main content

Module auto_compaction

Module auto_compaction 

Source
Expand description

Automatic compaction of the root lane: the settings it runs with and when it starts. The session worker’s harness (packages/agent/src/harness/runtime/drive) compacts at a run’s checkpoints, before the run ends or before its next request, when the context crosses contextWindow - reserveTokens (checkpoint.ts, prepareCompactionThreshold), and on a response that overflowed the window, compacting and retrying the request once (response.ts, publishResponse). The session actor runs both (crate::core); this module is the arithmetic and the classification, ported from pi-ai isContextOverflow / isRecoverableLength and the settings manager’s getCompactionSettings.

Enums§

Reason
Why an automatic compaction runs (compaction_start.reason).

Functions§

as_error
normalizeError: an overflowed response as the error it is committed as.
is_context_overflow
pi-ai isContextOverflow(message, contextWindow): an error a provider uses for an oversized request, a successful response whose input exceeds the window (silent overflow), or a length stop with no output that filled it.
is_recoverable_length
pi-ai isRecoverableLength: a length stop below the output limit the request asked for.
may_be_due
Whether a threshold compaction can be due at all: automatic compaction is on and the model has a window. The cheap half of threshold_due, for callers that would otherwise build the whole context to learn nothing is due.
overflowed
publishResponse’s overflow: the response overflowed the window, or stopped for length below the requested limit; either one compacts and retries once.
settings
getCompactionSettings(model): compaction.enabled (default on), and each token setting from the model’s compaction.modelOverrides["provider/id"], else the ordinary setting, else the default (16384 reserved, 20000 kept). enabled overrides the setting (set_auto_compaction on a live session).
threshold_due
prepareCompactionThreshold: a threshold compaction is due at a checkpoint when compaction is on, the branch has no compaction at or after the checkpoint’s trigger entry, and the context leaves less than reserveTokens of the window. path is the branch, oldest first; tokens_before the preparation’s context estimate.