[PR #11453] fix(opencode): prevent context overflow during compaction #13796

Open
opened 2026-02-16 18:18:37 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11453

State: open
Merged: No


Target --> fix for : https://github.com/anomalyco/opencode/issues/11450

Using opencode often leads to exceeding token limits, even /compact fails to clean it up, getting the whole conversation stuck if the history is already too long

Screenshot 2026-01-31 alle 11 57 50

This PR adds
truncateForCompaction()
to
compaction.ts
which:

  • Calculates the available input budget (context limit - output reserve - prompt reserve).
  • Keeps existing summary messages (critical context).
  • Adds recent messages until the budget is full.
  • Truncates older messages to ensure the compaction request itself succeeds.

Fixes #11450

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11453 **State:** open **Merged:** No --- Target --> fix for : https://github.com/anomalyco/opencode/issues/11450 Using opencode often leads to exceeding token limits, even /compact fails to clean it up, getting the whole conversation stuck if the history is already too long <img width="735" height="435" alt="Screenshot 2026-01-31 alle 11 57 50" src="https://github.com/user-attachments/assets/814cffe4-6f03-4a76-bbc4-3081d83e0a47" /> This PR adds **truncateForCompaction()** to **compaction.ts** which: - Calculates the available input budget (context limit - output reserve - prompt reserve). - Keeps existing summary messages (critical context). - Adds recent messages until the budget is full. - Truncates older messages to ensure the compaction request itself succeeds. Fixes #11450
yindo added the pull-request label 2026-02-16 18:18:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13796