fix(context): show post-compaction size immediately after /compact#16757
Open
paulbkim01 wants to merge 1 commit intoanomalyco:devfrom
Open
fix(context): show post-compaction size immediately after /compact#16757paulbkim01 wants to merge 1 commit intoanomalyco:devfrom
paulbkim01 wants to merge 1 commit intoanomalyco:devfrom
Conversation
After compaction, the last assistant message's `input` tokens reflect the full pre-compaction history fed to the summarizer, not the context the next turn will actually see. Both the TUI sidebar and the web/desktop context display showed this inflated number, making it appear as if compaction had no effect until the next user message was sent. Fix: when the last assistant message has `summary: true`, use only its `output` tokens (the summary text) as the context size estimate. The raw per-field breakdown (input/output/reasoning/cache) is left untouched so the context breakdown panel still shows full compaction details. Closes anomalyco#5760
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.
Issue for this PR
Closes #5760
Type of change
What does this PR do?
After
/compactruns, the sidebar and web context display continue showingthe pre-compaction token count until the next user message is sent. This makes
it appear as if compaction had no effect.
Root cause: both displays compute context size from the last assistant
message's tokens as
input + output + reasoning + cache. For a compactionsummary message,
inputreflects the full pre-compaction history that was fedto the summarizer — not the context the next turn will actually use.
outputis the summary text (~2-5k tokens). So the display shows ~155k instead of ~5k.
Fix: when the last assistant message has
summary: true, use only itsoutputtokens as the context size estimate. The raw per-field breakdown(
input/output/reasoning/cache) is left untouched so the contextbreakdown panel still shows full compaction details.
Changed files:
packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx— TUI sidebar context memopackages/app/src/components/session/session-context-metrics.ts— web/desktop context metricspackages/app/src/components/session/session-context-metrics.test.ts— three new test casesHow did you verify your code works?
session-context-metrics.test.tssuite (all 7 pass)bun turbo typecheck, 13 packages)/compacton a session with substantial history, confirmthe sidebar immediately shows the reduced count (~output tokens of the summary)
rather than the pre-compaction total
Checklist