Skip to content

feat(context): fix soft compaction tier rarely firing (#1828)#1857

Merged
bug-ops merged 1 commit intomainfrom
soft-compaction-window
Mar 15, 2026
Merged

feat(context): fix soft compaction tier rarely firing (#1828)#1857
bug-ops merged 1 commit intomainfrom
soft-compaction-window

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 15, 2026

Summary

  • 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 tool outputs 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 single-file reads before they exceed the hard threshold

Soft 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 via count_deferred_summaries >= tool_call_cutoff.

Test plan

  • cargo +nightly fmt --check
  • cargo clippy --workspace --features full -- -D warnings
  • cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins (5833 tests, +5 vs baseline)
  • 5 new unit tests cover all guard branches of maybe_soft_compact_mid_iteration(): early return on compacted_this_turn, no-op below threshold, deferred summaries applied at soft tier, flag never set, correct behavior at hard tier

Closes #1828

@github-actions github-actions bot added enhancement New feature or request size/L Large PR (201-500 lines) documentation Improvements or additions to documentation rust Rust code changes core zeph-core crate config Configuration file changes and removed enhancement New feature or request size/L Large PR (201-500 lines) labels Mar 15, 2026
@bug-ops bug-ops force-pushed the soft-compaction-window branch from c1acf62 to 520841d Compare March 15, 2026 17:22
@bug-ops bug-ops enabled auto-merge (squash) March 15, 2026 17:23
@github-actions github-actions bot added enhancement New feature or request size/L Large PR (201-500 lines) dependencies Dependency updates labels Mar 15, 2026
- 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
@bug-ops bug-ops force-pushed the soft-compaction-window branch from 7328bb3 to 1555333 Compare March 15, 2026 17:34
@github-actions github-actions bot removed the dependencies Dependency updates label Mar 15, 2026
@bug-ops bug-ops merged commit 73d0fdb into main Mar 15, 2026
19 checks passed
@bug-ops bug-ops deleted the soft-compaction-window branch March 15, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Configuration file changes core zeph-core crate documentation Improvements or additions to documentation enhancement New feature or request rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enhancement(context): Soft compaction tier rarely fires in practice — window too narrow for typical file reads

1 participant