Skip to content

fix(compaction): retry loop can burn tokens when summarizer model is unavailable #58838

Description

@aaron-he-zhu

Bug Description

summarizeChunks() in src/agents/compaction.ts uses retryAsync() with 3 attempts per chunk to handle transient errors during compaction. However, when the summarizer model is persistently unavailable (overloaded, rate-limited, or misconfigured), the retry loop burns tokens across multiple chunks without making progress.

In a multi-chunk compaction scenario (common with long channel conversations), this means:

  1. Chunk 1: 3 retries → fail
  2. Chunk 2: 3 retries → fail
  3. Chunk N: 3 retries → fail

Each retry sends the chunk to the model, consuming input tokens even though the response fails. With large chunks (~4K tokens each), a 5-chunk compaction can waste 60K+ tokens before finally throwing.

Expected Behavior

After N consecutive compaction failures, the system should stop attempting compaction and fall back to the previous summary (or a placeholder). This prevents cascading token waste when the summarizer is down.

A circuit breaker pattern would be appropriate:

  • Closed (normal): compaction attempts proceed
  • Open (after N failures): compaction is skipped, fallback used
  • Half-open (after cooldown): one test attempt allowed

Affected Code

  • src/agents/compaction.ts:263retryAsync() call in summarizeChunks()
  • Called from summarizeWithFallback() and summarizeInStages()

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions