{"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":"Error","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/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/agent/src/index.ts#L151-L187","documentation":"Thrown by the subagent() builder (packages/agent/src/index.ts:169): options.maxInputChars is not a positive safe integer. It defaults to 32768; an explicit value must be a whole number >= 1 (and within Number.MAX_SAFE_INTEGER) because it caps subagent input deterministically.","triggerScenarios":"Calling subagent({ maxInputChars, ... }) with 0, a negative number, a fractional value like 1024.5, NaN/Infinity, or a non-number (e.g. the string '32768').","commonSituations":"Passing a computed size that can be 0 (e.g. derived from remaining context); loading the value from config/env without coercion (string from process.env); using Infinity intending 'no limit'; float math producing fractional caps.","solutions":["Pass a positive integer literal or validated integer, e.g. 65536.","When reading from env/config, coerce and validate first: Number.isSafeInteger(n) && n > 0.","For 'unlimited' intent, omit the option and use the default (32768) or pick an explicit large integer cap."],"exampleFix":"// before\nsubagent({ maxInputChars: Number(process.env.SUBAGENT_INPUT), /* ... */ }); // string or NaN\n\n// after\nconst maxInputChars = Number(process.env.SUBAGENT_INPUT);\nsubagent({ maxInputChars: Number.isSafeInteger(maxInputChars) && maxInputChars > 0 ? maxInputChars : 32768, /* ... */ });","handlingStrategy":"type-guard","validationCode":"function isPositiveSafeInteger(v: unknown): v is number {\n  return typeof v === \"number\" && Number.isSafeInteger(v) && v > 0;\n}\nconst maxInputChars = isPositiveSafeInteger(config.maxInputChars) ? config.maxInputChars : undefined; // falls back to 32768 default","typeGuard":"function isPositiveSafeInteger(v: unknown): v is number {\n  return typeof v === \"number\" && Number.isSafeInteger(v) && v > 0;\n}","tryCatchPattern":null,"preventionTips":["Omit maxInputChars to use the 32768 default unless a specific cap is needed.","Coerce and validate env/config values with Number.isSafeInteger before passing.","Guard computed caps (e.g. 'remaining budget' derivations) against 0 with Math.max(1, Math.floor(x))."],"tags":["validation","subagent","configuration","limits"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}