{"record":{"id":"c38ca2a3640da1d0","repo":"JuliusBrussee/caveman","slug":"caveman-agent-subagent-maxinputchars-must-be-a-po","errorCode":null,"errorMessage":"caveman agent: subagent maxInputChars must be a positive integer","messagePattern":"caveman agent: subagent maxInputChars must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/index.ts","lineNumber":169,"sourceCode":"  maxInputChars?: number;\n  maxCalls?: number;\n  /**\n   * This child's wallet in USD. Under a USD-metered run the wallet is carved\n   * out of the parent's **remaining** budget when the child is spawned, and its\n   * unspent remainder returns to the parent when the child finishes.\n   */\n  maxCostUsd?: number;\n  /**\n   * This child's wallet in tokens — the denomination sibling of `maxCostUsd`,\n   * used by a token-metered run. A token-metered run cannot fund a subagent\n   * that declares no token wallet.\n   */\n  maxTokens?: number;\n  maxContextTokens?: number;\n}): ToolDefinition {\n  const maxInputChars = options.maxInputChars ?? 32_768;\n  if (!Number.isSafeInteger(maxInputChars) || maxInputChars <= 0) {\n    throw new Error(\"caveman agent: subagent maxInputChars must be a positive integer\");\n  }\n  const maxCalls = options.maxCalls ?? 1;\n  const maxCostUsd = options.maxCostUsd ?? 1;\n  const maxContextTokens = options.maxContextTokens ?? 128_000;\n  if (!Number.isSafeInteger(maxCalls) || maxCalls <= 0) {\n    throw new Error(\"caveman agent: subagent maxCalls must be a positive integer\");\n  }\n  if (!Number.isFinite(maxCostUsd) || maxCostUsd <= 0) {\n    throw new Error(\"caveman agent: subagent maxCostUsd must be positive\");\n  }\n  if (options.maxTokens !== undefined &&\n      (!Number.isSafeInteger(options.maxTokens) || options.maxTokens <= 0)) {\n    throw new Error(\"caveman agent: subagent maxTokens must be a positive integer\");\n  }\n  if (!Number.isSafeInteger(maxContextTokens) || maxContextTokens <= 0) {\n    throw new Error(\"caveman agent: subagent maxContextTokens must be a positive integer\");\n  }\n  return tool({","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/index.ts#L151-L187","documentation":"The subagent() tool factory validates maxInputChars (default 32768) and throws if it is not a positive safe integer, i.e. zero, negative, non-integer, or beyond Number.MAX_SAFE_INTEGER are all rejected. The option caps how many input characters a subagent invocation may receive.","triggerScenarios":"subagent({ maxInputChars: 0 }) or -1; passing a float like 1024.5; passing Infinity/NaN (e.g. from a misparsed config value); passing a string from env config without parsing.","commonSituations":"Reading the limit from config/env where an empty string or 'unlimited' becomes NaN; attempting to disable the cap with 0; arithmetic producing fractional values.","solutions":["Omit maxInputChars to use the 32_768 default","Pass a positive safe integer (e.g. 65536) parsed with Number.parseInt and validated with Number.isSafeInteger","Clamp: maxInputChars = Math.max(1, Math.floor(value)) after parsing","Fix the config source so the value is numeric, not a string/NaN"],"exampleFix":"// before\nsubagent({ maxInputChars: Number(process.env.SUBAGENT_LIMIT) }); // NaN if unset\n// after\nconst n = Number.parseInt(process.env.SUBAGENT_LIMIT ?? \"32768\", 10);\nsubagent({ maxInputChars: Number.isSafeInteger(n) && n > 0 ? n : 32768 });","handlingStrategy":"validation","validationCode":"const n = options.maxInputChars ?? 32768;\nif (!Number.isSafeInteger(n) || n <= 0) throw new Error(\"maxInputChars must be a positive integer\");","typeGuard":"const isValidMaxInputChars = (v) => v === undefined || (Number.isSafeInteger(v) && v > 0);","tryCatchPattern":"try { tool = subagent(opts); } catch (err) { if (String(err.message).includes(\"maxInputChars must be a positive integer\")) { tool = subagent({ ...opts, maxInputChars: 32768 }); } else throw err; }","preventionTips":["Parse numeric config with explicit radix and validate with Number.isSafeInteger","Never pass raw env strings as numeric options","Use Math.floor/Math.max(1, ...) to sanitize computed limits","Rely on the documented default (32768) instead of sentinel values like 0"],"tags":["validation","subagent","config"],"backgroundTag":"invalid-config-value","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"}