fix(session): prune tool outputs before serializing compaction request - #2070
Open
YOMXXX wants to merge 2 commits into
Open
fix(session): prune tool outputs before serializing compaction request#2070YOMXXX wants to merge 2 commits into
YOMXXX wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1661. Compaction fails with "context exceeds model limit" even when the thread's live token count is well under the model window (e.g. 100k used vs 1M window) — large tool outputs serialized into the compaction request inflate it past the limit.
Root cause:
packages/opencode/src/session/compaction.tshas a DBprune()for tool outputs that is defined but never called.compaction.processbuilds itsmodelMessagesfromselected.headviatoModelMessagesEffectWITHOUT pruning old tool outputs, so a session with big tool bodies (file reads, diffs) overflows the compaction model.Fix: strip old tool outputs on the in-memory copy before serialization:
pruneToolOutputs(messages)mirrors the DB prune walk (protect last 2 user turns + summary boundary +PRUNE_PROTECTED_TOOLS, accumulate pastPRUNE_PROTECT, stripoutputandproviderOutput).compaction.processafterstructuredClone(selected.head)and beforetoModelMessagesEffect— never touches the DB or the visible transcript.Test Plan
PRUNE_PROTECT; keeps protectedskilloutputs; small sessions untouched; summary boundary stops the walk.bun typecheckclean; session suite 913 pass no regression.Notes
prune()remains unwired (separate storage-savings enhancement).inputand non-provider-executed structured output are not bounded — the fix targets the common large-outputcase (read/bash/edit/write).