🚨 P0 Hotfix 2026-10-15: LiteLLM flash model max_tokens too low causing agent loops
🚨 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
- agent-reviewer:
max_tokenswas 8192 (too low for ~130K token prompts) - agent-heartbeat:
max_tokenswas 4096 (way too low) - fallback-reviewer-zai:
max_tokenswas 8192 - Average prompt size: ~130K tokens
- Flash models can't handle complex tool schemas properly
- DSML tag issue:
glm-5.3-flashoutputs<|DSML|>XML tags in content instead of propertool_callsformat
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.yamlchanges 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.pyto detect and fix DSML tags - b) Switch
agent-architectroute to non-flash model (glm-5.3full, not flash) - c) Add retry logic: if response has no
tool_callsbut content has DSML tags, retry with instruction
4. 🟠Consider Model Routing Changes
agent-architectcurrently usesglm-5.3-flash(50%+ of traffic)- Flash models can't handle 434 tool definitions (284K chars)
- Consider:
- Routing
agent-architecttoglm-5.3(full model, not flash) - Implementing tool filtering to reduce payload size
- Adding context budget enforcement (max 50K tokens)
- Routing
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
Moved to lesmoires/Clawith fork - all work is now done in the fork, not upstream