Skip to content

runs.subscribeToRun().withStreams() aborts active stream pipes as soon as the run status stream closes #5076

Open

Description

@shafiktanbir

What version of Trigger.dev are you using?

main (commit dd5eec1)

What Node.js version are you using?

20.18.0

What operating system are you using?

Linux

What build tool are you using?

tsup

Describe the Bug

When consuming runs.subscribeToRun(runId).withStreams(), the subscription aborts its shared abort signal as soon as the upstream run status stream finishes. If a task emits realtime stream chunks right before completing, the outer stream and its child stream subscriptions get aborted before buffered or in-flight stream events finish draining, so trailing stream chunks are dropped.

Reproduction Steps

  1. Trigger a task that writes several chunks to a realtime stream and immediately returns.
  2. Subscribe to the run using for await (const part of runs.subscribeToRun(runId).withStreams()).
  3. Observe that once the terminal run snapshot is read from the upstream run stream, the shared abort signal fires right away and cancels the outer stream reader and active realtime stream pipes before all queued stream chunks are yielded.

Expected Behavior

withStreams() should allow buffered run updates and active child stream subscriptions to finish draining naturally when the run completes, and only abort everything when the caller explicitly unsubscribes or cancels the outer stream.

Additional Context

Happy to open a PR with a test for this if you would like to vouch it!

Activity

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

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