Skip to content

fix: stop repeated identical tool call loops - #46272

Open
codeg-dev wants to merge 2 commits into
anomalyco:devfrom
codeg-dev:fix/session-identical-tool-call-loop
Open

fix: stop repeated identical tool call loops#46272
codeg-dev wants to merge 2 commits into
anomalyco:devfrom
codeg-dev:fix/session-identical-tool-call-loop

Conversation

@codeg-dev

@codeg-dev codeg-dev commented Aug 30, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #45442

Related: #43603

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Stops a session after 10 consecutive calls with the same tool name and canonical arguments. Before returning to idle, it emits a visible session error so repeated read loops do not continue indefinitely. Tests cover the threshold, below-threshold calls, and alternating arguments.

How did you verify your code works?

  • bun test packages/opencode/test/session/prompt.test.ts — 61 passed, 1 skipped, 0 failed
  • bun turbo typecheck — 30/30 packages passed

Screenshots / recordings

Not applicable; this is not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@agentgoblin

Copy link
Copy Markdown

Stops a session after 10 consecutive calls with the same tool name and canonical arguments.

However, there is already a solution for such cases:

https://open-code.ai/en/docs/permissions
doom_loop — triggered when the same tool call repeats 3 times with identical input

For fully automatic operation, it is better to set it to "deny".

It looks like the pull request duplicates existing functionality. Or does it solve the problem in a new way?

codeg-dev and others added 2 commits September 3, 2026 11:56
@codeg-dev
codeg-dev force-pushed the fix/session-identical-tool-call-loop branch from d87794c to d2263e5 Compare September 3, 2026 03:14
@codeg-dev

Copy link
Copy Markdown
Author

It overlaps with doom_loop, but it addresses a different failure boundary. The existing check runs inside the processor for three identical tool parts in a single assistant response and delegates the outcome to the configurable permission rule. This PR checks consecutive identical calls across assistant turns for the same user prompt and emits a session error before another provider turn. That provides a final runtime circuit breaker even when doom_loop is configured as allow (or repeated calls are split across turns).

I rebased the branch onto the current dev and kept the focused regression tests. The three loop-guard tests pass, package typecheck passes, and the repository pre-push hook completed all 30 typecheck tasks.

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.

subagent: infinite loop of identical tool calls for ~50min with no loop protection, uncontrollable token burn

2 participants