Skip to content

fix(core): prevent context compaction loop when budget too tight (#1708)#1727

Merged
bug-ops merged 3 commits intomainfrom
context-compaction-loop
Mar 14, 2026
Merged

fix(core): prevent context compaction loop when budget too tight (#1708)#1727
bug-ops merged 3 commits intomainfrom
context-compaction-loop

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

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

Summary

Fixes #1708 — context compaction loop when context_budget_tokens is set tighter than the system prompt size.

Three guards added to maybe_compact() to prevent infinite compaction loops:

  • Exhaustion guard: stops further compaction permanently when it cannot reduce context below threshold (fired when context remains at Hard tier after LLM summarization). Emits a user-visible warning once.
  • Cooldown guard: skips Hard-tier LLM summarization for compaction_cooldown_turns turns (default 2) after each successful compaction. Soft-tier pruning still runs during cooldown.
  • Counterproductive guard: marks compaction exhausted when net freed tokens is zero (the summary consumed all freed space) or when there are ≤1 messages compactable.

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

bug-ops added 2 commits March 14, 2026 02:10
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.
@github-actions github-actions bot added bug Something isn't working 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 bug Something isn't working size/L Large PR (201-500 lines) labels Mar 14, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 14, 2026 01:24
@github-actions github-actions bot added bug Something isn't working size/L Large PR (201-500 lines) labels Mar 14, 2026
@bug-ops bug-ops merged commit c3c8173 into main Mar 14, 2026
15 checks passed
@bug-ops bug-ops deleted the context-compaction-loop branch March 14, 2026 01:35
@bug-ops bug-ops mentioned this pull request Mar 14, 2026
9 tasks
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working config Configuration file changes core zeph-core crate documentation Improvements or additions to documentation rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): context compaction loop when budget too tight — each turn compacts, 400 on oversized context

1 participant