From 7d82eff753cbdf61e0fd15c30e9a7fd4a8cde99b Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 5 May 2026 20:12:15 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20handle=20truncated=20tool=20call=20JSON?= =?UTF-8?q?=20=E2=80=94=20guide=20model=20to=20use=20bash=20heredoc=20for?= =?UTF-8?q?=20large=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When file_write gets a 15KB+ HTML payload, the streaming JSON gets truncated. Now catches JSON parse errors and returns a specific hint to use bash heredoc instead of silently failing. --- src/bot/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/bot/index.js b/src/bot/index.js index a9e2b3c4..6085cfbc 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -426,7 +426,20 @@ export async function initBot(config, api, tools, skills, agents) { if (!handler) { result = `❌ Unknown tool: ${fn.name}`; } else { - const args = JSON.parse(fn.arguments || '{}'); + let args; + try { + args = JSON.parse(fn.arguments || '{}'); + } catch (parseErr) { + // Tool call JSON was truncated (common with large file content in file_write) + const argLen = (fn.arguments || '').length; + result = `❌ ${fn.name} failed: Tool call arguments JSON was truncated (${argLen} chars). ` + + (fn.name === 'file_write' + ? 'The file content is too large for a single tool call. Use bash with heredoc instead: bash({ command: "cat > /path/to/file << \'EOF\'\\ncontent here\\nEOF" })' + : 'Retry with shorter arguments or split into smaller calls.'); + logger.error(` → ${fn.name} failed: ${parseErr.message} (args length: ${argLen})`); + loopMessages.push({ role: 'tool', tool_call_id: tc.id, content: result }); + continue; + } logger.info(` → ${fn.name}(${fn.arguments?.slice(0, 100)})`); result = String(await handler(args)).slice(0, 8000); }