feat: configurable auto-compact threshold with Ctrl+L keybinding#1723
feat: configurable auto-compact threshold with Ctrl+L keybinding#1723aboimpinto wants to merge 2 commits into
Conversation
Adds configurable auto-compact threshold (default 70%) and Ctrl+L keybinding for manual compaction. - New auto_compact_threshold_percent setting (default 70.0, range 10-100) - should_auto_compact_before_send() now uses configurable threshold + 500K hard floor - Early context-pressure warning at 60% (CONTEXT_SUGGEST_COMPACT_THRESHOLD_PERCENT) - Ctrl+L keybinding triggers Op::CompactContext directly, even mid-turn - Updated system prompt to inform model about auto-compact and Ctrl+L Backward compatible: auto_compact still defaults to false. Closes Hmbown#1722
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable threshold for automatic context compaction, defaulting to 70%, and adds a Ctrl+L shortcut for manual compaction. It also implements an early warning status message when context usage exceeds 60% and updates the system prompt to inform the AI of these mechanisms. Feedback was provided regarding the early warning hint, which may be misleading when auto-compaction is blocked by the 500K token floor or when the user-configured threshold has not yet been reached; a more precise logic for these status messages was suggested.
The hint now checks both the 500K floor and configured threshold before claiming auto-compaction will fire. Warning threshold uses min(60%, user_threshold) so custom thresholds still see early warnings.
|
Fixed. The hint now checks both gates (500K floor and configured threshold) before claiming auto-compaction will fire. Four distinct hints cover every combination. Warning threshold also uses min(60%, user_threshold). |
|
This is attached to v0.8.40 because context-pressure hangs matter, but please keep the bar high here. The safe path is a minimal, well-tested change: no default auto-compaction behavior changes without clear cache/cost analysis, and Ctrl+L / threshold behavior needs targeted tests plus a manual long-context smoke note. We should prefer the smallest fix that breaks the 99% context deadlock. |
…#1723) - 6 tests for should_auto_compact_before_send: 500K floor, threshold boundaries, master switch - 5 tests for maybe_warn_context_pressure: all 4 hint messages, disabled hint
Maintainer hardening requests — addressedA1: Cache/cost analysis ✅auto-compact-cache-cost-analysis.md Three independent gates prevent surprise compaction:
No prefix-cache regression: the 500K floor is the same constant from the compaction.rs code. A2: Targeted tests ✅ (11 tests)Pushed to
A3: Manual smoke test ✅6 test scenarios: 60% warning, threshold firing, 500K floor blocking, Ctrl+L (idle, mid-turn, with text), threshold boundaries, disabled auto-compact. Step-by-step with expected outputs. Bonus: Multi-tier trailing compaction proposaltrailing-auto-compact-proposal.md For v0.8.41 discussion: instead of one heavy compaction at 70%, compact in small increments at 50% / 60% / 70%. User feedback: "I prefer small compacts that don't affect memory much and don't take much time, rather than wait several minutes for a heavy compact." |
|
This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current |
Refs #1722 Preserves auto_compact as opt-in, adds the saved threshold setting, keeps the 500K hard floor, and wires Ctrl+L as a manual compaction shortcut for context-pressure recovery. Harvested from PR #1723 by @aboimpinto Co-authored-by: Paulo Aboim Pinto <aboimpinto@gmail.com>
Problem
At ~99.6% context saturation, the TUI becomes completely unresponsive — a chicken-and-egg deadlock where the model is too slow to suggest
/compactand no automatic compaction fires. Both guardrails (capacity controller and auto-compact) are disabled by default since v0.8.11.Closes #1722
Solution
Adds a configurable auto-compact threshold (default 70%) and a Ctrl+L keybinding for manual compaction, closing the gap between model guidance (suggest
/compactat 60%) and engine action (which previously only fired at 95%).Changes
crates/tui/src/settings.rsauto_compact_threshold_percentfield, default 70.0, set handler with validation (10-100), help textcrates/tui/src/tui/app.rsauto_compact_threshold_pctfield in App struct, wired from settingscrates/tui/src/tui/ui.rsmaybe_warn_context_pressure()early-warning tier,should_auto_compact_before_send()uses configurable threshold + 500K floor, Ctrl+L keybindingcrates/tui/src/prompts.rsConfiguration
Behavior
Backward Compatibility
auto_compactstill defaults tofalse— no change for existing users/compactcommand unchanged