# Compaction is a state transition

Suppose a model has just read a large log. The next request exceeds its context window. Deleting arbitrary old messages may discard the user's correction or leave a tool result without its call. Summarization can retain intent, but it changes the representation from which the agent continues.

Ask four questions: **what triggers compaction, what survives, when the result is adopted, and what remains available for replay?**

| Harness | Trigger and transformation | State consequence |
| --- | --- | --- |
| Codex | Thresholds and full-context limits; model/capability changes can matter. Client-managed and provider-supported remote summaries are separate paths. Token-budget rollover can occur without summarization. | Replacement history and context-window metadata affect reconstruction. Optional background summaries are adopted at defined checkpoints after compatibility checks. |
| pi | Estimated context use approaches the window minus reserved tokens; overflow recovery is another path. Summaries retain a recent tail and handle split turns. | Compaction entries project the next model context without erasing the raw append-only session history. |
| Goose | Token thresholds or context errors can trigger compaction; providers managing their own context are a separate case. | Older messages become hidden from the model; summary/continuation records are inserted. Storage updates visibility and summary records transactionally. |

Sources: [Codex context checks][c-context] and [background adoption][c-background], [pi compaction][p-context] and [session projection][p-projection], [Goose compaction operation][g-context] and [storage update][g-compaction-store].

**Design implication:** a background summary is computed against an older history. If the user changes the task while it is running, blindly replacing current context can lose that correction. Capture the input boundary, check compatibility when adopting, and preserve subsequent input. Do not confuse a summary successfully generated with a summary safely installed.

For an experienced builder, test compaction alongside tool-call/result pairing, model switches, user corrections, forks, cancellation, failed summaries, and overflow retries. A good summary of a static transcript does not test these transitions.

## Sidekick: trimming is not summary compaction

Sidekick’s native loop rebuilds request context from stored messages each iteration. Its optional pipeline strategy replaces old, large tool outputs with placeholders while preserving tool-result identifiers. That changes the request projection, not the saved history. The inspected factory does not establish full-history summary checkpoints or automatic summary-compaction recovery. Configuration fields naming a summarization model do not establish those behaviors. An external Outpost runtime may manage its own context. [Pipeline][s-context], [trimming strategy][s-trim] (private source).

[c-context]: https://github.com/openai/codex/blob/8c076942cb70fba8e5c4732c23f1faabc4aed484/codex-rs/core/src/session/context_window.rs#L1-L130
[c-background]: https://github.com/openai/codex/blob/8c076942cb70fba8e5c4732c23f1faabc4aed484/codex-rs/core/src/session/async_compaction.rs#L40-L214
[p-context]: https://github.com/earendil-works/pi/blob/482c1381a00d8d00bc81697e4a980c593db6803e/packages/coding-agent/src/core/compaction/compaction.ts#L789-L922
[p-projection]: https://github.com/earendil-works/pi/blob/482c1381a00d8d00bc81697e4a980c593db6803e/packages/coding-agent/src/core/session-manager.ts#L483-L589
[g-context]: https://github.com/aaif-goose/goose/blob/34a222e3f2b95d8b4a43482b53c2cc957ecce26d/crates/goose/src/agents/state_machine/ops_compaction.rs#L184-L295
[g-compaction-store]: https://github.com/aaif-goose/goose/blob/34a222e3f2b95d8b4a43482b53c2cc957ecce26d/crates/goose/src/session/session_manager.rs#L2198-L2255

[s-context]: https://github.com/datex/sidekick/blob/463d653124e1c2cda46a3f14f01f3d6f384326b1/backend/src/sidekick/services/context_pipeline/factory.py#L34-L117
[s-trim]: https://github.com/datex/sidekick/blob/463d653124e1c2cda46a3f14f01f3d6f384326b1/backend/src/sidekick/services/context_pipeline/processors/limits.py#L13-L157
