Skip to content

bug: batchTriggerAndWait runs forever when idempotencyKey is provided #2965

@richardneotax

Description

@richardneotax

Provide environment information

System:
OS: macOS 26.2
CPU: (10) arm64 Apple M2 Pro
Memory: 99.34 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.11.0 - ~/.local/share/mise/installs/node/22.11.0/bin/node
Yarn: 4.12.0 - ~/.local/share/mise/installs/node/22.11.0/bin/yarn
npm: 10.9.0 - ~/.local/share/mise/installs/node/22.11.0/bin/npm

Describe the bug

When I try to run batches using taskName.batchTriggerAndWait or batch.triggerByTaskAndWait they are able to run correctly until I provide the idempotencyKey option to the runs. Then the batch never completes.

Reproduction repo

Code provided

To reproduce

Here is a simple example I used to reproduce:

import { task } from '@trigger.dev/sdk';
import { idempotencyKeys, wait } from '@trigger.dev/sdk';

const getOne = task({
  id: 'get-1',
  run: async () => {
    await wait.for({ seconds: 10 });

    return 1;
  }
});

export const sumBatch = task({
  id: 'sum-batch',
  run: async (): Promise<number> => {
    const result = await getOne.batchTriggerAndWait([{
      payload: null,
      options: {
        idempotencyKey: await idempotencyKeys.create('get-1', { scope: 'global' }),
      },
    }, {
      payload: null,
      options: {
        idempotencyKey: await idempotencyKeys.create('get-1', { scope: 'global' }),
      },
    }, {
      payload: null,
      options: {
        idempotencyKey: await idempotencyKeys.create('get-2', { scope: 'global' }),
      },
    }, {
      payload: null,
      options: {
        idempotencyKey: await idempotencyKeys.create('get-3', { scope: 'global' }),
      },
    }]);

    return result.runs.reduce((acc, curr) => {
      if (curr.ok) {
        return acc + curr.output;
      }
      return acc;
    }, 0);
  },
});

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions