Skip to content

fix: add maxTurns limit to prevent agent loop runaway#36

Closed
NSEvent wants to merge 1 commit intoqwibitai:mainfrom
NSEvent:fix/add-maxturns-limit
Closed

fix: add maxTurns limit to prevent agent loop runaway#36
NSEvent wants to merge 1 commit intoqwibitai:mainfrom
NSEvent:fix/add-maxturns-limit

Conversation

@NSEvent
Copy link
Copy Markdown

@NSEvent NSEvent commented Feb 2, 2026

Summary

Fixes #30 - Adds maxTurns limit and improves tool response format to prevent agent loop runaway.

Changes

1. Add maxTurns: 10 to query options

File: container/agent-runner/src/index.ts

options: {
  maxTurns: 10, // Prevent runaway loops (see issue #30)
  // ... other options
}

10 turns is sufficient for complex tasks while preventing runaway behavior that caused the incident (21 duplicate messages in 32 seconds).

2. Improve send_message tool response

File: container/agent-runner/src/ipc-mcp.ts

Before (ambiguous):

Message queued for delivery (filename)

After (clear success signal):

✓ Message sent successfully. The user will receive: "preview of message..."

The clearer response format helps the SDK understand the task is complete, reducing retry behavior.

Test plan

  • Rebuild container: ./container/build.sh
  • Test with reminder request to verify no duplicate sends
  • Verify agent completes within 10 turns for normal tasks

Acceptance Criteria from Issue

  • maxTurns: 10 added to query options in container/agent-runner/src/index.ts
  • Tool response format improved in ipc-mcp.ts

🤖 Generated with Claude Code

Addresses issue qwibitai#30 with two changes:

1. Add `maxTurns: 10` to the query options in agent-runner
   - Prevents unlimited loop iterations that can cause duplicate messages
   - 10 turns is sufficient for complex tasks while preventing runaway behavior

2. Improve `send_message` tool response format
   - Changed from ambiguous "queued for delivery" to clear "✓ Message sent successfully"
   - Includes preview of sent message for confirmation
   - Better signals task completion to prevent SDK retry behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@NSEvent NSEvent requested a review from gavrielc as a code owner February 2, 2026 16:30
chidev added a commit to lev-os/nanoclaw that referenced this pull request Feb 3, 2026
Adds maxTurns: 10 to agent query options and improves send_message
tool response to give clear success signal, preventing retries.

Cherry-picked from upstream PR qwibitai#36.
chidev added a commit to lev-os/nanoclaw that referenced this pull request Feb 3, 2026
Adds maxTurns: 10 to agent query options and improves send_message
tool response to give clear success signal, preventing retries.

Cherry-picked from upstream PR qwibitai#36.
@gavrielc gavrielc force-pushed the main branch 2 times, most recently from c83bc27 to 80e68dc Compare February 3, 2026 15:03
@gavrielc
Copy link
Copy Markdown
Collaborator

gavrielc commented Feb 3, 2026

@NSEvent Thank you for the PR.

maxTurns is not an appropriate fix to the issue you reported. This would end every session after 10 turns (i.e. 10 messages between the user and the agent). With this kind of agent, people typically want the same session to continue indefinitely (auto-compaction clears the context window when needed). There is an explicit clear command for clearing the conversation and starting a new session.

Closing this I'm not sure it's an appropriate fix. Will look into the issue separately

@gavrielc gavrielc closed this Feb 3, 2026
dratspiker added a commit to dratspiker/nanoclaw that referenced this pull request Mar 19, 2026
jbaruch pushed a commit to jbaruch/nanoclaw-public that referenced this pull request Apr 9, 2026
…, duplicate check

Promote script now:
- Validates tile placement before copying (red flag grep for admin content)
- Blocks skills that already exist in another tile (prevents duplicates)
- Reports blocked items with reasoning

New rule: no-inplace-overrides — all changes via promotion pipeline only,
never write directly to /workspace/group/skills/.

Updated skill-tile-placement rule with:
- More examples (17 skills mapped)
- Explicit "ASK Baruch when in doubt" instead of silent default
- "Skills must NEVER duplicate across tiles" section
- Clearer red flag list

Bump admin 0.1.104.

Closes qwibitai#36.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kenansun-dev-bot Bot pushed a commit to kenansun-dev/nanoclaw-github-copilot that referenced this pull request Apr 12, 2026
…ibitai#36)

1. DEFAULT_CONFIG in init.ts updated to agents.defaults format
   (was old providers format)
2. host-runner always uses source .ts (not stale dist/)
3. Init next steps mention host mode option

344/344 tests pass.

Co-authored-by: Kenan VM Claw <vm-claw@kenan.dev>
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.

fix: Add maxTurns limit to prevent agent loop runaway

2 participants