fix: remove context-relative suppression from filterRecommendedRanges (Issue #251) - #252
Merged
Merged
Conversation
… (Issue #251) At 1M context windows, filterRecommendedRanges used a 5% threshold (50K) to suppress compression recommendations. This meant 30-40K of genuinely compressible content never triggered compression nudges. Fix: always return all input ranges, mark last segment as dangerous. The minCompressRange backstop in range.ts (5000 chars) handles garbage. Files: utils.ts, inject.ts, 3 test files. 941 tests pass.
When nothingToCompress (all ranges protected), lastNudgeShownTokens was reset to undefined. This caused a feedback loop: next turn, growthReference fell back to stale lastPerMessageNudgeTokens → huge growth → nudge fires again → nothingToCompress → reset → repeat every turn. Fix: keep lastNudgeShownTokens when nothingToCompress. The half-threshold gate applies naturally, preventing re-firing without a wipe. Also fix growth display to use lastNudgeShownTokens ?? lastPerMessageNudgeTokens (matching the actual growthReference used for decisions) instead of always using the stale lastPerMessageNudgeTokens. Tests: 942 pass, 0 fail.
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 two bugs in the nudge injection system:
Bug 1: filterRecommendedRanges 5% threshold (issue #251)
filterRecommendedRangesused a context-relative threshold (5% of modelContextLimit) to suppress recommendations. At 1M context = 50K threshold → sessions with 30-40K compressible content never get recommendations → nudge suppressed → no compression.Fix: Removed suppression logic entirely. All ranges always shown, last gets
dangerous: true.minCompressRange(5000 chars) backstop prevents garbage compressions.Bug 2: lastNudgeShownTokens reset causes nudge loop
When
nothingToCompress(all ranges protected),lastNudgeShownTokenswas reset toundefined. This caused a loop: next turn,growthReferencefell back to stalelastPerMessageNudgeTokens→ huge growth → nudge fires →nothingToCompress→ reset → repeat every turn.Fix: Keep
lastNudgeShownTokenswhennothingToCompress. Also fix growth display to uselastNudgeShownTokens ?? lastPerMessageNudgeTokens(matching the actual decision logic).Changes
lib/messages/inject/utils.ts: RewrotefilterRecommendedRanges— no suppressionlib/messages/inject/inject.ts: RemovedlastNudgeShownTokens = undefinedreset; fixed growth display baselinetests/smart-nudge-gating.test.ts: 7 tests (rewritten for new behavior)tests/inject.test.ts: Updated 1 test, added 1 multi-turn regression testtests/property-invariants.test.ts: INV5 updatedVerification
npm run typecheck— cleannpm test— 942 tests pass, 0 failures