GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(session): add custom compaction thresholds along with prevention of continuous compaction by saksham1341 · Pull Request #10123 · anomalyco/opencode

Conversation

@saksham1341

@saksham1341 saksham1341 commented Jan 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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%).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

claui reacted with heart emoji saldanhacl, verrerie, pablopunk, lclbm, cvaisnor, claui, GoldenStain, and egemala-ens reacted with rocket emoji
All reactions
  • ❤️ 1 reaction
  • 🚀 8 reactions
@saksham1341
feat(session): make compaction thresholds and message buffer configur…
6001ad5
…able
@github-actions github-actions Bot added the needs:issue label Jan 23, 2026
@github-actions

github-actions Bot commented Jan 23, 2026

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

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

I found one potentially related PR:

PR #9656: feat(opencode): trigger compaction earlier and add multi-file read
#9656

This PR appears to address compaction triggering behavior, which is related to the compaction threshold configuration being added in the current PR (#10123). However, it seems to focus on multi-file read functionality as well, so they may not be exact duplicates. You should review #9656 to ensure there's no overlap in the compaction logic implementation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:issue label Jan 23, 2026
@saksham1341

saksham1341 commented Jan 23, 2026

Copy link
Copy Markdown
Author

EDITS: Correctly mentioned the issue being fixed.

Reviewed the potentially related PR, this one focuses solely on customizing the early compaction threshold as per the user's need, while preventing infinite compaction loop. Meanwhile the related PR (#96956) is a hardcoded early compaction (at 90% of the context) fix along with multi-file read validation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jan 23, 2026
fix(opencode): accumulate step tokens for compaction #10215
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:49
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 4 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
This was referenced Jan 31, 2026
fix(opencode): lastUser identification and loop exit condition #11443
Closed
fix(opencode): prevent context overflow during compaction #11453
Closed
feat: configurable context compaction threshold #11467
Closed
@iyunbo iyunbo mentioned this pull request Jan 31, 2026
Feature Request: Configurable Context Compaction Threshold #11314
Closed
@WietRob

WietRob commented Feb 2, 2026

Copy link
Copy Markdown

@jeremyakers Just +1 on this PR! Custom compaction thresholds are critical for long-context models like Gemini/GPT that degrade quality at 30-50% context. The hardcoded 75% threshold causes severe performance issues in production workflows.

Having per-model threshold configuration would allow power users to:

  • Set Gemini to compact at 30% (300k tokens) instead of 75%
  • Set Claude to compact at 50% instead of 75%
  • Keep shorter-context models at default 75%

This aligns perfectly with the 'auto-archive' mode you mentioned - both give users fine-grained control over when context gets compacted.

Happy to test beta implementations!

egemala-ens reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saksham1341
feat(session): support model-specific compaction thresholds
3daf373
@saksham1341

saksham1341 commented Feb 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@WietRob I have added a commit allowing model-specific threshold control, thank you for the suggestion!

Here is a sample config.

{
  "$schema": "https://opencode.ai/config.json",
    "compaction": {
        "token_threshold": 100000,
        "context_threshold": 0.30,
        "models": {
            "opencode/minimax-m2.1-free": {
                "token_threshold": 50000,
                "context_threshold": 0.10
            }
        }
    }
}

It would be great help if you could test it out as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Feb 3, 2026
feat(compaction): configurable threshold and model (global + per-model) #11931
Closed
@WietRob

WietRob commented Feb 6, 2026

Copy link
Copy Markdown

@saksham1341 Tested this with opencode/minimax-m2.1-free using a 5% threshold in my config. It definitely works - I pushed context to ~24% and it triggered compaction immediately (and kept compacting as I stayed over the limit). The model-specific overrides are doing their job. Thanks for adding this!

saksham1341 and kfwang90 reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

saksham1341 added 2 commits February 11, 2026 08:08
@saksham1341
sync dev;
99712df
@saksham1341
typecheck fix;
f4c0935
@WietRob

WietRob commented Feb 24, 2026

Copy link
Copy Markdown

Thank you for implementing this! I have tested it with opencode 1.2.10.

Working config format:

{
  "compaction": {
    "token_threshold": 60000,
    "context_threshold": 0.45,
    "models": {
      "google/antigravity-gemini-3-flash": {
        "context_threshold": 0.30
      },
      "google/antigravity-gemini-3-pro-high": {
        "context_threshold": 0.30
      }
    }
  }
}

Note: The following keys from my previous config are not supported in this implementation:

  • auto, prune, reserved, strategy, threshold, preserveRecentMessages, preserveSystemPrompt

These should be removed. The supported keys are only:

  • token_threshold (global default)
  • context_threshold (global default)
  • models (per-model overrides with same keys)

Feature request: Would it be possible to add min_messages (minimum messages between compactions) to prevent continuous compaction loops? This would be especially useful for long-running sessions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fea17e86

fea17e86 commented Feb 25, 2026

Copy link
Copy Markdown

@WietRob how did you get this to work? I just updated my opencode to 1.2.12 and adjusted my opencode.json accordingly. Still, the auto compaction only kicks in at 75%.

// opencode.json
{
    "$schema": "https://opencode.ai/config.json",
    "compaction": {
        "token_threshold": 60000,
        "context_threshold": 0.45
    },
    "mcp": {
        ...
    }
}
Screenshot 2026-02-25 at 10 11 06
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 25, 2026
feat(opencode): add double-buffer context management #15130
Closed
fix(session): prevent infinite loop in auto-compaction when assistant ended its turn #15532
Closed
@Lee-SiHyeon Lee-SiHyeon mentioned this pull request Mar 1, 2026
Auto-compaction infinite loop when assistant ended its turn (finish !== tool-calls) #15533
Closed
@ke7in-zz

ke7in-zz commented Mar 24, 2026

Copy link
Copy Markdown

nudge!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Mar 24, 2026
fix: trigger auto-compaction at the configured threshold #18951
Closed
4 of 6 tasks
@WietRob

WietRob commented Mar 26, 2026

Copy link
Copy Markdown

@fea17e86 Sorry for the confusion! I just tested this myself and found the issue.

Why it doesn't work for you:
The custom compaction thresholds (token_threshold, context_threshold) are part of PR #10123, which is still open and not yet merged. Version 1.2.12 does not include these features - it only has the default behavior (compaction at 75% context usage).

What I found when testing the PR branch:

  • The PR code correctly reads compaction.token_threshold and compaction.context_threshold from opencode.json
  • It also supports compaction.min_messages to prevent compaction loops
  • Model-specific overrides via compaction.models work as documented

To use these features now:
You would need to build from the PR branch directly:

git clone https://github.com/anomalyco/opencode.git
cd opencode
git fetch origin pull/10123/head:pr-10123
git checkout pr-10123
# Follow the build instructions in the repo

Your config format is correct - it will work once this PR is merged and released.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Apr 1, 2026
feat(compaction): harden compaction system with breaker, retry, caps, and budget #20516
Closed
5 of 8 tasks
This was referenced Apr 8, 2026
feat(opencode): add threshold-based compaction via maxTurns config #21567
Closed
feat: compression improvements #22029
Closed
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
This was referenced May 15, 2026
fix(session): compact finished overflowed turns #27730
Closed
fix(session): break infinite compaction loop #27919
Closed
fix(session): stop auto-compaction infinite loop when assistant ended its turn #28798
Closed
@github-actions github-actions Bot mentioned this pull request May 25, 2026
fix(opencode): break auto-compact loop when compaction makes no progress #29150
Closed
3 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Jun 6, 2026
feat(ui): add OpenCode config editor SakuraByteCore/codexmate#191
Merged
@github-actions github-actions Bot mentioned this pull request Jun 18, 2026
fix(opencode): honor disabled automatic compaction #32864
Closed
3 of 6 tasks
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
fix: bound compaction request size #34379
Closed
3 of 6 tasks
@github-actions github-actions Bot mentioned this pull request Jul 18, 2026
fix(session): bound consecutive overflow compaction cycles in the prompt loop #37584
Closed
3 of 6 tasks
This was referenced Aug 22, 2026
feat(session): add suffix compaction #44264
Closed
fix(compaction): use cumulative token usage for auto-compaction overflow check #46136
Closed
@github-actions github-actions Bot mentioned this pull request Sep 9, 2026
fix(session): stop auto-compacting after 3 consecutive attempts that don't shrink the request #48188
Closed
@saksham1341 saksham1341 closed this by deleting the head repository Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Feature Request: Custom compaction threshold to trigger earlier

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@saksham1341 @WietRob @fea17e86 @ke7in-zz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.