Skip to content

Fix debounce forwarding in batchTriggerAndWait arrays#3446

Closed
GautamBytes wants to merge 1 commit intotriggerdotdev:mainfrom
GautamBytes:fix/batch-debounce
Closed

Fix debounce forwarding in batchTriggerAndWait arrays#3446
GautamBytes wants to merge 1 commit intotriggerdotdev:mainfrom
GautamBytes:fix/batch-debounce

Conversation

@GautamBytes
Copy link
Copy Markdown

Summary

Fixes the array input path for batchTriggerAndWait so per-item options.debounce is forwarded instead of being dropped.

The async iterable path already forwarded debounce correctly; this brings the array serializer in line with that behavior for both task.batchTriggerAndWait([...]) and tasks.batchTriggerAndWait(id, [...]).

Closes TRI-8310.

Signed-off-by: Gautam Manchandani <gautammanch@Gautams-MacBook-Air.local>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

🦋 Changeset detected

Latest commit: 6802690

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python Patch
@internal/sdk-compat-tests Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
references-realtime-hooks-test Patch
references-realtime-streams Patch
references-telemetry Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
trigger.dev Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f37bad18-808c-4f95-b02c-3be714d453d5

📥 Commits

Reviewing files that changed from the base of the PR and between d205955 and 6802690.

📒 Files selected for processing (3)
  • .changeset/fix-batch-trigger-and-wait-debounce.md
  • packages/trigger-sdk/src/v3/shared.test.ts
  • packages/trigger-sdk/src/v3/shared.ts

Walkthrough

This pull request adds support for forwarding per-item debounce options in the batchTriggerAndWait function when called with an array of items. The change consists of a one-line implementation update in the shared module that extracts the debounce value from each item's options and includes it in the batch-item request payload, a new test suite validating that debounce options are correctly propagated for both single-task and multi-task batch scenarios, and a changelog entry documenting the patch-level fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

Hi @GautamBytes, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Apr 24, 2026
@GautamBytes
Copy link
Copy Markdown
Author

@ericallam can you check this , not sure why its closed even after claude not added me to vouch.yml

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 batchTrigger_internal array path silently drops per-item debounce options

The PR fixes the missing debounce forwarding in batchTriggerAndWait_internal's array path (line 2510), but the same bug still exists in the sister function batchTrigger_internal at lines 2214-2236. When users call batchTrigger() with an array of items that include per-item debounce options, those options are silently dropped. The streaming counterpart transformSingleTaskBatchItemsStream correctly includes debounce: item.options?.debounce at packages/trigger-sdk/src/v3/shared.ts:2041, confirming this is an oversight. The BatchItem type uses TriggerOptions which includes a debounce field (packages/core/src/v3/types/tasks.ts:946), so users can set it but it has no effect in the array path.

(Refers to lines 2234-2236)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +222 to +332
describe("batchTriggerAndWait debounce forwarding", () => {
afterEach(() => {
vi.doUnmock("@trigger.dev/core/v3");
vi.resetModules();
vi.restoreAllMocks();
});

async function setupBatchTriggerAndWaitHarness() {
vi.resetModules();

const capturedItems: any[] = [];

const createBatch = vi.fn(async ({ runCount }: { runCount: number }) => ({
id: "batch_test123",
runCount,
publicAccessToken: "access_token",
isCached: false,
}));

const streamBatchItems = vi.fn(async (_batchId: string, items: any[]) => {
capturedItems.push(...items);

return {
id: "batch_test123",
itemsAccepted: items.length,
itemsDeduplicated: 0,
sealed: true,
};
});

const waitForBatch = vi.fn(async ({ id }: { id: string }) => ({
id,
items: [],
}));

vi.doMock("@trigger.dev/core/v3", async (importOriginal) => {
const original = await importOriginal<typeof import("@trigger.dev/core/v3")>();

return {
...original,
apiClientManager: {
clientOrThrow: vi.fn(() => ({
createBatch,
streamBatchItems,
})),
} as any,
runtime: {
...original.runtime,
waitForBatch,
} as any,
taskContext: {
ctx: {
run: {
id: "run_123",
isTest: false,
},
},
worker: {
version: "worker_123",
},
} as any,
};
});

const tasksModule = await import("./tasks.js");

return {
...tasksModule,
capturedItems,
createBatch,
streamBatchItems,
waitForBatch,
};
}

it("forwards per-item debounce for task.batchTriggerAndWait array items", async () => {
const { task, capturedItems, streamBatchItems, waitForBatch } =
await setupBatchTriggerAndWaitHarness();
const debounce = { key: "same-key", delay: "30s", mode: "trailing" as const };
const taskId = `batch-debounce-task-${++taskIdCounter}`;

const myTask = task({
id: taskId,
run: async (payload: { id: string }) => payload,
});

await myTask.batchTriggerAndWait([{ payload: { id: "a" }, options: { debounce } }]);

expect(streamBatchItems).toHaveBeenCalledTimes(1);
expect(waitForBatch).toHaveBeenCalledTimes(1);
expect(capturedItems).toHaveLength(1);
expect(capturedItems[0]?.task).toBe(taskId);
expect(capturedItems[0]?.options?.debounce).toEqual(debounce);
});

it("forwards per-item debounce for tasks.batchTriggerAndWait array items", async () => {
const { tasks, capturedItems, streamBatchItems, waitForBatch } =
await setupBatchTriggerAndWaitHarness();
const debounce = { key: "same-key", delay: "30s", mode: "trailing" as const };

await tasks.batchTriggerAndWait("batch-debounce-by-id-task", [
{ payload: { id: "a" }, options: { debounce } },
]);

expect(streamBatchItems).toHaveBeenCalledTimes(1);
expect(waitForBatch).toHaveBeenCalledTimes(1);
expect(capturedItems).toHaveLength(1);
expect(capturedItems[0]?.task).toBe("batch-debounce-by-id-task");
expect(capturedItems[0]?.options?.debounce).toEqual(debounce);
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 New tests use vi.doMock/vi.fn contrary to repo testing conventions

The new batchTriggerAndWait debounce forwarding test suite at packages/trigger-sdk/src/v3/shared.test.ts:222-332 uses vi.doMock, vi.fn(), vi.resetModules(), and vi.restoreAllMocks(). The repository's testing guidelines in ai/references/tests.md:78-83 explicitly state 'Do not mock anything', 'Do not use mocks in tests', and 'Do not use spies in tests'. However, this is a case where testing SDK option forwarding through internal functions practically requires mocking the API client and runtime — there's no Redis/Postgres dependency where testcontainers could substitute. The prose in ai/references/tests.md:26 also says 'We almost NEVER mock anything' (emphasis on 'almost'), suggesting rare exceptions exist. Worth discussing whether this test approach is acceptable or if an alternative testing strategy should be used.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant