Skip to content

Conversation

@ericallam
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

⚠️ No Changeset found

Latest commit: 36b08d6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Walkthrough

Expands idempotency documentation with new explanatory sections and examples. Adds "Why use idempotency keys?" (sequence diagram), an idempotencyKey option section, and a comprehensive "Understanding scopes" section (run, attempt, global) describing hashing semantics and typical use cases. Updates default behavior, backend-trigger behavior, failed-run handling, and environment/task scoping. Introduces key-resetting details and API (idempotencyKeys.reset), dashboard reset instructions, and payload-based idempotency guidance. Revises numerous examples to reflect scope-driven behavior, raw-string handling, key creation, and reset flows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description provided, which fails to meet the repository's description template requirements. Add a description following the template: include which issue it closes, confirm checklist items, describe testing steps, provide a changelog entry, and add any relevant screenshots.
Title check ❓ Inconclusive The title contains a typo ('expored' instead of 'exposed') and is somewhat unclear, but it does relate to idempotency key documentation improvements mentioned in the changeset. Fix the typo 'expored' to 'exposed' and clarify the title. Consider: 'chore(docs): Improve idempotency key documentation' or 'chore(docs): Add comprehensive idempotency key scope and reset guidance'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@vibe-kanban-cloud
Copy link

Review Complete

Your review story is ready!

View Story

Comment !reviewfast on this PR to re-generate the story.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/idempotency.mdx (1)

64-66: Tighten wording and article usage in examples.

Minor grammar tweaks improve readability.

✏️ Proposed text tweaks
-We automatically inject the run ID when generating the idempotency key when running inside a task by default.
+We automatically inject the run ID when generating the idempotency key inside a task by default.
-// You can also pass an array of strings to create a idempotency key
+// You can also pass an array of strings to create an idempotency key
-// You can also pass an array of strings to create a idempotency key
+// You can also pass an array of strings to create an idempotency key

Also applies to: 91-102

🤖 Fix all issues with AI agents
In `@docs/idempotency.mdx`:
- Line 247: Update the sentence that currently reads "When triggering tasks from
your backend code (outside of a task), there is no parent run context. In this
case, `\"run\"` and `\"attempt\"` scopes behave the same as `\"global\"` since
there's no run ID or attempt number to inject:" by removing the extra "of" and
using "outside a task" for tighter phrasing—i.e., change "outside of a task" to
"outside a task" while keeping the rest of the sentence and the quoted scopes
(`"run"`, `"attempt"`, `"global"`) unchanged.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c859be9 and 2b6d6d7.

⛔ Files ignored due to path filters (1)
  • docs/images/idempotency-key-dashboard.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • docs/idempotency.mdx
🧰 Additional context used
🧠 Learnings (18)
📓 Common learnings
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeyTTL` option to define a time window during which duplicate triggers return the original run

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use the `task()` function from `trigger.dev/sdk/v3` to define tasks with id and run properties

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Export tasks with unique IDs within the project to enable proper task discovery and execution

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2026-01-15T11:50:06.044Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-15T11:50:06.044Z
Learning: Applies to **/*.{ts,tsx} : Every Trigger.dev task must be exported and have a unique `id` property with no timeouts in the run function

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `tasks.batchTrigger()` to trigger multiple runs of a single task with different payloads

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.trigger()` to trigger a task from inside another task with specified payload

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTrigger()` to trigger multiple runs of a task from inside another task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Attach metadata to task runs using the metadata option when triggering, and access/update it inside runs using metadata functions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.trigger()` to trigger multiple different tasks at once from backend code

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTaskAndWait()` to batch trigger tasks by passing task instances and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTask()` to batch trigger tasks by passing task instances for static task sets

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerAndWait()` to batch trigger multiple different tasks and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTriggerAndWait()` to batch trigger tasks and wait for all results from a parent task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Limit task duration using the `maxDuration` property (in seconds)

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Configure task retry behavior using the `retry` property with options like maxAttempts, factor, and timeout values

Applied to files:

  • docs/idempotency.mdx
🪛 LanguageTool
docs/idempotency.mdx

[style] ~247-~247: This phrase is redundant. Consider using “outside”.
Context: ...riggering tasks from your backend code (outside of a task), there is no parent run context...

(OUTSIDE_OF)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
docs/idempotency.mdx (6)

6-7: Concise intro; please confirm the duplicate-return behavior wording.

Reads well. Please double-check that the SDK returns the original run handle on duplicate idempotency keys (vs. another artifact) so the phrasing matches current behavior.


10-37: Diagram/use cases are strong; verify retry semantics.

The narrative and diagram are clear. Please sanity‑check that the retry + idempotency behavior shown matches current SDK behavior.


124-218: Scopes section is clear; confirm hashing inputs and defaults.

Great structure and examples. Please verify the hashed inputs and scope defaults reflect current SDK behavior.


233-235: Verify the v4.3.1 breaking‑change note.

Please confirm the default‑scope change and version number match the current SDK release history.


311-335: Confirm failed/canceled key retention and reset signature.

Please verify that failed runs clear keys (while successful/canceled retain) and that idempotencyKeys.reset(taskIdentifier, idempotencyKey) matches the current SDK API.


384-404: Notes section is helpful; verify the scope‑hash bullets.

Nice summary and debugging guidance. Please confirm the hash behavior bullets reflect current SDK logic.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/idempotency.mdx (1)

91-102: Use “an” before “idempotency key.”

Minor grammar fix in both comment lines.

✏️ Proposed fix
-// You can also pass an array of strings to create a idempotency key
+// You can also pass an array of strings to create an idempotency key
@@
-// You can also pass an array of strings to create a idempotency key
+// You can also pass an array of strings to create an idempotency key
🤖 Fix all issues with AI agents
In `@docs/idempotency.mdx`:
- Around line 367-385: Update the documented signature for idempotencyKeys.reset
to match the SDK: change the second parameter type from `IdempotencyKey | string
| string[]` to `string`, rename the third parameter to `requestOptions` and type
it as `ZodFetchOptions` (not the `{ scope, parentRunId, attemptNumber }`
object), and document the return type as `Promise<{ id: string }>`; also remove
or update the parameter table rows for options.scope, options.parentRunId, and
options.attemptNumber so the table reflects the single `requestOptions?:
ZodFetchOptions` parameter.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c73be8 and c54de7e.

📒 Files selected for processing (1)
  • docs/idempotency.mdx
🧰 Additional context used
🧠 Learnings (20)
📓 Common learnings
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeyTTL` option to define a time window during which duplicate triggers return the original run

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `tasks.trigger()` with type-only imports to trigger tasks from backend code without importing the task implementation

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `metadata.parent` and `metadata.root` to update parent and root task metadata from child tasks

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use the `task()` function from `trigger.dev/sdk/v3` to define tasks with id and run properties

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Export tasks with unique IDs within the project to enable proper task discovery and execution

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2026-01-15T11:50:06.044Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-15T11:50:06.044Z
Learning: Applies to **/*.{ts,tsx} : Every Trigger.dev task must be exported and have a unique `id` property with no timeouts in the run function

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `tasks.batchTrigger()` to trigger multiple runs of a single task with different payloads

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.trigger()` to trigger a task from inside another task with specified payload

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTrigger()` to trigger multiple runs of a task from inside another task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Attach metadata to task runs using the metadata option when triggering, and access/update it inside runs using metadata functions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.trigger()` to trigger multiple different tasks at once from backend code

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTaskAndWait()` to batch trigger tasks by passing task instances and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTask()` to batch trigger tasks by passing task instances for static task sets

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerAndWait()` to batch trigger multiple different tasks and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTriggerAndWait()` to batch trigger tasks and wait for all results from a parent task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Configure task retry behavior using the `retry` property with options like maxAttempts, factor, and timeout values

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Limit task duration using the `maxDuration` property (in seconds)

Applied to files:

  • docs/idempotency.mdx
🪛 LanguageTool
docs/idempotency.mdx

[style] ~247-~247: This phrase is redundant. Consider using “outside”.
Context: ...riggering tasks from your backend code (outside of a task), there is no parent run context...

(OUTSIDE_OF)


[style] ~382-~382: To form a complete sentence, be sure to include a subject or ‘there’.
Context: ...ncyKey| The idempotency key to reset. Can be anIdempotencyKeyfromcreate()`,...

(MISSING_IT_THERE)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
docs/idempotency.mdx (2)

277-277: No changes needed. The 30-day default retention for idempotency keys is accurate and matches current Trigger.dev behavior.


311-314: The documentation accurately reflects the implementation. The idempotency key behavior is correct: shouldIdempotencyKeyBeCleared() clears keys only for statuses in FAILED_RUN_STATUSES (INTERRUPTED, COMPLETED_WITH_ERRORS, SYSTEM_FAILURE, CRASHED, TIMED_OUT) and EXPIRED, while CANCELED and COMPLETED_SUCCESSFULLY runs retain their keys as documented.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/idempotency.mdx (2)

91-93: Minor grammar fix: "a idempotency" → "an idempotency".

The word "idempotency" starts with a vowel sound.

✏️ Suggested fix
-// You can also pass an array of strings to create a idempotency key
+// You can also pass an array of strings to create an idempotency key

99-103: Misleading comment: example shows a single string, not an array.

The comment says "pass an array of strings" but the example passes a single string (myUser.id). Also has the same "a idempotency" grammar issue.

✏️ Suggested fix
 import { myTask } from "./trigger/myTasks";
 
-// You can also pass an array of strings to create a idempotency key
+// You can also pass a raw string directly as an idempotency key
 await myTask.trigger({ some: "data" }, { idempotencyKey: myUser.id });
🤖 Fix all issues with AI agents
In `@docs/idempotency.mdx`:
- Around line 400-456: The examples call idempotencyKeys.reset("task", "key", {
scope, parentRunId, attemptNumber }) but the documented signature shows
requestOptions?: ZodFetchOptions; fix by making the docs and examples consistent
with the SDK: either update the API signature to accept a proper ResetOptions
type (e.g., replace ZodFetchOptions with ResetOptions including
scope/parentRunId/attemptNumber) and describe that in the signature, or change
the examples to compute and pass the fully-qualified key/hash (using
idempotencyKeys.create or the SDK's key-derivation method) and pass only
ZodFetchOptions to reset; reference idempotencyKeys.reset and
idempotencyKeys.create in the examples and ensure the signature line for reset
reflects the chosen behavior.
- Around line 365-379: The docs show incorrect example calls to
idempotencyKeys.reset(...) passing `{ scope: "...", parentRunId: "...",
attemptNumber: ... }` which are not part of the third parameter type
ZodFetchOptions; remove scope/parentRunId/attemptNumber from all reset examples
(lines referenced: examples at 408, 437-440, 451-455) and make them follow the
correct pattern used at line 395 (e.g., await
idempotencyKeys.reset("child-task", key);), leaving only an optional
ZodFetchOptions object (retry, tracer, name, attributes, icon, onResponseBody,
prepareData) if needed; ensure any mention of scope remains with
idempotencyKeys.create(...) examples only.
♻️ Duplicate comments (1)
docs/idempotency.mdx (1)

247-247: Minor phrasing: drop "of".

Consider "outside a task" for a tighter read.

✏️ Suggested change
-When triggering tasks from your backend code (outside of a task), there is no parent run context. In this case, `run` and `attempt` scopes behave the same as `global` since there's no run ID or attempt number to inject:
+When triggering tasks from your backend code (outside a task), there is no parent run context. In this case, `run` and `attempt` scopes behave the same as `global` since there's no run ID or attempt number to inject:
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c54de7e and 36b08d6.

📒 Files selected for processing (1)
  • docs/idempotency.mdx
🧰 Additional context used
🧠 Learnings (20)
📓 Common learnings
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeyTTL` option to define a time window during which duplicate triggers return the original run
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Scope idempotency keys globally or to current run using the scope parameter

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeys.create()` to create idempotency keys for preventing duplicate task executions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `idempotencyKeyTTL` option to define a time window during which duplicate triggers return the original run

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `tasks.trigger()` with type-only imports to trigger tasks from backend code without importing the task implementation

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `metadata.parent` and `metadata.root` to update parent and root task metadata from child tasks

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use the `task()` function from `trigger.dev/sdk/v3` to define tasks with id and run properties

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Export tasks with unique IDs within the project to enable proper task discovery and execution

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2026-01-15T11:50:06.044Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-15T11:50:06.044Z
Learning: Applies to **/*.{ts,tsx} : Every Trigger.dev task must be exported and have a unique `id` property with no timeouts in the run function

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `tasks.batchTrigger()` to trigger multiple runs of a single task with different payloads

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.trigger()` to trigger a task from inside another task with specified payload

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTrigger()` to trigger multiple runs of a task from inside another task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Attach metadata to task runs using the metadata option when triggering, and access/update it inside runs using metadata functions

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.trigger()` to trigger multiple different tasks at once from backend code

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTaskAndWait()` to batch trigger tasks by passing task instances and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerByTask()` to batch trigger tasks by passing task instances for static task sets

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.triggerAndWait()` to batch trigger multiple different tasks and wait for results

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `yourTask.batchTriggerAndWait()` to batch trigger tasks and wait for all results from a parent task

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Configure task retry behavior using the `retry` property with options like maxAttempts, factor, and timeout values

Applied to files:

  • docs/idempotency.mdx
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Limit task duration using the `maxDuration` property (in seconds)

Applied to files:

  • docs/idempotency.mdx
🪛 LanguageTool
docs/idempotency.mdx

[style] ~247-~247: This phrase is redundant. Consider using “outside”.
Context: ...riggering tasks from your backend code (outside of a task), there is no parent run context...

(OUTSIDE_OF)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
docs/idempotency.mdx (2)

8-37: Well-structured introduction with helpful visualization.

The mermaid sequence diagram effectively illustrates the parent retry scenario, and the bulleted use cases provide practical context. This section reads clearly and helps users understand why they'd want idempotency keys.


124-217: Comprehensive scopes documentation.

The table format clearly presents the three scopes with their hashing behavior and use cases. The accompanying examples for each scope are practical and demonstrate the differences well.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +365 to +379
### API signature

```ts
idempotencyKeys.reset(
taskIdentifier: string,
idempotencyKey: string,
requestOptions?: ZodFetchOptions
): Promise<{ id: string }>
```

| Parameter | Description |
| --- | --- |
| `taskIdentifier` | The identifier of the task (e.g., `"my-task"`) |
| `idempotencyKey` | The idempotency key hash to reset (the 64-character hash string) |
| `requestOptions` | Optional fetch options for the API request |
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for idempotencyKeys.reset implementation
rg -n "reset.*idempotencyKey" --type=ts --type=tsx -A 5 | head -50

# Search for IdempotencyKeysAPI or similar class definitions
rg -n "class.*IdempotencyKeys|interface.*IdempotencyKeys" --type=ts --type=tsx -A 10 | head -50

Repository: triggerdotdev/trigger.dev

Length of output: 124


🏁 Script executed:

#!/bin/bash
# Find files that define idempotencyKeys
fd -e ts -e tsx | xargs rg -l "reset.*function|reset.*:.*\=>" | grep -E "(idempotency|reset)" | head -20

Repository: triggerdotdev/trigger.dev

Length of output: 190


🏁 Script executed:

#!/bin/bash
# Search more broadly for reset method in SDK files
find . -type f \( -name "*.ts" -o -name "*.tsx" \) | xargs grep -l "idempotencyKeys" | head -10

Repository: triggerdotdev/trigger.dev

Length of output: 613


🏁 Script executed:

#!/bin/bash
# Examine the idempotencyKeys server implementation
cat -n ./apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts | head -200

Repository: triggerdotdev/trigger.dev

Length of output: 5952


🏁 Script executed:

#!/bin/bash
# Check the API client that users interact with
cat -n ./packages/core/src/v3/apiClient/index.ts | head -150

Repository: triggerdotdev/trigger.dev

Length of output: 5123


🏁 Script executed:

#!/bin/bash
# Search for reset method in the API client
rg -n "reset" ./packages/core/src/v3/apiClient/index.ts -A 10 -B 2

Repository: triggerdotdev/trigger.dev

Length of output: 2308


🏁 Script executed:

#!/bin/bash
# Look at the ResetIdempotencyKeyResponse schema
fd -name "*.ts" -path "*/schemas/*" | xargs rg -l "ResetIdempotencyKeyResponse" | head -5

Repository: triggerdotdev/trigger.dev

Length of output: 392


🏁 Script executed:

#!/bin/bash
# Find the ZodFetchOptions definition
rg -n "type ZodFetchOptions|interface ZodFetchOptions" ./packages/core/src/v3/apiClient/ -A 15

Repository: triggerdotdev/trigger.dev

Length of output: 1240


🏁 Script executed:

#!/bin/bash
# Look at the ResetIdempotencyKeyResponse schema
cat -n ./packages/core/src/v3/schemas/api.ts | grep -A 3 -B 3 "ResetIdempotencyKeyResponse"

Repository: triggerdotdev/trigger.dev

Length of output: 474


🏁 Script executed:

#!/bin/bash
# Read the actual documentation file to see the examples
cat -n ./docs/idempotency.mdx | sed -n '365,480p'

Repository: triggerdotdev/trigger.dev

Length of output: 4583


🏁 Script executed:

#!/bin/bash
# Also search for how reset is actually being called in tests or server code
rg -n "resetIdempotencyKey" ./apps/webapp --type=ts -B 3 -A 3 | head -50

Repository: triggerdotdev/trigger.dev

Length of output: 6691


🏁 Script executed:

#!/bin/bash
# Search for the user-facing idempotencyKeys.reset implementation
fd -name "*.ts" -path "*sdk*" -o -path "*core*" | xargs grep -l "idempotencyKeys\|reset" | grep -v node_modules | head -20

Repository: triggerdotdev/trigger.dev

Length of output: 299


🏁 Script executed:

#!/bin/bash
# Look for the idempotencyKeys API wrapper in packages/sdk
find ./packages -name "*.ts" -type f | xargs grep -l "idempotencyKeys.*reset\|export.*idempotencyKeys" | head -10

Repository: triggerdotdev/trigger.dev

Length of output: 268


🏁 Script executed:

#!/bin/bash
# Check if there's a wrapper that transforms the reset call
find ./packages/sdk -name "*.ts" -type f 2>/dev/null | head -20

Repository: triggerdotdev/trigger.dev

Length of output: 51


🏁 Script executed:

#!/bin/bash
# Examine the trigger-sdk idempotencyKeys implementation
cat -n ./packages/trigger-sdk/src/v3/idempotencyKeys.ts | head -200

Repository: triggerdotdev/trigger.dev

Length of output: 359


🏁 Script executed:

#!/bin/bash
# Find the resetIdempotencyKey implementation in core
rg -n "export.*resetIdempotencyKey|function resetIdempotencyKey" ./packages/core/src/v3 -A 20

Repository: triggerdotdev/trigger.dev

Length of output: 980


🏁 Script executed:

#!/bin/bash
# Also check the exports from `@trigger.dev/core/v3`
cat -n ./packages/core/src/v3/index.ts | head -100

Repository: triggerdotdev/trigger.dev

Length of output: 3289


🏁 Script executed:

#!/bin/bash
# See the full idempotencyKeys.ts file to understand how scope is handled
cat -n ./packages/core/src/v3/idempotencyKeys.ts

Repository: triggerdotdev/trigger.dev

Length of output: 5639


Documentation examples pass incorrect parameters to idempotencyKeys.reset().

The API signature correctly shows requestOptions?: ZodFetchOptions as the third parameter, but the examples at lines 408, 437-440, and 451-455 incorrectly pass objects like { scope: "global" }, { scope: "run", parentRunId: "..." }, and { scope: "attempt", parentRunId: "...", attemptNumber: 1 }.

These objects do not match ZodFetchOptions (which contains retry, tracer, name, attributes, icon, onResponseBody, and prepareData). The scope parameter belongs to idempotencyKeys.create(), not reset() — scope is determined when the key is created, not when it's reset. Users following these examples will encounter API errors.

Update the examples to remove the scope, parentRunId, and attemptNumber parameters. Line 395's example (await idempotencyKeys.reset("child-task", key);) is correct and should be the pattern for all cases.

🤖 Prompt for AI Agents
In `@docs/idempotency.mdx` around lines 365 - 379, The docs show incorrect example
calls to idempotencyKeys.reset(...) passing `{ scope: "...", parentRunId: "...",
attemptNumber: ... }` which are not part of the third parameter type
ZodFetchOptions; remove scope/parentRunId/attemptNumber from all reset examples
(lines referenced: examples at 408, 437-440, 451-455) and make them follow the
correct pattern used at line 395 (e.g., await
idempotencyKeys.reset("child-task", key);), leaving only an optional
ZodFetchOptions object (retry, tracer, name, attributes, icon, onResponseBody,
prepareData) if needed; ensure any mention of scope remains with
idempotencyKeys.create(...) examples only.

Comment on lines +400 to +456
### Resetting global keys

Global keys are the simplest to reset since they don't require any run context:

```ts
import { idempotencyKeys } from "@trigger.dev/sdk";

// Reset an idempotency key for a specific task
await idempotencyKeys.reset("my-task", "my-idempotency-key");
// From anywhere - inside a task or from your backend code
await idempotencyKeys.reset("my-task", "my-key", { scope: "global" });
```

The `reset` function requires both parameters:
- `taskIdentifier`: The identifier of the task (e.g., `"my-task"`)
- `idempotencyKey`: The idempotency key to reset
### Resetting run-scoped keys

After resetting, any subsequent triggers with the same idempotency key will create new task runs instead of returning the existing ones.
Keys created with `"run"` scope (the default) include the parent run ID in the hash. When resetting from inside the same task, the run ID is automatically available:

```ts
import { idempotencyKeys, task } from "@trigger.dev/sdk";

export const parentTask = task({
id: "parent-task",
run: async (payload) => {
// Create a run-scoped key (default)
const key = await idempotencyKeys.create("my-key");
await childTask.trigger(payload, { idempotencyKey: key });

// Reset works automatically inside the task - run ID is available from context
await idempotencyKeys.reset("child-task", key);
},
});
```

When resetting from outside a task (e.g., from your backend code), you must provide the `parentRunId`:

```ts
import { idempotencyKeys } from "@trigger.dev/sdk";

// From your backend code - you need to know the parent run ID
await idempotencyKeys.reset("my-task", "my-key", {
scope: "run",
parentRunId: "run_abc123"
});
```

### Resetting attempt-scoped keys

Keys created with `"attempt"` scope include both the parent run ID and attempt number. When resetting from outside a task, you must provide both:

```ts
import { idempotencyKeys } from "@trigger.dev/sdk";

// From your backend code
await idempotencyKeys.reset("my-task", "my-key", {
scope: "attempt",
parentRunId: "run_abc123",
attemptNumber: 1
});
```
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Examples don't match the API signature above.

All examples in these sections pass { scope: "...", parentRunId: "...", attemptNumber: ... } as the third parameter, but the documented signature on line 371 specifies requestOptions?: ZodFetchOptions.

If the SDK truly only accepts ZodFetchOptions for request configuration (as noted in a previous review), these examples need to be rewritten. The scope/parentRunId/attemptNumber would need to be incorporated into the key hash before calling reset(), not passed as options.

Alternatively, if the SDK was updated to accept these options, the API signature section needs updating.

🤖 Prompt for AI Agents
In `@docs/idempotency.mdx` around lines 400 - 456, The examples call
idempotencyKeys.reset("task", "key", { scope, parentRunId, attemptNumber }) but
the documented signature shows requestOptions?: ZodFetchOptions; fix by making
the docs and examples consistent with the SDK: either update the API signature
to accept a proper ResetOptions type (e.g., replace ZodFetchOptions with
ResetOptions including scope/parentRunId/attemptNumber) and describe that in the
signature, or change the examples to compute and pass the fully-qualified
key/hash (using idempotencyKeys.create or the SDK's key-derivation method) and
pass only ZodFetchOptions to reset; reference idempotencyKeys.reset and
idempotencyKeys.create in the examples and ensure the signature line for reset
reflects the chosen behavior.

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.

3 participants