Understand Pi's /compact context compaction logic
Session from pi-mono-sessions on Hugging Face by thomasmustier · MIT · condensed by Coders Talk
Click a segment to jump to that moment
33msession
0interventions
by library · 2d
GOAL
Understand how Pi's /compact command generates its compaction summary and what gets exposed to the agent afterward, including cut-point and split-turn behavior.
- +0Prompt · +0How does Pi currently compact? Explain in simple terms how /compact generates the summary and what's exposed to the agent post-compaction.
- +0mAgent did · +0mSearched the codebase for compaction logic, read compaction.ts, session-manager.ts, messages.ts, and interactive-mode.ts, and summarized how /compact picks a cut point, keeps a recent token tail, and generates a checkpoint summary.
- +14mPrompt · +14mCan you illustrate with an example of what the assistant sees post-compaction? Does the recent tail include tool calls and responses? How long is the tail?
- +15mPrompt · +15mWhat do you mean by 'if the cut splits a turn'?
- +15mAgent did · +15mTraced findTurnStartIndex and findCutPoint to explain that a turn runs from a user message through assistant/tool activity, and a split turn occurs when the cut lands mid-turn, requiring a separate turn-prefix summary appended to the main summary.
- +28mPrompt · +28mExplain the turn-prefix behavior in plain English. Isn't every compaction landing on a split turn? When would /compact not do this?
- +28mAgent did · +28mRead findValidCutPoints and findCutPoint in detail, clarifying that cut points never land on tool results, and explaining when a cut can land exactly on a user message (no split) versus mid-turn.
- +31mPrompt · +31mIn what scenario does the cut point fall exactly on a user message? And is a split turn always the oldest turn in the kept tail, with a turn summary substituted for it?
- +33mOutcome · +33mConfirmed via code (compaction.ts) that a split turn is always the oldest turn in the kept tail, and pinned down exactly which messages form the 'prefix' summarized before the cut point.
VERDICT
I'd start by asking the agent to trace findCutPoint and findTurnStartIndex directly instead of doing broad rg searches first, since that's where the real logic lives. Repeatedly pushing back with 'what do you mean by X' forced it to ground its explanations in exact line numbers rather than hand-wavy summaries, which is what actually clarified the split-turn behavior for me.