Skip to content

fix: prevent self-amplifying compaction failure loop (#900) - #1055

Closed
kartikmengane09-oss wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
kartikmengane09-oss:fix/compaction-failure-loop-900
Closed

fix: prevent self-amplifying compaction failure loop (#900)#1055
kartikmengane09-oss wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
kartikmengane09-oss:fix/compaction-failure-loop-900

Conversation

@kartikmengane09-oss

@kartikmengane09-oss kartikmengane09-oss commented Aug 9, 2026

Copy link
Copy Markdown

Summary

Fixes the self-amplifying compaction failure loop described in #900.

Problem

Long-running sessions can exceed the model context window. The initial provider call fails, recovery compaction is then attempted with an oversized summarization request, and the compaction failure is persisted and replayed into subsequent model context. This causes repeated failures and progressively larger context until the session becomes unresponsive.

Changes

  • Prevent internal failed/recovery state from contaminating model-facing context while preserving the durable JSONL audit trail.
  • Bound compaction/summarization requests against the available model context budget.
  • Process oversized history through bounded message-aligned summarization rather than a single oversized request.
  • Ensure necessary pre-compaction checks are performed before provider calls, including direct agent-message paths.
  • Handle stale provider usage with a current-state token estimate where necessary.
  • Prevent uncontrolled repeated compaction failures and preserve valid state when compaction fails.

Validation

Relevant compaction and session-context regression tests are included/run as part of the change.

Closes #900

Note

Fix self-amplifying compaction failure loop by adding context budget enforcement

  • compaction.ts: generateSummary now splits oversized conversations into budget-sized chunks using a chars/4 token estimate, summarizes each chunk independently, then aggregates into a final summary with a second-pass if needed.
  • compact validates the produced summary against the model's context window after generation and throws if the result would exceed the safe limit, preventing an oversized compacted state from being committed.
  • session-manager.ts: buildSessionContext now filters out assistant messages with stopReason: "error" and compaction_outcome custom messages from the model context to avoid replaying failed attempts.
  • Behavioral Change: compact now throws instead of silently succeeding when the compacted result is too large for the context window.

Macroscope summarized 6f1ef3e.

…meIntellect-ai#900)

- Skip failed assistant provider attempts (stopReason: error) from buildSessionContext replay
- Skip compaction_outcome custom_message telemetry from buildSessionContext replay
- Enforce safe input token budget and message-boundary chunking in generateSummary
- Add post-compaction result validation in compact to prevent committing oversized context
- Add regression test coverage for session context filtering and bounded summarization
@kartikmengane09-oss
kartikmengane09-oss marked this pull request as ready for review August 9, 2026 07:34
avion23 pushed a commit to avion23/prime-agent that referenced this pull request Aug 9, 2026
@sethkarten

Copy link
Copy Markdown
Contributor

Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1165, authored independently from upstream/main.

We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1165 and is being closed.

The complete review stack is #1158#1165. It is being left unmerged for human review after CI and review-bot findings are cleared.

@sethkarten sethkarten closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction can permanently self-amplify from durable retry debris and unbounded summary input

2 participants