Skip to content

fix: redesign compaction to never alter chat history#67

Merged
platypusrex merged 1 commit intomainfrom
fix/compaction-redesign
Feb 22, 2026
Merged

fix: redesign compaction to never alter chat history#67
platypusrex merged 1 commit intomainfrom
fix/compaction-redesign

Conversation

@platypusrex
Copy link
Contributor

Summary

  • Compaction no longer alters chat history — full conversation is always displayed, compaction only affects what gets sent to the model
  • Replaced snapshot-based compaction with summary message pointer (summary_message_id on sessions)
  • Agent loop uses real prompt_eval_count from model for compaction decisions instead of character heuristic alone
  • Auto-retry on "prompt too long" errors (summarize then re-submit)

Closes #61

Follow-on issues

Closes #61

Compaction has been fully redesigned so that chat history is never altered.
Compaction only affects what gets sent to the model.

Part A — Compaction redesign:
- Add summary_message_id to sessions table (migration v4), drop message_snapshots
- Remove all snapshot CRUD and fromOllamaMessages (~180 lines)
- Split message store: displayMessages (full history) vs history (summary-aware slice)
- Summarizer as separate Ollama call with structured 6-section prompt
- CompactionSummaryPart renders inline in chat

Part B — Token accuracy (core fix):
- Agent loop uses real prompt_eval_count from model for compaction decisions
- buildContextUsage() prefers real token counts over heuristic
- Sidebar preserves real counts (hasRealCounts flag prevents heuristic overwrite)
- CHARS_PER_TOKEN.mixed 3→2.5, OVERHEAD_AGENT_LOOP 4k→6k

Part C — Auto-compaction trigger:
- Agent returns needsSummarization flag (caller handles summarization)
- promptTooLong detection with auto-retry (summarize then re-submit)
- Post-run auto-summarization when needsSummarization flag set
- Manual /compact command calls summarizeConversation directly

Remaining token accuracy improvements deferred to #64.
Observational memory (hybrid approach) tracked in #65.
Summary quality improvements tracked in #66.
@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

⚠️ No Changeset found

Latest commit: 55040b5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@platypusrex platypusrex merged commit e1d53df into main Feb 22, 2026
1 check passed
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.

fix: redesign compaction — never alter chat history, fix token accuracy, use subagent for summarization

1 participant