Skip to content

feat(opencode): trim old tool output and media in one batch at a token mark - #186

Merged
exe-dev-github-integration[bot] merged 2 commits into
mainfrom
context-limits
Nov 5, 2026
Merged

exe-dev-github-integration[bot] merged 2 commits into
mainfrom
context-limits

Conversation

@sarath-menon

@sarath-menon sarath-menon commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Long V4 runs resend their whole history and only compact near the model window, and prune runs only when a turn ends, so a single long run never prunes. compaction.prune_at runs the existing prune inside the loop once the context reaches that many tokens, and compaction.keep_media keeps the latest N tool results with screenshots whole and clears everything older in one batch, so the prompt cache is rewritten rarely instead of every step. Without prune_at nothing changes: prune still runs only when a turn ends with its token-window rules. Tests cover the mark, the batch and the default (the existing config-dependent prune test also fails on main in this environment); typecheck passes and the prompt suite fails identically on main and this branch.


Summary by cubic

Adds compaction.prune_at and compaction.keep_media options so long runs can trim old tool output and media in one batch inside the loop instead of only pruning when a turn ends. Without prune_at, behavior is unchanged and prune still runs only at turn end with its existing token-window rules.

  • The in-loop prune fires once context reaches prune_at tokens and clears everything older than the latest keep_media (default: 2) completed tool results with media, rewriting the prompt cache rarely.
  • A trim frees context that the last finished message's token usage does not reflect, so the next pass skips the overflow check to avoid compacting on stale numbers.
  • Screenshots and other media count toward the token estimate at a fixed 1,500 tokens each.

Written for commit e6347c6. Summary will update on new commits.

View guided diff Turn on auto-fix

…n mark

compaction.prune_at runs the prune inside the loop once the context reaches the mark and clears everything older than the latest keep_media results with media, in one batch so the prompt cache is rewritten rarely. Without prune_at nothing changes: prune still runs only when a turn ends, with its token-window rules.
@exe-dev-github-integration
exe-dev-github-integration Bot merged commit 5affb30 into main Nov 5, 2026
3 checks passed
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.

1 participant