feat(agent-loop): compaction circuit breaker (IMPROVEMENTS_PLAN #1) - #220
Merged
Conversation
When the summarizer keeps failing (network errors, invalid summaries, model garbage), every fold trigger re-called the LLM and silently fell back to pruned-only context — wasting API calls every turn. Add a per-run consecutive-failure counter. `run_compaction_pass[_with_focus]` now takes the current count and returns a `SummaryOutcome` (Succeeded / Failed / Skipped); `run_loop` folds that into `compaction_failures` via `record_compaction_outcome`. Once the count reaches MAX_CONSECUTIVE_COMPACTION_FAILURES (3), the pass skips the LLM summarizer entirely (logs "circuit breaker open") — the cheap `prune_tool_outputs` pass still runs, so context can't grow unbounded. Counter resets on the next successful summary; it's per-run, so a fresh run_loop starts clean. Tests: pure `record_compaction_outcome` counter logic, and an end-to-end test asserting the summarizer is invoked once per sub-threshold attempt then NOT called once the breaker opens, with the prune-only fallback still firing. 2135 pass at -D warnings.
This was referenced May 29, 2026
This was referenced May 29, 2026
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
May 29, 2026
…PLAN #3) The per-result cap (cap_oversized_tool_results) was a flat 3000 tokens regardless of context pressure. Near the limit, a single uncapped tool result could push the NEXT request over before the reactive 75% post-response fold fires. Add a tiered cap: above AGGRESSIVE_CAP_THRESHOLD (60% estimated context) the per-result cap tightens to AGGRESSIVE_RESULT_CAP_TOKENS (1000) via a pure `tiered_result_cap(estimate, ctx_max)` helper; below it stays at 3000. The 60% threshold sits below the 75% fold trigger so the tighter cap has room to work first. Wired at the pre-send cap site in run_loop. Unit test for the tiering (normal below 60%, strict boundary at 60%, aggressive above). 2136 pass at -D warnings. Stacked on the circuit-breaker branch (PR dirge-code#220).
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
Jun 3, 2026
…action-circuit-breaker feat(agent-loop): compaction circuit breaker (IMPROVEMENTS_PLAN #1)
allen-munsch
pushed a commit
to allen-munsch/dirge
that referenced
this pull request
Jun 3, 2026
…PLAN #3) The per-result cap (cap_oversized_tool_results) was a flat 3000 tokens regardless of context pressure. Near the limit, a single uncapped tool result could push the NEXT request over before the reactive 75% post-response fold fires. Add a tiered cap: above AGGRESSIVE_CAP_THRESHOLD (60% estimated context) the per-result cap tightens to AGGRESSIVE_RESULT_CAP_TOKENS (1000) via a pure `tiered_result_cap(estimate, ctx_max)` helper; below it stays at 3000. The 60% threshold sits below the 75% fold trigger so the tighter cap has room to work first. Wired at the pre-send cap site in run_loop. Unit test for the tiering (normal below 60%, strict boundary at 60%, aggressive above). 2136 pass at -D warnings. Stacked on the circuit-breaker branch (PR dirge-code#220).
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.
First of the 5 IMPROVEMENTS_PLAN phases — one PR per feature for review.
Problem
A failing summarizer (network errors / invalid summaries / model garbage) was retried on every fold trigger, silently falling back to pruned-only context each time — burning API calls for the whole run.
Fix
Per-run consecutive-failure counter:
run_compaction_pass[_with_focus]now takes the current failure count and returns aSummaryOutcome(Succeeded/Failed/Skipped).run_loopfolds that intocompaction_failuresviarecord_compaction_outcomeat all three call sites (turn-start fold, post-usage fold, exit-with-summary).MAX_CONSECUTIVE_COMPACTION_FAILURES = 3, the pass skips the LLM summarizer (logs circuit breaker open); the cheapprune_tool_outputsstill runs, so context stays bounded.run_loop), matching the plan's design decision.Tests
record_compaction_outcome: reset/increment/skip).2135 pass under the full feature matrix at
-D warnings.Next phases (each its own PR): #3 aggressive prune tier → #4 snip feedback loop → #2 post-compaction file restore → #5 report enrichment.