Skip to content

fix: remove context-relative suppression from filterRecommendedRanges (Issue #251) - #252

Merged
ranxianglei merged 2 commits into
masterfrom
2026-07-30_filter-recommended-ranges-fix
Jul 31, 2026
Merged

fix: remove context-relative suppression from filterRecommendedRanges (Issue #251)#252
ranxianglei merged 2 commits into
masterfrom
2026-07-30_filter-recommended-ranges-fix

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes two bugs in the nudge injection system:

Bug 1: filterRecommendedRanges 5% threshold (issue #251)

filterRecommendedRanges used 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), lastNudgeShownTokens was reset to undefined. This caused a loop: next turn, growthReference fell back to stale lastPerMessageNudgeTokens → huge growth → nudge fires → nothingToCompress → reset → repeat every turn.

Fix: Keep lastNudgeShownTokens when nothingToCompress. Also fix growth display to use lastNudgeShownTokens ?? lastPerMessageNudgeTokens (matching the actual decision logic).

Changes

  • lib/messages/inject/utils.ts: Rewrote filterRecommendedRanges — no suppression
  • lib/messages/inject/inject.ts: Removed lastNudgeShownTokens = undefined reset; fixed growth display baseline
  • tests/smart-nudge-gating.test.ts: 7 tests (rewritten for new behavior)
  • tests/inject.test.ts: Updated 1 test, added 1 multi-turn regression test
  • tests/property-invariants.test.ts: INV5 updated

Verification

  • npm run typecheck — clean
  • npm test — 942 tests pass, 0 failures

… (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.
@ranxianglei
ranxianglei merged commit d087522 into master Jul 31, 2026
5 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