Clawith icon indicating copy to clipboard operation
Clawith copied to clipboard

P0 Hotfix: Success loop detection — agents stuck calling same tool indefinitely

Open up-guillaume opened this issue 1 month ago • 1 comments

🚨 P0 Incident — Deployed 2026-10-15 12:11 UTC

Summary

All agents on Clawith live (agents.moiria.com) were stuck in tool loops, calling the same tool repeatedly for up to 3 days (since Oct 12). The existing anti-loop system failed to detect these loops.

Symptoms

  • SEO agent called "Google Ads Staging Health Check" 69 times in a row
  • Loop ran for 3 days undetected
  • Agents appeared "dumb" — repeating identical operations
  • Context bloat from accumulated tool calls degraded all sessions

Root Causes Identified

  1. Hardcoded discovery tool whitelist — Anti-loop system only watched 12 specific discovery tools. Health check tools (and any others) weren't in the list, so loops went undetected.

  2. Exact-args matching too strict — Identical-args detection required exact argument match. If args varied slightly between calls, the detection never triggered.

  3. No "successful but pointless" detection — If a tool returned success but the agent kept calling it anyway, nothing stopped the loop. The system only caught failures.

  4. Context bloat — 284K chars of tool definitions per request (434 tools, ~100K tokens). Large context makes models more likely to get stuck in patterns.

  5. DSML tag corruption — Flash models (glm-5.3-flash) output <|DSML|> XML tags instead of proper tool_calls format, causing parsing failures and retry loops.

Fix Deployed (P0 Hotfix)

File: backend/app/services/telemetry.py

Added check_success_loop(session_id, tool_name) function:

  • Warns at 6 consecutive calls to the same tool (regardless of args or results)
  • Hard blocks at 10 consecutive calls
  • Tracks by (session_id, tool_name) pair
  • Independent of the existing discovery-tool whitelist

File: backend/app/services/llm/caller.py

  • Integrated check_success_loop() call after tool execution (after line 492)
  • Placed after update_productive_tracking() in the execution flow
  • Logs warnings with SUCCESS_LOOP tag for monitoring

Immediate Actions Required

1. Monitor Live (next 30 min)

docker logs backend-twcgssk... 2>&1 | grep -i "SUCCESS_LOOP"

Should see warnings when agents hit the 6-call threshold. Loops should now be broken automatically.

2. Deploy to Staging

Copy the telemetry.py changes to staging:

# Source (live)
LIVE_PATH=/data/coolify/applications/twcgssk04ckw4kgw0gcwcw48/backend/app/services/telemetry.py
# Destination (staging)
STAGING_PATH=/data/coolify/applications/ifjyy4gnl8lt3z3bpu6e7xt9/backend/app/services/telemetry.py

cp "$LIVE_PATH" "$STAGING_PATH"
# Then restart staging backend

3. Fix DSML Sanitizer (Not Yet Deployed)

Flash models (glm-5.3-flash) output malformed tags. Need to add _sanitize_dsml_tags() to caller.py:

  • Detect patterns: <|DSML|>, `

up-guillaume avatar Oct 15 '26 12:10 up-guillaume

Moved to lesmoires/Clawith fork - all work is now done in the fork, not upstream

up-guillaume avatar Oct 20 '26 11:10 up-guillaume