{"record":{"id":"ebaf7f49c843fac5","repo":"different-ai/openwork","slug":"invaliddatavalue-ebaf7f","errorCode":"InvalidDataValue","errorMessage":"${label} exceeds the maximum value depth of ${MAX_VALUE_DEPTH}.","messagePattern":"(.+?) exceeds the maximum value depth of (.+?)\\.","errorType":"error_code","errorClass":"ToolRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/tool-runtime.ts","lineNumber":182,"sourceCode":" * - **Intra-sandbox checkpoint** (`preserveSandboxValues` true; see `boundedData` in\n *   codemode.ts): standard-library value instances pass through untouched (treated as leaves,\n *   contents not walked), so values flowing through `Object.*` helpers, coercion inputs, and\n *   other in-sandbox checkpoints stay fully usable (`.getTime()`, `.has()`, ...).\n *\n * Both modes reject un-awaited promises with an await-hinting diagnostic.\n */\nexport const copyIn = (value: unknown, label: string, preserveSandboxValues = false): unknown =>\n  copyBounded(value, label, 0, new Set(), preserveSandboxValues)\n\nconst copyBounded = (\n  value: unknown,\n  label: string,\n  depth: number,\n  seen: Set<object>,\n  preserveSandboxValues: boolean,\n): unknown => {\n  if (depth > MAX_VALUE_DEPTH) {\n    throw new ToolRuntimeError(\"InvalidDataValue\", `${label} exceeds the maximum value depth of ${MAX_VALUE_DEPTH}.`)\n  }\n  if (\n    value === null ||\n    value === undefined ||\n    typeof value === \"string\" ||\n    typeof value === \"boolean\" ||\n    // NaN/Infinity are allowed to exist as in-sandbox intermediates (matching real JS and a real\n    // engine) so defensive guards like `Number.isNaN(x)` / `parseInt(x) || 0` can run. They are\n    // normalized to `null` when the value leaves the sandbox - see copyOut - exactly as\n    // JSON.stringify already does at any tool boundary.\n    typeof value === \"number\"\n  ) {\n    return value\n  }\n\n  if (typeof value !== \"object\") {\n    throw new ToolRuntimeError(\"InvalidDataValue\", `${label} must contain data only.`)\n  }","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/tool-runtime.ts#L164-L200","documentation":"CodeMode bounds every value crossing the tool/interpreter boundary (copyIn/copyBounded/copied) to a maximum nesting depth (MAX_VALUE_DEPTH). Deeply nested objects/arrays beyond that limit are rejected with this InvalidDataValue ToolRuntimeError to prevent stack exhaustion and runaway memory when copying values in or out of the sandbox.","triggerScenarios":"Passing a self-referential or very deeply nested object as a tool argument or return value; a linked-list-like structure built by recursive code; circular JSON-style data.","commonSituations":"Host tool returns a deep ORM/graph result; recursive algorithms build structures deeper than the limit; accidental circular references in cached objects.","solutions":["Flatten the data before passing it (e.g. JSON round-trip after removing cycles, or serialize rows instead of a nested tree).","Break cycles before copying: track visited nodes and replace back-references with ids.","Select only the needed subset of fields to reduce depth.","Raise MAX_VALUE_DEPTH only deliberately, understanding the stack/memory cost."],"exampleFix":"// before\ntool.run({ tree: cyclicNode }) // circular/deep\n// after\nconst safe = JSON.parse(JSON.stringify(cyclicNode, (k, v) => v === cyclicNode.parent ? null : v))\ntool.run({ tree: safe })","handlingStrategy":"validation","validationCode":"function depth(v, d = 0, seen = new Set()) {\n  if (d > 16 || (typeof v === \"object\" && v !== null && seen.has(v))) throw new RangeError(\"too deep or circular\")\n  if (typeof v === \"object\" && v !== null) { seen.add(v); for (const k of Object.keys(v)) depth(v[k], d + 1, seen) }\n  return v\n}","typeGuard":"const isShallowEnough = (v, max = 16) => { try { depth(v, 0, new Set()); return true } catch { return false } }","tryCatchPattern":"try { sandboxArgs = copyIn(data) } catch (e) { if (e.code === \"InvalidDataValue\") sandboxArgs = copyIn(flatten(data)) }","preventionTips":["Strip cycles before passing data across the boundary","Project only needed fields to keep trees shallow","Sanitize deep ORM/graph results before tool calls"],"tags":["codemode","depth-limit","data-validation","sandbox"],"backgroundTag":"max-depth-exceeded","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}