{"record":{"id":"a3f33c0f0404e37f","repo":"Hmbown/CodeWhale","slug":"parallel-max-max-items-items-per-call","errorCode":null,"errorMessage":"parallel(): max \" + MAX_ITEMS + \" items per call","messagePattern":"parallel\\(\\): max \" \\+ MAX_ITEMS \\+ \" items per call","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/workflow-js/src/vm.rs","lineNumber":1379,"sourceCode":"    const envelope = JSON.parse(await hostTask(JSON.stringify(opts)));\n    if (envelope.error !== undefined) {\n      const err = new Error(envelope.error);\n      // The host always names the kind; a missing one means an envelope this\n      // prelude did not produce, which is not a typed task failure.\n      err.kind = HOST_KINDS.indexOf(envelope.error_kind) !== -1\n        ? envelope.error_kind\n        : SCRIPT_KIND;\n      throw err;\n    }\n    return envelope.value;\n  };\n\n  globalThis.parallel = (thunks, opts) => {\n    if (!Array.isArray(thunks)) {\n      throw new TypeError(\"parallel(): expected an array of thunks\");\n    }\n    if (thunks.length > MAX_ITEMS) {\n      throw new Error(\"parallel(): max \" + MAX_ITEMS + \" items per call\");\n    }\n    const mode = slotMode(\"parallel\", opts);\n    const failFast = mode === \"fail-fast\";\n    const partial = mode === \"partial\";\n    const errors = [];\n    // Returns the slot value, or throws to reject the whole fan-out.\n    const onSlotError = (index, err) => {\n      const kind = taskErrorKind(err);\n      const message = taskErrorText(err);\n      stampKind(err, kind);\n      // Cancellation is the run's deadline in every mode, partial included.\n      if (kind === \"cancelled\") throw err;\n      if (partial) {\n        // Opt-in partial mode: every non-cancellation slot failure becomes a\n        // structured value the script can branch on. It never masquerades as\n        // a success -- `__taskError` is the whole point of the shape.\n        errors.push({ index: index, kind: kind, message: message });\n        hostLog(","sourceCodeStart":1361,"sourceCodeEnd":1397,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/workflow-js/src/vm.rs#L1361-L1397","documentation":"The prelude caps fan-out size: parallel() throws when the thunks array exceeds MAX_ITEMS (PARALLEL_MAX_ITEMS, substituted into the prelude template). This bound keeps a single call's record/replay payload and host load bounded.","triggerScenarios":"Calling parallel(thunks) where thunks.length > MAX_ITEMS — e.g. fanning out over an unbounded input list, a large DB result set, or a per-item loop building thousands of thunks.","commonSituations":"Processing a large dataset in one call instead of chunking; a config/inventory file with thousands of entries; fan-out size driven by user input that grew over time.","solutions":["Chunk the input into batches of at most MAX_ITEMS and call parallel once per batch (sequentially or nested within limits).","Push the large set to a host task and process it host-side, returning only summary results.","Check thunks.length before calling and degrade gracefully (stream/chunk) rather than throwing.","Raise PARALLEL_MAX_ITEMS only if the host genuinely supports larger fan-outs; prefer chunking."],"exampleFix":"// before\nawait parallel(items.map(makeThunk)); // items can be 100k\n// after\nfor (let i = 0; i < items.length; i += MAX_ITEMS) {\n  await parallel(items.slice(i, i + MAX_ITEMS).map(makeThunk));\n}","handlingStrategy":"validation","validationCode":"const MAX_ITEMS = 1000; // keep in sync with PARALLEL_MAX_ITEMS\nif (thunks.length > MAX_ITEMS) {\n  // chunk before calling parallel\n}","typeGuard":"const withinFanOutLimit = (thunks, max) => Array.isArray(thunks) && thunks.length <= max;","tryCatchPattern":"try {\n  return await parallel(thunks);\n} catch (e) {\n  if (e.message.includes('max ') && e.message.includes('items per call')) {\n    const out = [];\n    for (let i = 0; i < thunks.length; i += CHUNK) {\n      out.push(...await parallel(thunks.slice(i, i + CHUNK)));\n    }\n    return out;\n  }\n  throw e;\n}","preventionTips":["Chunk unbounded inputs before fan-out","Assert thunks.length <= MAX_ITEMS at the call site","Move very large batch processing to a host task"],"tags":["limit-exceeded","workflow","fan-out"],"backgroundTag":"payload-too-large","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}