Repository navigation
feat(chat): Add local context compaction - #432
Merged
Merged
Conversation
Add a local context compactor that forks completed Pi checkpoints into bounded replacement history before fresh turns. Derive compaction thresholds from model context windows and let operators override missing or constrained context-window metadata. Preserve recent context in compaction summaries, retain recent user messages, avoid raw compaction prompt telemetry, and keep retry behavior deterministic for synthetic checkpoints. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Only compact Pi history when the loaded messages came from the completed reusable checkpoint. This keeps crashed or active-turn checkpoint history from being replaced by an older compacted session. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
Use the auxiliary model registry metadata for visible conversation compaction budgets. Keep the explicit context-window override limited to the primary agent model. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
Use Pi context estimation for automatic compaction triggers and keep the trigger conservative by comparing usage-based and structural estimates. This prevents tool-heavy checkpoints from bypassing compaction because they lack plain text content. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
Keep automatic pre-turn compaction as the only current service entry point and share checkpoint loading with token estimation. Remove the unused forced compaction path and expose the test threshold as a plain numeric override. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
dcramer
marked this pull request as ready for review
May 28, 2026 20:22
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4df7515. Configure here.
Start assistant status with explicit compaction progress once automatic compaction crosses its threshold, then restart the normal turn status before agent execution. This keeps long pre-turn summarization visible without adding user-facing compaction commands. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
Move the coarse text token heuristic into context-budget so Pi checkpoint compaction and visible conversation memory use the same local estimate. Refs GH-431 Co-Authored-By: GPT-5 Codex <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Add local context compaction for completed Pi checkpoints so long Slack threads keep bounded model history without a user-facing or manual compaction command. Junior summarizes reusable history locally, preserves recent user-authored context, and forks a synthetic completed checkpoint before the next turn uses it.
Before / After
Before, fresh turns reused raw completed checkpoint history until they approached the provider context limit. Conversation-state compaction used small fixed thresholds, and there was no local LLM pass to replace oversized Pi history with a bounded handoff.
After, fresh turns compact only reusable completed checkpoints when estimated history exceeds a model-window-derived threshold. Junior shows assistant progress while the compaction LLM pass runs, retains recent user messages, stores a deterministic synthetic checkpoint, and passes that replacement Pi history into the agent.
Compactor Contract
The current service exposes only
maybeCompact(...); there is no manual, forced, slash-command, or tool-exposed compaction path. Test overrides use a plain numericautoCompactionTriggerTokensvalue, while production thresholds come from active model metadata plus the primaryAI_MODEL_CONTEXT_WINDOW_TOKENSoverride when needed. Auxiliary-model visible conversation budgets use model registry metadata directly; there is no auxiliary context-window env override.Compaction Safety
The compactor refuses resumable checkpoints, avoids active crash-recovery history, counts structured Pi content such as tool calls and tool results when estimating trigger size, and captures only metadata attributes for compaction model calls.
Refs #431