{"record":{"id":"e5d4448018267bc2","repo":"JuliusBrussee/caveman","slug":"cave-delegate-missing-task","errorCode":null,"errorMessage":"cave_delegate_missing_task","messagePattern":"cave_delegate_missing_task","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/delegate/caveman-delegate-mcp.mjs","lineNumber":143,"sourceCode":"  },\n};\n\nasync function handle(msg) {\n  const { id, method, params } = msg;\n  if (method === \"initialize\") {\n    return {\n      protocolVersion: params?.protocolVersion || PROTOCOL_FALLBACK,\n      capabilities: { tools: { listChanged: false } },\n      serverInfo: { name: \"caveman-delegate\", version: \"0.1.0\" },\n    };\n  }\n  if (method === \"tools/list\") return { tools: [TOOL] };\n  if (method === \"ping\") return {};\n  if (method === \"tools/call\") {\n    if (params?.name !== TOOL.name) throw new Error(`unknown tool: ${params?.name}`);\n    if (process.env.CAVEMAN_DELEGATE_CHILD === \"1\") throw new Error(\"cave_delegate_depth_exceeded\");\n    const task = params?.arguments?.task;\n    if (!task || typeof task !== \"string\") throw new Error(\"cave_delegate_missing_task\");\n    const r = await runWorker(task, params?.arguments?.cwd);\n    const lines = [r.out || \"(worker produced no output)\"];\n    if (r.usage) {\n      const u = r.usage;\n      let usageLine = `delegate usage (measured, provider-reported): input ${u.input + u.cacheRead + u.cacheWrite} (cacheRead ${u.cacheRead}, cacheWrite ${u.cacheWrite}), output ${u.output}`;\n      if (u.cost > 0) usageLine += `, cost $${u.cost.toFixed(4)}`;\n      lines.push(\"---\", usageLine);\n    }\n    if (r.code !== 0) {\n      lines.push(\"---\", `worker exit ${r.code}: ${r.err.slice(-500)}`);\n      return { content: [{ type: \"text\", text: lines.join(\"\\n\") }], isError: true };\n    }\n    return { content: [{ type: \"text\", text: lines.join(\"\\n\") }] };\n  }\n  if (method?.startsWith(\"notifications/\")) return undefined;\n  throw Object.assign(new Error(`method not found: ${method}`), { code: -32601 });\n}\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/agents/delegate/caveman-delegate-mcp.mjs#L125-L161","documentation":"The caveman-delegate MCP server throws this when a tools/call arrives without a usable arguments.task — the task must be a non-empty string; it is the one required argument of the delegate tool and the prompt handed to the worker subprocess.","triggerScenarios":"Calling the delegate tool with arguments omitted, with task set to null/undefined/number/object, or with an empty string — commonly a client schema bug or a template variable that rendered empty.","commonSituations":"Client forms that submit before input; templating producing empty strings; passing the task under a different key (prompt, query, description); JSON.stringify dropping undefined fields.","solutions":["Pass arguments as { task: \"<non-empty instruction string>\" }","Validate and require the task field in the caller's form or schema before issuing tools/call","If the task is built from variables, fail loudly upstream when it composes to empty"],"exampleFix":"// before\nawait rpc(\"tools/call\", { name, arguments: { cwd } }); // task missing\n\n// after\nif (!task?.trim()) throw new Error(\"task is required\");\nawait rpc(\"tools/call\", { name, arguments: { task, cwd } });","handlingStrategy":"validation","validationCode":"const callArgs = { task, cwd };\nif (typeof callArgs.task !== \"string\" || callArgs.task.trim() === \"\") {\n  throw new Error(\"delegate requires a non-empty task string\");\n}\nawait rpc(\"tools/call\", { name, arguments: callArgs });","typeGuard":"function isDelegateArgs(a) {\n  return typeof a === \"object\" && a !== null && typeof a.task === \"string\" && a.task !== \"\";\n}","tryCatchPattern":"try { await callDelegate(task); }\ncatch (e) {\n  if (String(e?.message) === \"cave_delegate_missing_task\") { /* surface a form-level 'task required' error */ }\n  else throw e;\n}","preventionTips":["Require the task field in the client's input schema or UI before the call","Compose task strings from variables only after checking they are non-empty"],"tags":["mcp","validation","delegate"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}