Skip to content

fix: compaction bugs #13946 and #13980#14245

Open
andrea-tomassi wants to merge 1 commit intoanomalyco:devfrom
andrea-tomassi:fix/compaction-bugs
Open

fix: compaction bugs #13946 and #13980#14245
andrea-tomassi wants to merge 1 commit intoanomalyco:devfrom
andrea-tomassi:fix/compaction-bugs

Conversation

@andrea-tomassi
Copy link

@andrea-tomassi andrea-tomassi commented Feb 19, 2026

Issue for this PR

Closes #13946
Closes #13980

Type of change

  • Bug fix

What does this PR do?

This PR fixes two separate bugs in the compaction logic, both of which I hit while running opencode in headless/daemon mode.

Fix #13946 — Compaction crash in headless mode

When the compaction processor runs and the summary itself exceeds the context window (result becomes "compact"), the code path that creates the synthetic "Continue..." user message was being skipped. That message is what lets the next turn resume — without it, opencode run exits silently mid-session instead of continuing. The fix adds a check for result === "compact" alongside the existing result === "continue" check so the resume message is always created when running in auto mode.

Fix #13980compaction.reserved ignored for Claude / models without limit.input

The shouldCompact function computes how many tokens are "usable" before triggering a summary. For models that do have limit.input set, it correctly subtracts the reserved buffer. But for models that only have limit.context (e.g. Claude via GitHub Copilot), the fallback branch was computing context - maxOutputTokens, ignoring the configured reserved value entirely. This made it impossible to tune the compaction threshold on those models. The fix applies context - reserved in the fallback branch, consistent with the behavior for models with explicit input limits.

How did you verify your code works?

  • Ran the patched binary as the backing process for a persistent AI assistant that triggers compaction regularly. Confirmed opencode run no longer exits after compaction turns, and that the reserved threshold is respected correctly across sessions.
  • Ran turbo typecheck — no type errors.

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings February 19, 2026 07:00
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two critical bugs in the compaction system that could cause opencode run to exit prematurely and prevent users from tuning compaction thresholds.

Changes:

  • Fixed #13946: Ensures synthetic "Continue..." message is created even when the compaction processor itself overflows, preventing premature exit in headless mode
  • Fixed #13980: Makes compaction.reserved configuration apply consistently to models with and without explicit limit.input, allowing users to tune the compaction threshold

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant

Comments