feat(context): fix soft compaction tier rarely firing (#1828)#1857
Merged
feat(context): fix soft compaction tier rarely firing (#1828)#1857
Conversation
c1acf62 to
520841d
Compare
- Lower soft_compaction_threshold default from 0.70 to 0.60, widening the soft-to-hard window from 10% to 20% of context budget - Add maybe_soft_compact_mid_iteration() for per-tool-call soft compaction: applies deferred summaries and prunes to soft threshold without triggering Hard tier, LLM calls, or mutating turn counters - Call mid-iteration check in native.rs and legacy.rs after summarize+prune, catching large file reads before they exceed hard threshold - Add 5 unit tests covering all guard branches of the new method Closes #1828
7328bb3 to
1555333
Compare
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
soft_compaction_thresholddefault from 0.70 to 0.60, widening the soft-to-hard window from 10% to 20% of context budgetmaybe_soft_compact_mid_iteration()for per-tool-call soft compaction: applies deferred summaries and prunes tool outputs without triggering Hard tier, LLM calls, or mutating turn countersnative.rsandlegacy.rsafter summarize+prune, catching large single-file reads before they exceed the hard thresholdSoft tier was previously bypassed entirely when a single tool output (e.g. a large file read) pushed token usage from below-soft to above-hard in one step. The mid-iteration check now intercepts this case.
FIX-2 (count-pressure trigger in
maybe_compact()) was intentionally skipped — Tier-0 already handles count pressure viacount_deferred_summaries >= tool_call_cutoff.Test plan
cargo +nightly fmt --checkcargo clippy --workspace --features full -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins(5833 tests, +5 vs baseline)maybe_soft_compact_mid_iteration(): early return oncompacted_this_turn, no-op below threshold, deferred summaries applied at soft tier, flag never set, correct behavior at hard tierCloses #1828