# ADR-0017: Pi-Model-Aware Compaction — Per-Model Context Thresholds

**Status:** Accepted
**Date:** 2026-05-13
**Package:** `pi-model-aware-compaction@0.1.5`
**Maintainer:** @w-winter | **Repo:** github.com/w-winter/dot314
**Last published:** 6 days ago | **Publish cadence:** ~1/week

## Problem

Fixed compaction threshold is suboptimal across models with different context windows:

| Model                | Context | Compaction Sweet Spot |
| -------------------- | ------- | --------------------- |
| Claude Opus/Sonnet 4 | 200K    | ~160K                 |
| Qwen 3.6-27B         | 128K    | ~100K                 |

Too early = useful context lost. Too late = truncation.

## Decision

Per-model `reserveTokens` and `keepRecentTokens` thresholds. Hooks into pi's built-in compaction (`settings.json`):

```json
"compaction": { "enabled": true, "reserveTokens": 16384, "keepRecentTokens": 20000 }
```

Model detection at session start → applies correct thresholds automatically.

## Alternatives

| Approach        | Why Rejected                          |
| --------------- | ------------------------------------- |
| Fixed global    | Suboptimal for every model except one |
| No compaction   | Hits context limit                    |
| User-configured | Error-prone                           |

## Trade-offs

New models need threshold config. Falls back to defaults (safe but suboptimal) if model not in registry.

## References

- [npm](https://www.npmjs.com/package/pi-model-aware-compaction)
- arXiv 2604.18071: "hybrid and hierarchical context strategies"
- [Agentic Harness Engineering](https://arxiv.org/abs/2604.25850) — "harnesses mediate how models interact with tools"
