Planner agent gets stuck in infinite loop when planning undefined projects #6820

Closed
opened 2026-02-16 18:05:22 -05:00 by yindo · 2 comments
Owner

Originally created by @mannyluvstacos on GitHub (Jan 19, 2026).

Originally assigned to: @thdxr on GitHub.

Bug Description

The Planner agent enters an infinite loop when invoked to plan a project that doesn't have existing specs or documentation in the codebase. The agent was invoked via @planner develop opencode-council-swarm and got stuck, requiring manual abort.

Steps to Reproduce

  1. Start an opencode session
  2. Invoke the planner agent with a project that doesn't exist: @planner develop opencode-council-swarm
  3. Observe the agent spinning indefinitely until manually aborted

Expected Behavior

The planner should:

  1. Search for existing specs/docs (reasonable timeout)
  2. If nothing found, acknowledge this and either:
    • Ask clarifying questions about what the project should be
    • Create a plan based on the project name semantics ("council-swarm" suggests multi-agent coordination)
    • Return a "no context found" response with suggestions

Actual Behavior

The agent enters an infinite loop, likely:

  • Repeatedly searching the same locations
  • Making identical exploration queries
  • No termination condition or max iteration limit

Root Cause Hypothesis

  1. No exploration timeout/limit - The planner's exploration phase has no max iterations
  2. Recursive search pattern - When no results found, it may retry the same search
  3. Missing early-exit condition - No check for "zero context found, ask user"
  4. Model looping - The claude-opus-4.5 model may be generating identical tool calls repeatedly

Proposed Fixes

Short-term

  • Add max iteration limit (e.g., 10 exploration attempts)
  • Add timeout for planning phase (e.g., 60 seconds)
  • Detect repeated identical tool calls and break

Long-term

  • Planner should have explicit "context gathering" phase with bounded scope
  • If no specs/docs found after N attempts, prompt user for requirements
  • Add loop detection at the Task tool level

Environment

  • Agent: planner.md (subagent mode)
  • Model: github-copilot/claude-opus-4.5
  • Temperature: 0.2
  • Invocation: @planner develop opencode-council-swarm

Related Context

The planner agent is configured at ~/.config/opencode/agents/planner.md and is designed to create .ralph-plan-*.md files for autonomous execution by Ralph. The loop appears to occur in the exploration phase before any plan file is created.

Additional Notes

This is a usability issue that wastes user time and API tokens. The agent should fail gracefully rather than loop indefinitely.

Originally created by @mannyluvstacos on GitHub (Jan 19, 2026). Originally assigned to: @thdxr on GitHub. ## Bug Description The Planner agent enters an infinite loop when invoked to plan a project that doesn't have existing specs or documentation in the codebase. The agent was invoked via `@planner develop opencode-council-swarm` and got stuck, requiring manual abort. ## Steps to Reproduce 1. Start an opencode session 2. Invoke the planner agent with a project that doesn't exist: `@planner develop opencode-council-swarm` 3. Observe the agent spinning indefinitely until manually aborted ## Expected Behavior The planner should: 1. Search for existing specs/docs (reasonable timeout) 2. If nothing found, acknowledge this and either: - Ask clarifying questions about what the project should be - Create a plan based on the project name semantics ("council-swarm" suggests multi-agent coordination) - Return a "no context found" response with suggestions ## Actual Behavior The agent enters an infinite loop, likely: - Repeatedly searching the same locations - Making identical exploration queries - No termination condition or max iteration limit ## Root Cause Hypothesis 1. **No exploration timeout/limit** - The planner's exploration phase has no max iterations 2. **Recursive search pattern** - When no results found, it may retry the same search 3. **Missing early-exit condition** - No check for "zero context found, ask user" 4. **Model looping** - The claude-opus-4.5 model may be generating identical tool calls repeatedly ## Proposed Fixes ### Short-term - Add max iteration limit (e.g., 10 exploration attempts) - Add timeout for planning phase (e.g., 60 seconds) - Detect repeated identical tool calls and break ### Long-term - Planner should have explicit "context gathering" phase with bounded scope - If no specs/docs found after N attempts, prompt user for requirements - Add loop detection at the Task tool level ## Environment - Agent: `planner.md` (subagent mode) - Model: `github-copilot/claude-opus-4.5` - Temperature: 0.2 - Invocation: `@planner develop opencode-council-swarm` ## Related Context The planner agent is configured at `~/.config/opencode/agents/planner.md` and is designed to create `.ralph-plan-*.md` files for autonomous execution by Ralph. The loop appears to occur in the exploration phase before any plan file is created. ## Additional Notes This is a usability issue that wastes user time and API tokens. The agent should fail gracefully rather than loop indefinitely.
yindo closed this issue 2026-02-16 18:05:22 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 19, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #3038: The model loops attempting to edit files in PLAN mode - Similar looping behavior where agent keeps repeating the same operations without progressing
  • #9284: Agent repeatedly re-asks same question after answer is provided, fails to update plan after Glob result - Exact same symptom of agent not converging and repeating the same query/action
  • #9389: [BUG] it gets stuck in Plan mode - Agent stuck in planning mode with iterating/waiting loop
  • #3743: Loop in certain models - Models repeatedly getting stuck in loops for extended periods

Additionally, this relates to:

  • #9446: feat: Implement opencode-council-swarm - This issue actually originated from attempting to @planner develop opencode-council-swarm which triggered this loop bug

The core issue appears to be missing max iteration limits and loop detection mechanisms in the agent/task execution system.

@github-actions[bot] commented on GitHub (Jan 19, 2026): This issue might be a duplicate of existing issues. Please check: - #3038: The model loops attempting to edit files in PLAN mode - Similar looping behavior where agent keeps repeating the same operations without progressing - #9284: Agent repeatedly re-asks same question after answer is provided, fails to update plan after Glob result - Exact same symptom of agent not converging and repeating the same query/action - #9389: [BUG] it gets stuck in Plan mode - Agent stuck in planning mode with iterating/waiting loop - #3743: Loop in certain models - Models repeatedly getting stuck in loops for extended periods Additionally, this relates to: - #9446: feat: Implement opencode-council-swarm - This issue actually originated from attempting to `@planner develop opencode-council-swarm` which triggered this loop bug The core issue appears to be missing max iteration limits and loop detection mechanisms in the agent/task execution system.
Author
Owner

@mannyluvstacos commented on GitHub (Jan 19, 2026):

please ignore, local agent pushed an issue that was not meant to be pushed

@mannyluvstacos commented on GitHub (Jan 19, 2026): please ignore, local agent pushed an issue that was not meant to be pushed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6820