Skip to content

bug: prune thresholds are too aggressive for 1M+ context models #21208

Closed as not planned

Description

@okuyam2y

Description

The prune function in SessionCompaction uses hardcoded thresholds (PRUNE_PROTECT = 40_000 and PRUNE_MINIMUM = 20_000 tokens) to decide when to clear old tool call outputs.

These values were reasonable when most models had 200K context (40K = 20%), but with Claude Opus 4.6, GPT-5.4, and Gemini 2.5 Pro all at 1M+ context, 40K is only 4%. Tool results from just a few turns ago get pruned even though context usage is well under the limit.

Steps to reproduce

  1. Use a 1M context model (Claude Opus, GPT-5.4, etc.)
  2. Have a multi-turn conversation with tool calls (reading/editing files)
  3. After several turns, observe that tool outputs from earlier turns are pruned prematurely
  4. The model loses access to recent work results

Expected behavior

Prune thresholds should scale with model context size so that larger-context models retain more tool output history.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 6, 2026
  2. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. okuyam2y commented on Apr 6, 2026

    @okuyam2y
    Author

    Related but different from #15871. That issue is about the compaction trigger threshold (when to start compacting), while this one is about the prune thresholds (how much tool output to protect from clearing). Both stem from hardcoded values that don't scale to 1M contexts, but they affect different code paths — overflow.ts vs compaction.ts:prune().

    PR #21209 addresses only the prune side.

  4. okuyam2y commented on Apr 6, 2026

    @okuyam2y
    Author

    Also related to #16308 (1M context but compaction/prune triggers at ~272K) — the hardcoded prune thresholds are part of that problem. #11930 requests making thresholds configurable; this PR takes the simpler approach of auto-scaling to context size.

  5. assigned and unassigned on Apr 26, 2026
  6. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  7. github-actions commented on Jul 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions