Skip to content

Commit ebd39aa

Browse files
Verify reconnect flow tolerates onError callback failures
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 065d933 commit ebd39aa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,39 @@ describe("TriggerChatTransport", function () {
14881488
expect(runStore.get("chat-reconnect-string-failure")).toBeUndefined();
14891489
});
14901490

1491+
it("ignores onError callback failures during reconnect error reporting", async function () {
1492+
const runStore = new InMemoryTriggerChatRunStore();
1493+
runStore.set({
1494+
chatId: "chat-reconnect-onerror-failure",
1495+
runId: "run_reconnect_onerror_failure",
1496+
publicAccessToken: "pk_reconnect_onerror_failure",
1497+
streamKey: "chat-stream",
1498+
lastEventId: "100-0",
1499+
isActive: true,
1500+
});
1501+
1502+
const transport = new TriggerChatTransport({
1503+
task: "chat-task",
1504+
stream: "chat-stream",
1505+
accessToken: "pk_trigger",
1506+
runStore,
1507+
onError: async function onError() {
1508+
throw new Error("onError failed");
1509+
},
1510+
});
1511+
1512+
(transport as any).fetchRunStream = async function fetchRunStream() {
1513+
throw new Error("reconnect root cause");
1514+
};
1515+
1516+
const stream = await transport.reconnectToStream({
1517+
chatId: "chat-reconnect-onerror-failure",
1518+
});
1519+
1520+
expect(stream).toBeNull();
1521+
expect(runStore.get("chat-reconnect-onerror-failure")).toBeUndefined();
1522+
});
1523+
14911524
it("cleans run store state when stream completes", async function () {
14921525
const trackedRunStore = new TrackedRunStore();
14931526

0 commit comments

Comments
 (0)