fix(core): prevent context compaction loop when budget too tight (#1708)#1727
Merged
fix(core): prevent context compaction loop when budget too tight (#1708)#1727
Conversation
Add three guards to maybe_compact() to prevent infinite compaction loops when context_budget_tokens is set tighter than the system prompt size: - Cooldown guard: skips compaction for compaction_cooldown_turns turns (default 2) after each successful compaction, preventing back-to-back re-triggers while context stabilizes. - Counterproductive guard: marks compaction exhausted when freed_tokens is zero (summary consumed all freed space), making further attempts pointless. - Exhaustion guard: marks compaction exhausted when context remains above threshold after compaction, meaning the budget is structurally too tight. Surfaces a user-visible warning once when exhausted. New config field: memory.compaction_cooldown_turns (u8, default 2).
…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.
bug-ops
added a commit
that referenced
this pull request
Mar 14, 2026
bug-ops
added a commit
that referenced
this pull request
Mar 14, 2026
* release: prepare v0.15.0 - Bump workspace version 0.14.3 → 0.15.0 in Cargo.toml and all workspace dependency entries - Update Cargo.lock - Finalize CHANGELOG.md [0.15.0] section dated 2026-03-14 - Update tests badge 4993 → 5413 - Update version references in snapshots, .zeph/zeph.md, crates/zeph-acp/README.md - Refresh docs/: version refs, Gemini provider docs, cascade routing, tiered compaction, scheduler list, graph memory chunked loading, cloud provider guide, configuration reference * docs: add compaction loop prevention section for v0.15.0 (#1727)
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
Fixes #1708 — context compaction loop when
context_budget_tokensis set tighter than the system prompt size.Three guards added to
maybe_compact()to prevent infinite compaction loops:compaction_cooldown_turnsturns (default 2) after each successful compaction. Soft-tier pruning still runs during cooldown.New config field:
[memory] compaction_cooldown_turns = 2(u8, serde default).Guards are integrated with the tiered compaction architecture from #1720 (Soft at 70%, Hard at 90%): cooldown and counterproductive/exhaustion guards only apply to the Hard (LLM) tier.
Test plan
crates/zeph-core/src/agent/context/mod.rscovering all three guardscargo +nightly fmt --check,cargo clippy --workspace --features full -- -D warnings