Skip to content

Conversation

@Hexecu
Copy link

@Hexecu Hexecu commented Jan 31, 2026

Target --> fix for : #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

@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.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, there are several related PRs that address similar context overflow and compaction issues, but no exact duplicates of PR #11453:

Related PRs:

  1. PR fix(session): prevent context overflow by adding safety margin to compaction check #6562 - fix(session): prevent context overflow by adding safety margin to compaction check

    • Earlier fix for context overflow prevention with safety margins
  2. PR feat(opencode): add context overflow prevention with configurable thresholds #8810 - feat(opencode): add context overflow prevention with configurable thresholds

    • Adds configurable thresholds for overflow prevention
  3. PR feat(opencode): trigger compaction earlier and add multi-file read #9656 - feat(opencode): trigger compaction earlier and add multi-file read

    • Related approach to handle compaction triggers earlier
  4. PR feat(session): add custom compaction thresholds along with prevention of continuous compaction #10123 - feat(session): add custom compaction thresholds along with prevention of continuous compaction

    • Adds custom thresholds and prevents continuous compaction
  5. PR fix(opencode): accumulate step tokens for compaction #10215 - fix(opencode): accumulate step tokens for compaction

    • Related token calculation for compaction decisions
  6. PR fix: add prompt caching to session compaction - Issue #10342 #10380 - fix: add prompt caching to session compaction - Issue #10342

    • Prompt caching for compaction optimization

These PRs all address the broader problem of context overflow and compaction, though PR #11453 introduces a specific truncateForCompaction() function that appears to be a more targeted solution.

@Hexecu
Copy link
Author

Hexecu commented Jan 31, 2026

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.

Fixes #11453 added

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.

ContextWindowExceededError during compaction (litellm & claude-opus-4.5)

1 participant