Skip to content

feat(core): resilient compaction with reactive retry and middle-out removal#821

Merged
bug-ops merged 3 commits intomainfrom
m30-resilient-compaction
Feb 24, 2026
Merged

feat(core): resilient compaction with reactive retry and middle-out removal#821
bug-ops merged 3 commits intomainfrom
m30-resilient-compaction

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Feb 24, 2026

Summary

  • Add ContextLengthExceeded error variant with heuristic pattern matching across Claude, OpenAI, and Ollama providers
  • Implement reactive retry in call_llm_with_retry() and call_chat_with_tools_retry() — intercept context length errors, auto-compact, retry up to 2 attempts
  • Add middle-out progressive tool response removal at 10/20/50/100% tiers, removing from conversation center outward
  • Replace ad-hoc compaction prompt with 9-section structured template (User Intent, Technical Concepts, Files & Code, Errors & Fixes, Problem Solving, User Messages, Pending Tasks, Current Work, Next Step)
  • Add build_metadata_summary() LLM-free fallback with safe UTF-8 truncation via truncate_chars()
  • 19 new tests: E2E compaction recovery, call_chat_with_tools_retry scenarios, prompt validation, edge cases, UTF-8 safety

Closes #792, closes #807, closes #808, closes #809, closes #810

Test plan

  • cargo +nightly fmt --check passes
  • cargo clippy --workspace -- -D warnings passes
  • cargo nextest run --workspace --lib --bins — 2626 tests pass
  • E2E test: agent recovers from ContextLengthExceeded and produces response
  • Retry tests: success, recovery, exhaustion paths for both LLM and tool calls
  • Middle-out: progressive tiers, single message, center-first ordering
  • UTF-8 safety: ASCII, emoji, Cyrillic, empty, zero-max, boundary

@github-actions github-actions bot added documentation Improvements or additions to documentation llm LLM provider related rust core enhancement New feature or request size/XL labels Feb 24, 2026
…rompt

Add ContextLengthExceeded error variant with provider-specific pattern
detection. Implement reactive compaction: intercept context overflow,
auto-compact, retry up to 2 times. Progressive middle-out tool response
removal as fallback when summarization itself exceeds context (10/20/50/
100% tiers). Replace generic summarization prompt with structured
9-section template (User Intent, Technical Concepts, Files & Code,
Errors & Fixes, Problem Solving, User Messages, Pending Tasks, Current
Work, Next Step). Add build_metadata_summary as LLM-free final fallback
with safe UTF-8 truncation.
Add 19 tests for resilient compaction: call_chat_with_tools_retry
(3 scenarios), build_chunk_prompt validation (9 sections),
remove_tool_responses_middle_out edge cases, build_metadata_summary
robustness, truncate_chars UTF-8 safety, E2E compaction recovery.

Update docs/src/advanced/context.md with structured compaction prompt,
progressive tool response removal, metadata fallback, reactive retry.
Update all READMEs with M30 feature descriptions.
@bug-ops bug-ops force-pushed the m30-resilient-compaction branch from 1c04e2b to 48cc482 Compare February 24, 2026 19:09
@bug-ops bug-ops enabled auto-merge (squash) February 24, 2026 19:17
@bug-ops bug-ops merged commit 35afc23 into main Feb 24, 2026
23 checks passed
@bug-ops bug-ops deleted the m30-resilient-compaction branch February 24, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation enhancement New feature or request llm LLM provider related rust size/XL

Projects

None yet

1 participant