gemini-cli - 💡(How to fix) Fix [Bug] Agent gets stuck in infinite Tool-use Looping (echo commands) when resolving strict negative output constraints [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25014Fetched 2026-04-10 03:45:27
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
labeled ×2

Error Message

  1. Wait until the system intervention triggers the Potential loop detected error.

Root Cause

Root Cause Analysis:

Fix Action

Fix / Workaround

Potential Mitigation for the framework:

Workaround for Skill Authors:

RAW_BUFFERClick to expand / collapse

What happened?

When using a custom skill (gh-address-cr) that implements a strict negative output contract (e.g., "Never output 'done', 'all resolved' or equivalent unless X condition is met"), the Agent correctly meets the condition but becomes "paralyzed" during the state transition from tool execution back to chat response.

Instead of breaking out of the ReAct loop and generating the final text summary, the agent repeatedly calls run_shell_command with redundant echo commands (e.g., echo "completed", echo "Ready to finish", echo "Done") as "noop for thought transitions". This creates an infinite loop that continues until the CLI's internal safety mechanism ("System: Potential loop detected.") forcefully interrupts the turn.

Steps to Reproduce:

  1. Execute a skill that contains strict negative output constraints (e.g., Never output "done" without final_gate.sh pass).
  2. Have the agent successfully complete all prerequisites and pass the validation gate.
  3. Observe the agent's internal tool calls: it will successfully run the final validation tool but then fail to output the final text response, opting instead to repeatedly invoke run_shell_command with echo commands.
  4. Wait until the system intervention triggers the Potential loop detected error.

Root Cause Analysis:

The ReAct model experiences "Reasoning Paralysis" due to the high penalty weight of the negative constraint in the prompt. Even when the condition is met, the model assigns a lower probability to directly outputting the completion text (fearing it might violate the constraint) and instead chooses the "safe" action of invoking another tool (echo), causing a loop.

[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.

Use this skill: https://github.com/RbBtSn0w/gh-address-cr-skill

What did you expect to happen?

Once the agent has successfully executed the necessary tools and met the criteria required to bypass the negative constraint, it should immediately break out of the tool-use loop and generate the final textual response (the "Completion Output Contract") to the user without generating redundant echo tool calls.

Client information

  • CLI Version: 0.36.0
  • Git Commit: 8b1e649c2
  • Session ID: 3ca86e45-6fcf-487b-b7a2-43be60aac661
  • Operating System: darwin v25.8.2
  • Sandbox Environment: no sandbox
  • Model Version: gemini-3.1-pro-preview
  • Auth Type: oauth-personal
  • Memory Usage: 198.2 MB
  • Terminal Name: tmux 3.6a
  • Terminal Background: #000000
  • Kitty Keyboard Protocol: Unsupported

Login information

No response

Anything else we need to know?

This issue highlights a common failure mode in LLM Agent architectures dealing with hard negative constraints.

Potential Mitigation for the framework:

Consider adding logic to the ReAct parser that detects sequential, semantically identical, or zero-impact tool calls (like sequential echo commands that don't capture stdout) and prompts the model to break out of the loop and generate a text response.

Workaround for Skill Authors:

Adding explicit "State Transition Permissions" to the skill prompt (e.g., "Once the gate passes, you MUST immediately stop calling tools and output the final summary directly to the user in normal text") helps the model overcome this probabilistic hesitation.

extent analysis

TL;DR

The agent can be fixed by adding explicit "State Transition Permissions" to the skill prompt to overcome the probabilistic hesitation caused by strict negative output constraints.

Guidance

  • Identify the strict negative output constraints in the custom skill (gh-address-cr) and assess their impact on the agent's behavior.
  • Consider adding logic to the ReAct parser to detect sequential, semantically identical, or zero-impact tool calls and prompt the model to break out of the loop.
  • Add explicit "State Transition Permissions" to the skill prompt, such as "Once the gate passes, you MUST immediately stop calling tools and output the final summary directly to the user in normal text".
  • Verify that the agent correctly breaks out of the tool-use loop and generates the final textual response after adding the permissions.

Example

No code snippet is provided as the issue does not require a specific code change, but rather a modification to the skill prompt.

Notes

The provided workaround may not apply to all cases, and the root cause analysis suggests that the issue is related to the ReAct model's "Reasoning Paralysis" due to high penalty weights. Further investigation may be required to fully resolve the issue.

Recommendation

Apply the workaround by adding explicit "State Transition Permissions" to the skill prompt, as this is a straightforward and effective way to address the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix [Bug] Agent gets stuck in infinite Tool-use Looping (echo commands) when resolving strict negative output constraints [1 participants]