Skip to content

fix(compaction): make compaction limits configurable and improve prompt detail retention#29324

Open
shrijit37 wants to merge 2 commits into
anomalyco:devfrom
shrijit37:fix/compaction-configurability
Open

fix(compaction): make compaction limits configurable and improve prompt detail retention#29324
shrijit37 wants to merge 2 commits into
anomalyco:devfrom
shrijit37:fix/compaction-configurability

Conversation

@shrijit37
Copy link
Copy Markdown

@shrijit37 shrijit37 commented May 26, 2026

Issue for this PR

Closes #25746

Related: #21478, #20246, #16333, #13946

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Compaction quality regressed after #23870 — models forget context after compaction, especially in tool-heavy sessions. The root causes were hardcoded limits (2k char tool output truncation, 8k token preserve budget) and a generic system prompt that told the model to prefer "terse bullets" over detail.

Changes:

  1. 4 new config options in opencode.json so users can tune compaction to their needs:

    • compaction.tool_output_max_chars — controls how many chars of tool output the compaction model sees (was hardcoded 2000)
    • compaction.summary_template — custom Markdown template replacing the hardcoded SUMMARY_TEMPLATE in source code
    • compaction.model — model override for compaction, lets you route to e.g. Opus while keeping a cheaper model for daily use
    • compaction.preserve_recent_tokens_max — upper bound for verbatim recent turns (default raised from 8000→32000)
  2. Compaction engine reads these config values instead of hardcoded constants. Constants renamed to DEFAULT_* signaling they're fallbacks.

  3. Compaction system prompt rewritten to emphasize preserving exact details (error messages, file paths, identifiers, command outputs, user preferences) over terse bullets.

How did you verify your code works?

  • Ran existing compaction test suite: 50/52 pass, 2 timeout (pre-existing infrastructure flake, not related to changes)
  • All message-v2 and revert-compact tests pass (43/43)
  • Typecheck passes with no new errors on the changed files
  • Confirmed the config schema accepts the new fields by inspecting the generated config type

Screenshots / recordings

N/A — config + engine change, no UI.

Checklist

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

…pt detail retention

- Add tool_output_max_chars config: controls how much tool output text the
  compaction model sees. Default 2000, can be raised to e.g. 16000.
- Add summary_template config: custom Markdown template replacing the
  hardcoded template. Lets users tailor sections to their workflow.
- Add model config: route compaction to a specific model (e.g.
  'anthropic/claude-opus-4') separate from the session model.
- Add preserve_recent_tokens_max config: upper bound for tokens kept
  verbatim from recent turns. Default raised from 8000 to 32000.
- Revise compaction system prompt to emphasize preserving exact error
  messages, file paths, command outputs, identifiers, and user preferences
  over terse bullets.

Closes anomalyco#25746
Refs anomalyco#21478, anomalyco#20246, anomalyco#16333, anomalyco#13946
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search, I found no duplicate PRs for PR #29324. The searches returned PR #29324 itself and various other compaction-related PRs, but none are addressing the same specific changes (making compaction limits configurable and improving prompt detail retention through the mechanisms described in this PR).

The other compaction-related PRs address different aspects like auto-compact loops, compaction thresholds, cache-aligned compaction, etc., but not the same feature scope as this PR.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 26, 2026
@github-actions
Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

Compaction updates made the models dumber

1 participant