Skip to content

fix(BetaToolRunner): Fix infinite loop logic and message loss when compaction occurs#886

Open
mineoka-kento wants to merge 2 commits intoanthropics:mainfrom
mineoka-kento:fix/beta-tool-runner-compaction-loop
Open

fix(BetaToolRunner): Fix infinite loop logic and message loss when compaction occurs#886
mineoka-kento wants to merge 2 commits intoanthropics:mainfrom
mineoka-kento:fix/beta-tool-runner-compaction-loop

Conversation

@mineoka-kento
Copy link

@mineoka-kento mineoka-kento commented Jan 29, 2026

Problem

Currently, the BetaToolRunner logic inside the while loop places the message pushing and tool execution logic inside an if (!isCompacted) block.
This causes two critical issues when compaction occurs:

  1. Infinite Loop: The loop termination condition (break) is skipped, causing an infinite loop.
  2. Message Loss: The current assistant message (containing tool_use) is not added to the history because the push operation is skipped. Since checkAndCompact only summarizes existing history and does not include the current message, the current message is effectively lost. This breaks the conversation flow and prevents tool execution.

Solution

I removed the if (!isCompacted) condition wrapping the message handling logic.
Now, the runner performs steps sequentially:

  1. Checks and compacts history if needed.
  2. Always pushes the current assistant message to history (ensuring the context is preserved even after compaction).
  3. Checks for tool execution and handles results or breaks the loop.

@mineoka-kento mineoka-kento requested a review from a team as a code owner January 29, 2026 01:33
@mineoka-kento mineoka-kento changed the title fix(beta-tool-runner): fix infinite loop when compaction occurs fix(BetaToolRunner): Fix infinite loop logic and message loss when compaction occurs Jan 30, 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.

1 participant