Skip to content

fix: use proportional safety reserve for context compression trigger - #2051

Open
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/compression-trigger-ratio-1529
Open

fix: use proportional safety reserve for context compression trigger#2051
xielixing wants to merge 1 commit into
GCWing:mainfrom
xielixing:fix/compression-trigger-ratio-1529

Conversation

@xielixing

Copy link
Copy Markdown

Problem

Issue #1529 reports that context compression triggers too late, especially for large-context models. The root cause is a fixed 10,000-token safety reserve constant that doesn't scale with context window size.

For a 64K context window, compression fires at ~59% — reasonable. But for 128K it fires at 67%, 200K at 70%, and 256K at 71%. The larger the context, the later compression triggers, degrading conversation quality.

Fix

Replace the fixed AUTO_COMPRESSION_SAFETY_RESERVE_TOKENS = 10_000 constant with:

  • AUTO_COMPRESSION_SAFETY_RESERVE_RATIO = 0.10 — 10% of the context window
  • AUTO_COMPRESSION_MIN_SAFETY_RESERVE_TOKENS = 10_000 — floor for small windows

This makes compression trigger at a consistent ~65% ratio across all context window sizes (128K-256K), while keeping 64K behavior unchanged (the floor applies).

Validation

  • \cargo check -p bitfun-core\ — passed
  • \cargo fmt\ — applied

Closes #1529

Replace fixed 10K safety reserve with a 10% ratio of context window
(minimum 10K floor for small windows). This makes compression trigger
fire at a consistent ~65% ratio for large-context models (128K-256K)
instead of the previous 67-71%, addressing the 'triggers too late'
complaint in GCWing#1529.

Closes GCWing#1529
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.

[Bug]: 上下文压缩触发过晚且同步阻塞,导致会话卡顿

1 participant