[PR #10123] feat(session): add custom compaction thresholds along with prevention of continuous compaction #13348

Open
opened 2026-02-16 18:18:12 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10123

State: open
Merged: No


What does this PR do?

This PR Closes #10017 configurable thresholds for session compaction, allowing users to define when compaction triggers based on token count or context usage percentage via opencode.json.
It also introduces a min_messages configuration to prevent infinite compaction loops. This ensures a minimum number of message turns must pass after a summary before a new compaction is triggered, solving edge cases where context remains overflowing immediately after compaction.

How did you verify your code works?

  1. Setup: Create a test directory with the following opencode.json:
  {
     "$schema": "https://opencode.ai/config.json",
     "compaction": {
         "token_threshold": 15000,
         "context_threshold": 0.06,
         "min_messages": 5
     }
   }
  1. Execution:
    • Launch opencode (tested with Big Pickle model).
    • Prompt the model to generate a large amount of text (e.g., "Write a 10,000 word story") to rapidly consume context.
  2. Observation:
    • Confirm that compaction triggers as soon as the 6% context threshold is reached.
    • Verify that after the summary is generated, the system processes at least 5 subsequent messages before attempting another compaction, even if the context usage immediately rises back above the threshold (e.g., to 7%).
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10123 **State:** open **Merged:** No --- ### What does this PR do? This PR Closes #10017 configurable thresholds for session compaction, allowing users to define when compaction triggers based on token count or context usage percentage via opencode.json. It also introduces a min_messages configuration to prevent infinite compaction loops. This ensures a minimum number of message turns must pass after a summary before a new compaction is triggered, solving edge cases where context remains overflowing immediately after compaction. ### How did you verify your code works? 1. Setup: Create a test directory with the following opencode.json: ```json { "$schema": "https://opencode.ai/config.json", "compaction": { "token_threshold": 15000, "context_threshold": 0.06, "min_messages": 5 } } ``` 2. Execution: - Launch opencode (tested with Big Pickle model). - Prompt the model to generate a large amount of text (e.g., "Write a 10,000 word story") to rapidly consume context. 3. Observation: - Confirm that compaction triggers as soon as the 6% context threshold is reached. - Verify that after the summary is generated, the system processes at least 5 subsequent messages before attempting another compaction, even if the context usage immediately rises back above the threshold (e.g., to 7%).
yindo added the pull-request label 2026-02-16 18:18:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13348