Skip to content

feat(chat): Add local context compaction - #432

Merged
dcramer merged 7 commits into
mainfrom
feat/local-context-compaction
May 28, 2026
Merged

dcramer merged 7 commits into
mainfrom
feat/local-context-compaction

Conversation

@dcramer

@dcramer dcramer commented May 28, 2026 •

Copy link
Copy Markdown
Member

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 numeric autoCompactionTriggerTokens value, while production thresholds come from active model metadata plus the primary AI_MODEL_CONTEXT_WINDOW_TOKENS override 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

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]>
@vercel

vercel Bot commented May 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 28, 2026 8:31pm

Request Review

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]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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]>
@dcramer
dcramer merged commit d621066 into main May 28, 2026
16 checks passed
@dcramer
dcramer deleted the feat/local-context-compaction branch May 28, 2026 20:43

This branch was successfully deployed

1 active deployment
Preview – junior-docs — b33f6b0e Deployed May 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant