Skip to content

fix(opencode): prevent context overflow during compaction#11453

Closed
Hexecu wants to merge 1 commit intoanomalyco:devfrom
Hexecu:fix/compaction-context-overflow
Closed

fix(opencode): prevent context overflow during compaction#11453
Hexecu wants to merge 1 commit intoanomalyco:devfrom
Hexecu:fix/compaction-context-overflow

Conversation

@Hexecu
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions bot closed this Apr 2, 2026
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