Repository navigation
Regression in 1.14.48: context compaction breaks sessions with large MCP tool sets #27631
Description
Description
Starting with v1.14.48, opencode's context compaction behavior regresses for sessions with large MCP tool definitions. Sessions that worked correctly on v1.14.47 become unusable — context usage jumps erratically (3% to 68% in a single turn), compaction fails or produces incorrect results, and the session enters a degraded state where every turn re-sends the full bloated context.
v1.14.47 and earlier handle this correctly: context stays steady at ~61% per turn with auto-compaction working as expected.
Reproduction
Environment:
- Provider: Z.AI coding plan (GLM-5-Turbo, 200K context)
- MCP tools: 206 tools x 2 transports (SSE + stdio) = 412 tool definitions (approx 123K tokens overhead per turn)
- OS: macOS 26.4.1, Apple Silicon (M1 Air 8GB)
- Install method: Homebrew
Steps to reproduce:
- Install opencode v1.14.48 (or v1.14.49 / v1.14.50 — all affected)
- Configure MCP servers with a large tool set (~100+ tools)
- Start a session with any model on a provider with a moderate context window (200K tokens or less)
- Send 2-3 messages and observe context usage
Expected behavior (v1.14.47):
- First turn: ~123K tokens (61% of 200K) — steady
- Subsequent turns: ~400 tokens (cache hit) or ~123K (cache miss) — predictable
- Compaction triggers at the configured threshold and works correctly
- Context percentage stays stable between turns
Actual behavior (v1.14.48+):
- First turn: ~3% context usage
- Second turn: jumps to 68-90%+ context usage
- Context percentage fluctuates erratically between turns
- Session degrades progressively, becoming slower and less reliable
- Eventually becomes unusable without DB intervention
Workaround
Downgrade to v1.14.47:
# Download from GitHub releases
curl -L -o /tmp/opencode-1.14.47.zip \
https://github.com/anomalyco/opencode/releases/download/v1.14.47/opencode-darwin-arm64.zip
unzip /tmp/opencode-1.14.47.zip -d /tmp/opencode-1.14.47/
# Backup current binary
cp /opt/homebrew/bin/opencode /opt/homebrew/bin/opencode.bak
# Replace
cp /tmp/opencode-1.14.47/opencode /opt/homebrew/bin/opencode
# Prevent brew from overwriting on next upgrade
brew pin opencodeAfter downgrading:
- Context stays at steady ~61% per turn
- Compaction works correctly
- Session remains stable
Version Information
- Broken: v1.14.48 (May 11), v1.14.49 (May 13), v1.14.50 (May 14)
- Working: v1.14.47 (May 11)
- Both v1.14.47 and v1.14.48 are dated May 11 — the regression was introduced in the same day's release
Additional Data
Token breakdown per turn (measured with reserved=8000, 200K context):
| Metric | v1.14.47 (working) | v1.14.48+ (broken) |
|---|---|---|
| Per-turn overhead | ~123K tokens (61%) | ~123K tokens (61%) |
| Context stability | Steady | Erratic (3% to 68% jumps) |
| Compaction behavior | Triggers correctly, reduces context | Fails or produces incorrect results |
The per-turn token cost is identical between versions. The regression is in how compaction manages the context window, not in the initial token calculation.
Related Issues
- fix(provider): classify "tokens in request more than max tokens allowed" as context overflow #27519 — Z.AI overflow error not in OVERFLOW_PATTERNS (separate but related: the missing pattern means even when compaction does trigger, the overflow error is not caught)
- Session permanently stuck after auto-compaction: post-compaction auto-trigger fires tool_use without tool_result error and is non-recoverable #27594 — compaction re-trigger bug (post-compaction auto-fire causes orphaned tool_use blocks)
Activity