Skip to content

Comments

feat: Closed#6374

Closed
ryanwyler wants to merge 4 commits intoanomalyco:devfrom
gignit:feature/collapse-compaction
Closed

feat: Closed#6374
ryanwyler wants to merge 4 commits intoanomalyco:devfrom
gignit:feature/collapse-compaction

Conversation

@ryanwyler
Copy link
Contributor

@ryanwyler ryanwyler commented Dec 29, 2025

Removed.

@ryanwyler ryanwyler force-pushed the feature/collapse-compaction branch 2 times, most recently from 4aa734a to 395b76b Compare December 29, 2025 17:50
@ariane-emory
Copy link
Contributor

Not really in favour of changing the defaults, new behaviour ought be opt-in IMO.

@ryanwyler ryanwyler force-pushed the feature/collapse-compaction branch 2 times, most recently from 41c4df7 to e51bdba Compare December 29, 2025 18:47
@ryanwyler
Copy link
Contributor Author

Not really in favour of changing the defaults, new behaviour ought be opt-in IMO.

Fixed it. Thank you for the feedback.

@ryanwyler ryanwyler changed the title feat: add collapse compaction mode feat: collapse compaction keeps the recent context perfect collapsing only the stale context keeping agent intelligent after compaction Dec 29, 2025
@ryanwyler ryanwyler changed the title feat: collapse compaction keeps the recent context perfect collapsing only the stale context keeping agent intelligent after compaction feat: Collapse Compaction maintains agent intelligence after compaction by preserving recent interactions and curating knowledge collapsing stale context Dec 29, 2025
@ryanwyler ryanwyler changed the title feat: Collapse Compaction maintains agent intelligence after compaction by preserving recent interactions and curating knowledge collapsing stale context feat: Collapse Compaction maintains agent intelligence beyond compaction by preserving recent interactions and curating knowledge collapsing the older stale messages Dec 29, 2025
@ryanwyler
Copy link
Contributor Author

ryanwyler commented Dec 29, 2025

Removed.

@ryanwyler ryanwyler force-pushed the feature/collapse-compaction branch 6 times, most recently from 34f527b to 42de421 Compare December 31, 2025 11:24
Adds a new 'collapse' compaction mode that preserves recent context while
summarizing older messages. Unlike standard compaction which summarizes the
entire conversation, collapse extracts the oldest 65% of tokens, summarizes
them at a breakpoint, and leaves the newest 35% untouched.

Changes:
- Add processCollapse() for breakpoint-based summarization
- Add Identifier.createLike() for inserting messages at past timestamps
- Add detectFormat() for backward compatibility with existing sessions
- Add configurable ratios: trigger (0.85), extractRatio (0.65), recentRatio (0.15)
- Add TUI toggle for switching between standard/collapse modes
- Fix isOverflow() to include cache.write tokens
- Fix link.tsx underline prop error from anomalyco#6317

Default remains 'standard' - users can opt-in to collapse via config or TUI toggle.
Adds support for merging historical context from previous compaction summaries
into new collapse summaries. This prevents loss of important information across
multiple compaction cycles.

New config options:
- summaryMaxTokens: target token count for summary output (default: 10000)
- previousSummaries: number of previous summaries to include (default: 3)

Changes:
- Add getPreviousSummaries() to fetch historical summaries from unfiltered messages
- Add extractSummaryText() to extract text content from summary parts
- Update collapse prompt to include previous summaries section
- Add merge instructions to preserve historical context
…arent-child message references

When forking a session, message IDs are regenerated but parentID references in assistant messages were not updated to point to the new IDs. This broke features that rely on parent-child relationships, such as compaction breakpoints.

## Problem

Forking a compacted session would fail with:
```
prompt is too long: 203573 tokens > 200000 maximum
```

The forked session didn't honor the compaction breakpoint because the parent-child message relationships were broken.

## Fix

Added an ID mapping that tracks old ID -> new ID, then updates parentID references when cloning assistant messages.

## Changes

- packages/opencode/src/session/index.ts - Add ID mapping in fork function to preserve parent-child relationships
…cture

- Calculate available token budget before fetching previous summaries
- Use XML-style delimiters for clearer prompt structure
- Add debug logging with [BUDGET_CALC] tag for troubleshooting
- Prevents context overflow when including previous summaries
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@ryanwyler ryanwyler changed the title feat: Collapse Compaction maintains agent intelligence beyond compaction by preserving recent interactions and curating knowledge collapsing the older stale messages feat: Closed Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants