Skip to content

Compaction retry cascade causes context overflow loop #10613

@1kuna

Description

@1kuna

Summary

When auto-compaction fires during a context overflow, the retry can immediately overflow again because the compaction summary + original prompt exceed the context window. This creates a cascade loop: overflow → compact → retry → overflow → compact → retry.

Expected Behavior

After compaction, the retry should use a slim prompt that fits within the remaining budget, preventing the cascade.

Actual Behavior

The retry reuses the full original prompt, which may exceed the post-compaction context budget, triggering another compaction immediately.

Fix

PR #10220 implements a compaction retry hook that:

  • Intercepts the retry before it fires
  • Calculates a safe token budget
  • Downgrades the prompt to a slim one-shot version if needed
  • Cancels the retry if even the slim prompt won't fit

Depends on setAutoCompactionRetryHook being exposed by pi-coding-agent (PR badlogic/pi-mono#1318).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions