{"record":{"id":"1ff3d3f80b6e4f91","repo":"JuliusBrussee/caveman","slug":"cave-subagent-input-limit","errorCode":"cave_subagent_input_limit","errorMessage":"cave_subagent_input_limit","messagePattern":"cave_subagent_input_limit","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3872,"sourceCode":"\nasync function executeSubagent(\n  toolDefinition: ToolDefinition,\n  params: unknown,\n  signal: AbortSignal | undefined,\n  parentOptions: InternalRunOptions,\n  usage: NestedUsage,\n  executionContext: InternalExecutionContext,\n  parentMeter: BudgetMeter | undefined,\n  parentDeadlineAt: number | undefined,\n): Promise<unknown> {\n  const runtime = toolDefinition.runtime;\n  if (runtime?.kind !== \"subagent\") throw new Error(\"cave_subagent_runtime_missing\");\n  if (params === null || typeof params !== \"object\" || Array.isArray(params) ||\n      typeof (params as { task?: unknown }).task !== \"string\") {\n    throw new Error(\"cave_subagent_arguments_invalid\");\n  }\n  const task = (params as { task: string }).task;\n  if (task.length > runtime.maxInputChars) throw new Error(\"cave_subagent_input_limit\");\n  const calls = usage.calls.get(toolDefinition.name) ?? 0;\n  if (calls >= runtime.maxCalls) throw new Error(\"cave_subagent_call_budget\");\n  // Reserve synchronously before any await so parallel Pi tool dispatch cannot\n  // pass the same maxCalls check twice.\n  usage.calls.set(toolDefinition.name, calls + 1);\n  const depth = executionContext.depth;\n  const depthLimit = Math.min(\n    parentOptions.maxSubagentDepth ?? DEFAULT_SUBAGENT_DEPTH_LIMIT,\n    ABSOLUTE_SUBAGENT_DEPTH_LIMIT,\n  );\n  if (depth + 1 > depthLimit) throw new Error(\"cave_subagent_depth_limit\");\n  // The wallet is carved here, still synchronously, for the same reason: two\n  // subagents dispatched in one turn must not both be funded out of the same\n  // remaining budget.\n  const walletAmount = parentMeter === undefined\n    ? undefined\n    : parentMeter.denomination === \"usd\" ? runtime.maxCostUsd : runtime.maxTokens;\n  if (parentMeter !== undefined && walletAmount === undefined) {","sourceCodeStart":3854,"sourceCodeEnd":3890,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3854-L3890","documentation":"The runtime caps the character length of the task prompt handed to a subagent at runtime.maxInputChars. A task string longer than this configured limit throws cave_subagent_input_limit, protecting the child agent's context window and cost from oversized inputs.","triggerScenarios":"Calling a subagent tool where typeof params.task === \"string\" but task.length > runtime.maxInputChars — e.g. pasting a large document as the task.","commonSituations":"Asking a subagent to process a big file's contents inline instead of by path; configured maxInputChars too low for the workflow; model echoing huge prior output back as the task text.","solutions":["Shorten the task: reference files/paths by name instead of embedding their contents","Increase runtime.maxInputChars in the subagent runtime configuration if large inputs are legitimate","Split the work into multiple smaller subagent tasks","Pre-truncate or summarize the input before dispatching"],"exampleFix":"// before\ndispatchSubagent({ task: hugeDocument });\n// after\ndispatchSubagent({ task: \"Summarize the file at \" + path + \" (read it yourself)\" });","handlingStrategy":"validation","validationCode":"if (typeof task !== \"string\" || task.length > subagentRuntime.maxInputChars) {\n  task = summarizeOrTruncate(task, subagentRuntime.maxInputChars);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dispatchSubagent({ task });\n} catch (e) {\n  if (e.message === \"cave_subagent_input_limit\") {\n    await dispatchSubagent({ task: task.slice(0, maxInputChars - 1) });\n  } else throw e;\n}","preventionTips":["Truncate or summarize task input to maxInputChars before dispatch","Pass file paths instead of embedding file contents in tasks","Set maxInputChars generously for document-processing workflows","Log task length on dispatch to spot near-limit inputs"],"tags":["subagent","input","limit"],"backgroundTag":"payload-too-large","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}