Bugfix: Why did chat show '413 Payload Too Large' after agent loop c...

Documentation for Sessions

🐛 Bugfix: Why did chat show '413 Payload Too Large' after agent loop c...

Date: 2026-03-09
Time: 19:37:55 UTC
Session: gspace1-191.5
Agent: backend
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

Why did chat show '413 Payload Too Large' after agent loop completed with many tool calls?

Task: Not specified


🎯 Decision Made

Chosen:

Raised JSON body limit from NestJS default 100KB to 5MB in backend-ai-api main.ts. Also raised frontend chat timeout from 60s to 5min, and fixed deprecated haiku model ID.

Options Considered:

  1. Truncate tool metadata before persistence
  2. Raise body limit (chosen)
  3. Compress payload with gzip
  4. Stream persistence in chunks

💭 Reasoning

Three cascading issues: (1) Agent loop with 18 tool calls (recall_memory, search_decisions) produced a response with embedded tool metadata exceeding 100KB NestJS default. Frontend tried to persist this to /ai-api/sessions/.../messages and got 413. (2) The 60s frontend timeout was too aggressive for agent loops that routinely take 2-4 minutes with tool calls, causing 'response is taking longer than expected' before completion. (3) SmartRouter fallback used deprecated model claude-3-5-haiku-20241022 which returned 404, forcing OpenAI failover.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation