fix(core,cli): label screenshot-triggered compaction accurately in the auto-compact notice - #4623
Conversation
…e auto-compact notice
The auto-compaction notice hardcoded "approached the input token limit"
even when the screenshot-overflow trigger fired. In computer-use sessions
that's misleading: compaction can fire on accumulated tool screenshots
while token usage is far below the window limit (observed: the notice
claimed "approached the input token limit" at ~116K/1M tokens when it was
actually the image-count trigger).
Add ChatCompressionInfo.triggerReason ('token_limit' | 'image_overflow' |
'manual'); compress() sets it to 'image_overflow' when the screenshot
trigger is what let it through the cheap gate. Both the TUI
(useGeminiStream) and ACP (Session) notices now show an accurate clause.
📋 Review SummaryThis PR addresses a user-facing accuracy issue where the auto-compaction notice incorrectly reported "approached the input token limit" when compaction was actually triggered by screenshot/image overflow. The implementation threads a 🔍 General Feedback
🎯 Specific Feedback🟢 Medium
const reasonClause =
compressed.triggerReason === 'image_overflow'
? `accumulated enough tool screenshots...`
: compressed.triggerReason === 'manual'
? `manually triggered compaction for...`
: `approached the input token limit for...`;🔵 Low
export type CompactionTriggerReason =
| 'token_limit' // Auto-triggered when effective tokens exceed threshold
| 'image_overflow' // Auto-triggered by screenshot count despite being below token threshold
| 'manual'; // User-initiated via explicit compact command
function buildCompressionNotice(
triggerReason: CompactionTriggerReason | undefined,
model: string,
originalCount: number | undefined,
newCount: number | undefined,
): string {
const reasonClause = triggerReason === 'image_overflow'
? `accumulated enough tool screenshots to trigger compaction for ${model}`
: `approached the input token limit for ${model}`;
return `IMPORTANT: This conversation ${reasonClause}. A compressed context...`;
}
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
wenshao
left a comment
There was a problem hiding this comment.
No issues found. LGTM! ✅ — qwen3.7-max via Qwen Code /review
Summary
The auto-compaction notice always read "This conversation approached the input token limit for {model}", even when compaction was actually fired by the screenshot/image-overflow trigger added in #4599. With the trigger threshold set well below the token-auto threshold (e.g. 20 images on a 1M-window model), the notice was misleading — the conversation had nowhere near the token limit; it had simply accumulated enough tool screenshots.
This PR threads a
triggerReasonthrough the compaction result so the notice reflects what actually happened.Changes
CompactionTriggerReason = 'token_limit' | 'image_overflow' | 'manual'and an optionaltriggerReasonfield onChatCompressionInfo.triggerReasonincompress(): defaults tomanual/token_limitby trigger, upgraded toimage_overflowin the gate when the screenshot trigger is what let a below-threshold compaction through. Surfaced on theCOMPRESSEDresult.triggerReason. Screenshot-triggered compaction reads "accumulated enough tool screenshots to trigger compaction for {model}"; the token-limit wording is unchanged.The notice string is not i18n'd today, so this stays English-only to match the existing behavior.
Test plan
chatCompressionService.test.ts— asserttriggerReason === 'image_overflow'on the two screenshot-trigger COMPRESSED cases and'token_limit'on the token-trigger case.Session.test.ts— new case asserting the ACP notice reads "accumulated enough tool screenshots…" whentriggerReason === 'image_overflow'.tsc --noEmitclean.