Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix/sdk stream root fallback #2874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bharathkumar39293 wants to merge 4 commits into triggerdotdev:main
base: main
Choose a base branch
Loading
from bharathkumar39293:fix/sdk-stream-root-fallback

Conversation

@bharathkumar39293
Copy link

@bharathkumar39293 bharathkumar39293 commented Jan 13, 2026
edited
Loading

This PR fixes the SDK stream helpers (streams.pipe, streams.append, streams.writer) to correctly handle semantic targets root and parent in root tasks. Previously, the getRunIdForOptions function in the SDK lacked fallback logic when the current task was a root task, causing errors. This change aligns SDK behavior with Core semantics, ensuring that the current run ID is used as a fallback.

Testing

Automated:

Added regression tests in packages/trigger-sdk/src/v3/streams.test.ts

Verified that:

streams.pipe(..., { target: "root" }) does not throw in a root task

streams.pipe(..., { target: "parent" }) does not throw in a root task

Tests pass locally

Manual:

Built the SDK successfully using pnpm run build --filter @trigger.dev/sdk

Changelog:
Fixed SDK stream helpers to fallback to current run ID when target: "root" or target: "parent" is used in a root task, aligning SDK behavior with Core semantics.

Changeset included:

Added a patch changeset for @trigger.dev/sdk

Issue Link:
Closes #2852

Copy link

changeset-bot bot commented Jan 13, 2026
edited
Loading

🦋 Changeset detected

Latest commit: 50737c2

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

This PR includes changesets to release 27 packages
Name Type
@trigger.dev/sdk Patch
@trigger.dev/python 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/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

Copy link
Contributor

coderabbitai bot commented Jan 13, 2026
edited
Loading

Walkthrough

A changeset was added for a patch release. In the SDK, getRunIdForOptions now falls back to the current run id when resolving "parent" or "root" semantic targets if parentTaskRunId or rootTaskRunId are undefined. A new unit test file was added to verify that streams.pipe uses the current run id ("run_123") for "root" and "parent" targets in a root task. The apps/webapp throttle utility was rewritten to fire immediately on first call and ensure a trailing invocation; no public API signatures were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes one out-of-scope change: modifications to apps/webapp/app/utils/throttle.ts that reimplements throttling behavior unrelated to the SDK stream root fallback fix. Remove the throttle.ts changes as they are unrelated to the getRunIdForOptions fix and stream semantic targets issue. Consider moving throttle changes to a separate PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Fix/sdk stream root fallback' directly addresses the main change: fixing SDK stream helpers to handle root task fallback logic for semantic targets.
Description check ✅ Passed The PR description comprehensively covers the issue, testing approach, and changes. However, it does not follow the template structure with checkbox items or explicit sections like 'Testing', 'Changelog', and 'Screenshots'.
Linked Issues check ✅ Passed The PR fully addresses issue #2852 by implementing fallback logic in SDK's getRunIdForOptions to match Core behavior, adding regression tests, and preventing streams.pipe/append/writer from throwing when used with semantic targets in root tasks.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

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: 0

🧹 Nitpick comments (2)
packages/trigger-sdk/src/v3/streams.test.ts (2)

31-46: Minor: Unused waitUntilComplete variable.

The destructured waitUntilComplete is unused in both test cases. Consider either using it to verify the full flow or removing the destructuring.

♻️ Suggested fix
- const { waitUntilComplete } = streams.pipe("test-key", mockStream, {
+ streams.pipe("test-key", mockStream, {
 target: "root",
 });

48-63: Consider adding edge case coverage.

The tests verify the happy path well. Consider adding a test for the target: "self" case to ensure consistency, and potentially a test that verifies behavior when taskContext.ctx is undefined (outside task context).

Would you like me to generate additional test cases for these edge scenarios?

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a94908 and c0dae38.

📒 Files selected for processing (3)
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
🧰 Additional context used
📓 Path-based instructions (10)
packages/trigger-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

Every Trigger.dev task must be exported; use task() function with unique id and run async function

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
**/*.{test,spec}.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use vitest for all tests in the Trigger.dev repository

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
**/*.{js,ts,jsx,tsx,json,md,css,scss}

📄 CodeRabbit inference engine (AGENTS.md)

Format code using Prettier

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.test.{ts,tsx,js,jsx}: Test files should live beside the files under test and use descriptive describe and it blocks
Avoid mocks or stubs in tests; use helpers from @internal/testcontainers when Redis or Postgres are needed
Use vitest for unit tests

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

Use vitest exclusively for testing and never mock anything; use testcontainers instead

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.test.{ts,tsx}: Place test files next to source files with .test.ts naming convention (e.g., MyService.ts → MyService.test.ts)
Use testcontainers helpers (redisTest, postgresTest, containerTest from @internal/testcontainers) for Redis/PostgreSQL testing instead of mocks

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: Import from @trigger.dev/core using subpaths only; never import from root of @trigger.dev/core
Always import task definitions from @trigger.dev/sdk, never from @trigger.dev/sdk/v3 or deprecated client.defineJob pattern

Files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
🧠 Learnings (22)
📓 Common learnings
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `.withStreams()` to subscribe to realtime streams from task metadata in addition to run changes
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `.withStreams()` to subscribe to realtime streams from task metadata in addition to run changes

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:26:37.432Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025年11月27日T16:26:37.432Z
Learning: Applies to packages/trigger-sdk/**/*.{ts,tsx} : In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2025年11月27日T16:26:37.432Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025年11月27日T16:26:37.432Z
Learning: Applies to **/*.{test,spec}.{ts,tsx} : Use vitest for all tests in the Trigger.dev repository

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Subscribe to run updates using `runs.subscribeToRun()` for realtime monitoring of task execution

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `trigger.dev/sdk/v3` for all imports in Trigger.dev tasks

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • .changeset/consistent-stream-targets.md
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Generate example payloads for tasks when possible

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to **/*.{ts,tsx} : Every Trigger.dev task must be exported; use task() function with unique id and run async function

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use metadata methods (set, del, replace, append, remove, increment, decrement, stream, flush) to update metadata during task execution

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to **/*.test.{ts,tsx,js} : Use vitest exclusively for testing and never mock anything; use testcontainers instead

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2025年11月27日T16:27:48.109Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: AGENTS.md:0-0
Timestamp: 2025年11月27日T16:27:48.109Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Avoid mocks or stubs in tests; use helpers from `internal/testcontainers` when Redis or Postgres are needed

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2025年11月27日T16:27:48.109Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: AGENTS.md:0-0
Timestamp: 2025年11月27日T16:27:48.109Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Use vitest for unit tests

Applied to files:

  • packages/trigger-sdk/src/v3/streams.test.ts
📚 Learning: 2026年01月12日T11:01:34.778Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.778Z
Learning: Add a changeset when modifying public packages in packages/* or integrations/* directories

Applied to files:

  • .changeset/consistent-stream-targets.md
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to rules/**/*.md : SDK documentation rules are versioned in rules/ directory and distributed to users; create new version directories with only changed files when adding features; update rules/manifest.json to point unchanged files to previous versions

Applied to files:

  • .changeset/consistent-stream-targets.md
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to **/*.{ts,tsx,js} : Always import task definitions from trigger.dev/sdk, never from trigger.dev/sdk/v3 or deprecated client.defineJob pattern

Applied to files:

  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `schemaTask()` from `trigger.dev/sdk/v3` with Zod schema for payload validation

Applied to files:

  • .changeset/consistent-stream-targets.md
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
🧬 Code graph analysis (1)
packages/trigger-sdk/src/v3/streams.test.ts (2)
packages/trigger-sdk/src/v3/streams.ts (1)
  • streams (657-663)
packages/core/src/v3/realtime-streams-api.ts (1)
  • realtimeStreams (5-5)
🔇 Additional comments (3)
.changeset/consistent-stream-targets.md (1)

1-5: LGTM!

The changeset is correctly formatted with an appropriate patch level for this bug fix. The description clearly explains the alignment between SDK and Core for semantic target handling.

packages/trigger-sdk/src/v3/streams.ts (1)

665-683: LGTM! Clean fix for root task fallback behavior.

The fallback logic correctly handles the edge case where a root task uses target: "root" or target: "parent". Since root tasks have no parent or root ancestors, falling back to the current run ID (taskContext.ctx?.run?.id) is the correct semantic behavior, making these targets behave equivalently to target: "self" in that context.

packages/trigger-sdk/src/v3/streams.test.ts (1)

5-24: Mocking is appropriate here for SDK internal unit testing.

While coding guidelines generally discourage mocks, this is a valid use case for mocking since you're testing SDK-internal logic that requires simulating the task execution context. Testcontainers wouldn't help here as there's no external service dependency.

Copy link
Author

This change aligns SDK fallback behavior with the existing Core implementation.
Longer-term, semantic target resolution could be centralized to avoid duplication, but this PR intentionally keeps scope minimal.

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: 0

🧹 Nitpick comments (1)
apps/webapp/app/utils/throttle.ts (1)

1-28: Well-implemented leading+trailing throttle pattern.

The recursive wrapped call on line 22 elegantly handles the trailing invocation while maintaining the leading-edge behavior. This ensures no calls are lost during rapid invocations.

Consider adding a cancel method if callers need to abort pending trailing calls (e.g., on component unmount or cleanup):

♻️ Optional: Add cancel capability
 export function throttle(
 func: (...args: any[]) => void,
 durationMs: number
-): (...args: any[]) => void {
+): ((...args: any[]) => void) & { cancel: () => void } {
 let timeoutId: NodeJS.Timeout | null = null;
 let nextArgs: any[] | null = null;
 const wrapped = (...args: any[]) => {
 if (timeoutId) {
 nextArgs = args;
 return;
 }
 func(...args);
 timeoutId = setTimeout(() => {
 timeoutId = null;
 if (nextArgs) {
 const argsToUse = nextArgs;
 nextArgs = null;
 wrapped(...argsToUse);
 }
 }, durationMs);
 };
+ wrapped.cancel = () => {
+ if (timeoutId) {
+ clearTimeout(timeoutId);
+ timeoutId = null;
+ }
+ nextArgs = null;
+ };
+
 return wrapped;
 }
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0dae38 and e229d61.

📒 Files selected for processing (4)
  • .changeset/consistent-stream-targets.md
  • apps/webapp/app/utils/throttle.ts
  • packages/trigger-sdk/src/v3/streams.test.ts
  • packages/trigger-sdk/src/v3/streams.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/consistent-stream-targets.md
  • packages/trigger-sdk/src/v3/streams.test.ts
🧰 Additional context used
📓 Path-based instructions (9)
packages/trigger-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

In the Trigger.dev SDK (packages/trigger-sdk), prefer isomorphic code like fetch and ReadableStream instead of Node.js-specific code

Files:

  • packages/trigger-sdk/src/v3/streams.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

Every Trigger.dev task must be exported; use task() function with unique id and run async function

Files:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Files:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
**/*.{js,ts,jsx,tsx,json,md,css,scss}

📄 CodeRabbit inference engine (AGENTS.md)

Format code using Prettier

Files:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries

Files:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js}: Import from @trigger.dev/core using subpaths only; never import from root of @trigger.dev/core
Always import task definitions from @trigger.dev/sdk, never from @trigger.dev/sdk/v3 or deprecated client.defineJob pattern

Files:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use zod for validation in packages/core and apps/webapp

Files:

  • apps/webapp/app/utils/throttle.ts
apps/webapp/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Access all environment variables through the env export of env.server.ts instead of directly accessing process.env in the Trigger.dev webapp

In webapp development, access environment variables via env export from apps/webapp/app/env.server.ts; never use process.env directly

Files:

  • apps/webapp/app/utils/throttle.ts
apps/webapp/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

apps/webapp/**/*.{ts,tsx}: When importing from @trigger.dev/core in the webapp, use subpath exports from the package.json instead of importing from the root path
Follow the Remix 2.1.0 and Express server conventions when updating the main trigger.dev webapp

Files:

  • apps/webapp/app/utils/throttle.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `.withStreams()` to subscribe to realtime streams from task metadata in addition to run changes
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Subscribe to run updates using `runs.subscribeToRun()` for realtime monitoring of task execution
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `.withStreams()` to subscribe to realtime streams from task metadata in addition to run changes

Applied to files:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Subscribe to run updates using `runs.subscribeToRun()` for realtime monitoring of task execution

Applied to files:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to **/*.{ts,tsx} : Every Trigger.dev task must be exported; use task() function with unique id and run async function

Applied to files:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2026年01月12日T11:01:34.777Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026年01月12日T11:01:34.777Z
Learning: Applies to **/*.{ts,tsx,js} : Always import task definitions from trigger.dev/sdk, never from trigger.dev/sdk/v3 or deprecated client.defineJob pattern

Applied to files:

  • packages/trigger-sdk/src/v3/streams.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16: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:

  • packages/trigger-sdk/src/v3/streams.ts
  • apps/webapp/app/utils/throttle.ts
📚 Learning: 2025年11月27日T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025年11月27日T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Limit task duration using the `maxDuration` property (in seconds)

Applied to files:

  • apps/webapp/app/utils/throttle.ts
🔇 Additional comments (1)
packages/trigger-sdk/src/v3/streams.ts (1)

665-683: LGTM! Fallback logic correctly aligns SDK with Core behavior.

The fallback to taskContext.ctx?.run?.id when parentTaskRunId or rootTaskRunId is undefined ensures that semantic targets "root" and "parent" resolve gracefully when called from a root task. This matches the documented behavior where target: "root" should behave like "self" when the task is already the root.

Copy link
Member

@bharathkumar39293 This looks great but can you remove the change to the throttle function in the webapp or explain the reason for the change?

Copy link
Author

Hi @ericallam ,

I’ve removed the unrelated throttle changes from this PR so it now focuses purely on the SDK stream root/parent fallback fix. The throttle/webapp fix for dashboard span refresh is still present in PR #2875, where it belongs.
This should make the review easier and keep the changes scoped correctly.
Thanks!

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

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bug: getRunIdForOptions function is duplicated, contains inconsistent fallback behavior

AltStyle によって変換されたページ (->オリジナル) /