Clawith icon indicating copy to clipboard operation
Clawith copied to clipboard

🚨 P0 Hotfix 2026-10-15: LiteLLM flash model max_tokens too low causing agent loops

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

🚨 P0 Hotfix Deployed to Live — 2026-10-15 12:11 UTC

Problem

Agents on Clawith live were stuck in loops, behaving "dumb". Investigation revealed LiteLLM was routing 50%+ of requests to glm-5.3-flash with insufficient max_tokens, causing output truncation before proper tool_calls could be produced.

Root Causes Found

  1. agent-reviewer: max_tokens was 8192 (too low for ~130K token prompts)
  2. agent-heartbeat: max_tokens was 4096 (way too low)
  3. fallback-reviewer-zai: max_tokens was 8192
  4. Average prompt size: ~130K tokens
  5. Flash models can't handle complex tool schemas properly
  6. DSML tag issue: glm-5.3-flash outputs <|DSML|> XML tags in content instead of proper tool_calls format

What Was Fixed

Increased max_tokens for flash models in LiteLLM config:

Route Before After
agent-reviewer 8192 16384
agent-heartbeat 4096 16384
fallback-reviewer-zai 8192 16384

File modified: /data/coolify/applications/qapy3nmgcxvf6rrg053od7kv/litellm-config.yaml (live)
LiteLLM restarted to apply changes.


Action Items

1. 🔴 Monitor Live (Next 30 min)

# Check LiteLLM health
curl -s https://litellm.moiria.com/health/liveliness

# Check recent errors
docker logs litellm-qapy3nmgcxvf6rrg053od7kv-180712021526 2>&1 | grep -iE "error|fail" | tail -20

# Check model routing distribution
docker logs litellm-qapy3nmgcxvf6rrg053od7kv-180712021526 2>&1 | grep "pre_call" | grep -oP '"route": "\K[^"]+' | sort | uniq -c | sort -rn

# Check finish_reason distribution (should see less "length" now)
docker logs litellm-qapy3nmgcxvf6rrg053od7kv-180712021526 2>&1 | grep "finish_reason" | grep -oP '"finish_reason": "\K[^"]+' | sort | uniq -c | sort -rn

2. 🔴 Deploy to Staging Immediately

  • Copy litellm-config.yaml changes to staging
  • Location: /data/coolify/applications/nv4dzgu1ocmmp5fgb1snyz9q/litellm-config.yaml
  • Restart staging LiteLLM

3. 🔴 Investigate DSML Tag Issue (Critical)

glm-5.3-flash outputs <|DSML|> XML tags in content instead of proper tool_calls. This causes agents to loop because the system can't parse tool calls.

Options:

  • a) Add response sanitizer in custom_callback.py to detect and fix DSML tags
  • b) Switch agent-architect route to non-flash model (glm-5.3 full, not flash)
  • c) Add retry logic: if response has no tool_calls but content has DSML tags, retry with instruction

4. 🟠 Consider Model Routing Changes

  • agent-architect currently uses glm-5.3-flash (50%+ of traffic)
  • Flash models can't handle 434 tool definitions (284K chars)
  • Consider:
    • Routing agent-architect to glm-5.3 (full model, not flash)
    • Implementing tool filtering to reduce payload size
    • Adding context budget enforcement (max 50K tokens)

5. 🟡 Check Cache Hit Ratio

  • Currently 0.2% (almost no caching)
  • 130K tokens per request × 50% of traffic = massive cost
  • Investigate why cache isn't working

Backup Location

  • /data/coolify/applications/qapy3nmgcxvf6rrg053od7kv/litellm-config.yaml.bak-pre-p0-*

Git Commit Required

Changes should be committed to survive redeployment:

cd /data/coolify/applications/qapy3nmgcxvf6rrg053od7kv
git add litellm-config.yaml
git commit -m "fix: increase max_tokens for flash models (P0 hotfix 2026-10-15)"
git push origin main

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