Hmbown/CodeWhale · error · Error

parallel(): max " + MAX_ITEMS + " items per call

Error message

parallel(): max " + MAX_ITEMS + " items per call

What it means

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.

Solutions

  1. Chunk the input into batches of at most MAX_ITEMS and call parallel once per batch (sequentially or nested within limits).
  2. Push the large set to a host task and process it host-side, returning only summary results.
  3. Check thunks.length before calling and degrade gracefully (stream/chunk) rather than throwing.
  4. Raise PARALLEL_MAX_ITEMS only if the host genuinely supports larger fan-outs; prefer chunking.

Example fix

// before
await parallel(items.map(makeThunk)); // items can be 100k
// after
for (let i = 0; i < items.length; i += MAX_ITEMS) {
  await parallel(items.slice(i, i + MAX_ITEMS).map(makeThunk));
}
Defensive patterns

Strategy: validation

Validate before calling

const MAX_ITEMS = 1000; // keep in sync with PARALLEL_MAX_ITEMS
if (thunks.length > MAX_ITEMS) {
  // chunk before calling parallel
}

Type guard

const withinFanOutLimit = (thunks, max) => Array.isArray(thunks) && thunks.length <= max;

Try / catch

try {
  return await parallel(thunks);
} catch (e) {
  if (e.message.includes('max ') && e.message.includes('items per call')) {
    const out = [];
    for (let i = 0; i < thunks.length; i += CHUNK) {
      out.push(...await parallel(thunks.slice(i, i + CHUNK)));
    }
    return out;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/a3f33c0f0404e37f. Report an issue: GitHub.

Appendix: source

Thrown at crates/workflow-js/src/vm.rs:1379

    const envelope = JSON.parse(await hostTask(JSON.stringify(opts)));
    if (envelope.error !== undefined) {
      const err = new Error(envelope.error);
      // The host always names the kind; a missing one means an envelope this
      // prelude did not produce, which is not a typed task failure.
      err.kind = HOST_KINDS.indexOf(envelope.error_kind) !== -1
        ? envelope.error_kind
        : SCRIPT_KIND;
      throw err;
    }
    return envelope.value;
  };

  globalThis.parallel = (thunks, opts) => {
    if (!Array.isArray(thunks)) {
      throw new TypeError("parallel(): expected an array of thunks");
    }
    if (thunks.length > MAX_ITEMS) {
      throw new Error("parallel(): max " + MAX_ITEMS + " items per call");
    }
    const mode = slotMode("parallel", opts);
    const failFast = mode === "fail-fast";
    const partial = mode === "partial";
    const errors = [];
    // Returns the slot value, or throws to reject the whole fan-out.
    const onSlotError = (index, err) => {
      const kind = taskErrorKind(err);
      const message = taskErrorText(err);
      stampKind(err, kind);
      // Cancellation is the run's deadline in every mode, partial included.
      if (kind === "cancelled") throw err;
      if (partial) {
        // Opt-in partial mode: every non-cancellation slot failure becomes a
        // structured value the script can branch on. It never masquerades as
        // a success -- `__taskError` is the whole point of the shape.
        errors.push({ index: index, kind: kind, message: message });
        hostLog(

View on GitHub (pinned to 433685b202)