# Behavior

## Checkpoint lifecycle

1. The agent calls `self-compact`, or the user runs `/autocompacter`.
2. The extension stores one request. A second request does not replace it.
3. Pi finishes the current assistant turn and its tool calls.
4. The extension summarizes the complete context preview. This preview includes the turn's tool results.
5. The extension adds a self-retaining Pi compaction entry.
6. A requested checkpoint starts the next model turn. The agent resumes from the summary.

An aborted or failed turn cancels a queued tool request. Session replacement also cancels stale work. An existing compaction at the same boundary prevents a duplicate.

Notice and warning messages start a model turn. The extension sends each level once per cycle. This rule prevents a notice loop. Force creates a checkpoint instead of a notice.

## Automatic force

The extension checks estimated token use at each completed turn. It compacts at the active force limit. A turn with tool results or pending messages continues after compaction. A completed response without pending work does not create an extra model turn.

The extension waits 10 seconds after a checkpoint. This cooldown prevents repeated requests without new work.

## Errors

A summary error leaves the session context unchanged. The extension adds a visible error message. Requested work and turns with pending work can continue from the original context.

Retry delays are 5, 10, and 20 seconds. The delay applies when a later turn reaches its boundary. The extension does not run a background timer. Three failures pause automatic attempts. `/autocompacter` clears the failure state and tries again.

## Settings and models

The extension reads settings from the current project at session start. A session tree change reloads them. A model change resets threshold notices.

The active force limit is the smallest of these values:

- The saved force limit.
- 270,000 tokens.
- 80% of the model context window.

Notice and warning scale by the same ratio as force. The three active values stay distinct.

## Nonterminal use

Both commands work in TUI, print, JSON, and RPC modes. The setup wizard needs a dialog-capable UI. In other modes, use the `set` or `reset` command form.
