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’scompaction.modelOverrides["provider/id"], else the ordinary setting, else the default (16384 reserved, 20000 kept).enabledoverrides the setting (set_auto_compactionon 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 thanreserveTokensof the window.pathis the branch, oldest first;tokens_beforethe preparation’s context estimate.