feat(memory): tiered context compaction — soft at 70%, hard at 90% (#1338)#1720
Merged
feat(memory): tiered context compaction — soft at 70%, hard at 90% (#1338)#1720
Conversation
…#1338) Replace single compaction_threshold (0.80) with two-tier compaction: - Soft tier (soft_compaction_threshold, default 0.70): apply deferred tool summaries + prune tool outputs without LLM call. Does not set compacted_this_turn, allowing the hard tier to fire in the same turn. - Hard tier (hard_compaction_threshold, default 0.90): apply deferred summaries, prune tool outputs, fall back to full LLM summarization. Sets compacted_this_turn to prevent double LLM calls per turn. Add CompactionTier enum (None/Soft/Hard) replacing should_compact() and should_apply_deferred() methods. Preserve maybe_apply_deferred_summaries() for tool execution loop call sites (legacy.rs:166, native.rs:202, mod.rs:2428) with both token-pressure (via compaction_tier()) and count-pressure triggers. Config backward compat: compaction_threshold serde alias maps to hard_compaction_threshold. ZEPH_MEMORY_COMPACTION_THRESHOLD env var also remapped to hard threshold. BREAKING: deferred_apply_threshold config field removed (silently ignored by serde). soft_compaction_threshold replaces it. Update config.toml to use new field names.
- Add ZEPH_MEMORY_SOFT_COMPACTION_THRESHOLD to ENV_KEYS cleanup array in config/tests.rs (REV-SUGGEST-02): count 52 → 53 so clear_env() covers the new env var - Update env var table in docs/src/advanced/context.md (REV-SUGGEST-01): replace stale ZEPH_MEMORY_DEFERRED_APPLY_THRESHOLD row with ZEPH_MEMORY_SOFT_COMPACTION_THRESHOLD; update ZEPH_MEMORY_COMPACTION_THRESHOLD description and default (0.75 → 0.90, now hard threshold backward compat alias) Follow-up filed: #1719 (wizard hard_compaction_threshold prompt)
1092c35 to
88b7c85
Compare
bug-ops
added a commit
that referenced
this pull request
Mar 14, 2026
…tion (#1720) Resolve conflicts with feat(core): tiered compaction (soft 70% / hard 90%). Integrate the three compaction guards from #1708 into the new tiered architecture: cooldown skips Hard-tier LLM summarization only (Soft pruning still runs), counterproductive and exhaustion guards apply within the Hard tier after LLM summarization.
This was referenced Mar 14, 2026
Closed
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
Implements tiered context compaction (issue #1338):
compacted_this_turn, allows Hard tier to fire in the same turnCompactionTierenum (None/Soft/Hard) replaces the separateshould_compact()andshould_apply_deferred()predicatesConfig changes
Old
compaction_thresholdstill accepted via#[serde(alias)].ZEPH_MEMORY_COMPACTION_THRESHOLDenv var remapped to hard threshold.Validation
soft < hard) enforced inconfig.validate(); no sensitive data leakscompaction_tier()is O(1), allocation-free; soft tier has zero await pointsFollow-up
--initwizard prompt forhard_compaction_thresholdCloses #1338