Skip to content

fix(sdk): add AbortSignal.any fallback in chat transport for Safari < 17.4 - #5100

Closed
cocvn157 wants to merge 1 commit into
triggerdotdev:mainfrom
cocvn157:fix/chat-transport-abortsignal-any-5098
Closed

cocvn157 wants to merge 1 commit into
triggerdotdev:mainfrom
cocvn157:fix/chat-transport-abortsignal-any-5098

Conversation

@cocvn157

@cocvn157 cocvn157 commented Nov 6, 2026

Copy link
Copy Markdown

Fixes #5098

TriggerChatTransport and AgentChat called AbortSignal.any() unconditionally when combining a caller-supplied AbortSignal with the internal stream controller signal, which throws TypeError: AbortSignal.any is not a function on Safari and iOS Safari versions prior to 17.4.

This adds an anyAbortSignal helper in ai-shared.ts that uses AbortSignal.any when available and falls back to listener forwarding on older runtimes, and updates chat.ts and chat-client.ts to use it.

@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3764667

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

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Hi @cocvn157, 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 Nov 6, 2026
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

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.

Devin Review found 5 potential issues.

Devin Review

Comment on lines +299 to +303
for (const s of signals) {
s.addEventListener("abort", () => controller.abort(s.reason), {
once: true,
signal: controller.signal,
});

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.

🟡 Finished streams retain abort listeners

On older Safari, anyAbortSignal keeps listeners after streams close without an abort. Reusing a caller signal accumulates retained callbacks and stream state across subscriptions.

Learn more

The fallback removes a source listener only when the composed controller aborts. An AgentChat subscription can close on a settled or empty response without aborting its controller. A browser reconnect also creates an outer composed signal whose controller remains un-aborted after an ordinary turn completes. A long-lived caller signal therefore retains the fallback's listener and captured controller for each such subscription.

Example: A page reuses one AbortController.signal for ten reconnects on Safari 16. Each completed reconnect leaves a listener on that signal, even though no stream remains open.

Recommended fix: Give the fallback an explicit disposal mechanism and call it on stream teardown, including the outer reconnect composition; alternatively ensure every composed controller aborts on every terminal path. Verify normal completion and settled-EOF cleanup as well as cancellation.

Devin Review


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

* to manual listener forwarding on runtimes without `AbortSignal.any` (such as
* Safari / iOS Safari < 17.4).
*/
export function anyAbortSignal(signals: AbortSignal[]): AbortSignal {

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.

🟡 Safari fix lacks a release note

The anyAbortSignal change fixes a customer-facing SDK failure, but this PR adds no changeset. The fix lacks the required patch release entry.

Learn more

The repository's AGENTS.md and CONTRIBUTING.md require a changeset for user-facing fixes in public packages. This change lets customers use chat transport on older Safari versions, so it meets that requirement.

Example: A customer upgrading the SDK to avoid AbortSignal.any is not a function cannot find this fix in the package's changeset-driven release notes.

Recommended fix: Add a patch changeset for @trigger.dev/sdk with a user-focused description of Safari chat compatibility.

Devin Review


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

});

try {
global.fetch = vi.fn().mockImplementation(async (url: string | URL) => {

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.

🟡 Browser regression test uses prohibited mocks

The new Safari test replaces global.fetch with vi.fn() twice. Repository testing rules prohibit mocks in new tests.

Learn more

The repository's AGENTS.md and test guidance prohibit new tests from using mocks, spies, stubs, or fakes. The added Safari test assigns a mocked global.fetch here and again later in the same test.

Example: The compatibility check serves synthetic responses from a vi.fn() implementation instead of exercising the real fetch boundary.

Recommended fix: Use an integration-style test with a real local HTTP endpoint and restore the original environment afterward, or move signal-composition assertions into a focused test that needs no fetch replacement.

Devin Review


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

Comment on lines +2984 to +2993
const callerAbort = new AbortController();
const stream = await transport.sendMessages({
trigger: "submit-message",
chatId: "chat-safari",
messageId: undefined,
messages: [createUserMessage("Hi from Safari 16")],
abortSignal: callerAbort.signal,
});
const chunks = await drainChunks(stream);
expect(chunks).toEqual([{ type: "text-delta", id: "p1", delta: "Safari fallback" }]);

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.

🔍 Active caller abort remains untested

The test never aborts callerAbort while a stream is open. Its pre-aborted case cannot detect broken forwarding of later abort events.

Devin Review


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

});

describe("Safari < 17.4 compatibility (no AbortSignal.any)", () => {
it("streams and propagates caller aborts when AbortSignal.any is undefined", async () => {

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.

🔍 Safari test lacks required regression comment

The new test has no // Catches: <bug> comment, as required by the repository's testing instructions.

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.

bug: Chat transport crashes on Safari < 17.4: AbortSignal.any is not a function

1 participant