Skip to content

Commit 2b6723e

Browse files
Retry inactive reconnect cleanup after string delete failures
Co-authored-by: Eric Allam <eric@trigger.dev>
1 parent 3732bd6 commit 2b6723e

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

packages/ai/src/chatTransport.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,52 @@ describe("TriggerChatTransport", function () {
706706
expect(stream).toBeNull();
707707
});
708708

709+
it("retries inactive reconnect string cleanup on subsequent reconnect attempts", async function () {
710+
const errors: TriggerChatTransportError[] = [];
711+
const runStore = new FailingCleanupDeleteValueRunStore("cleanup delete string failure");
712+
runStore.set({
713+
chatId: "chat-inactive-delete-string-retry",
714+
runId: "run_inactive_delete_string_retry",
715+
publicAccessToken: "pk_inactive_delete_string_retry",
716+
streamKey: "chat-stream",
717+
lastEventId: "10-0",
718+
isActive: false,
719+
});
720+
721+
const transport = new TriggerChatTransport({
722+
task: "chat-task",
723+
stream: "chat-stream",
724+
accessToken: "pk_trigger",
725+
runStore,
726+
onError: function onError(error) {
727+
errors.push(error);
728+
},
729+
});
730+
731+
const firstReconnect = await transport.reconnectToStream({
732+
chatId: "chat-inactive-delete-string-retry",
733+
});
734+
735+
expect(firstReconnect).toBeNull();
736+
expect(errors).toHaveLength(1);
737+
expect(errors[0]).toMatchObject({
738+
phase: "reconnect",
739+
chatId: "chat-inactive-delete-string-retry",
740+
runId: "run_inactive_delete_string_retry",
741+
});
742+
expect(runStore.get("chat-inactive-delete-string-retry")).toMatchObject({
743+
isActive: false,
744+
});
745+
746+
const secondReconnect = await transport.reconnectToStream({
747+
chatId: "chat-inactive-delete-string-retry",
748+
});
749+
750+
expect(secondReconnect).toBeNull();
751+
expect(errors).toHaveLength(1);
752+
expect(runStore.get("chat-inactive-delete-string-retry")).toBeUndefined();
753+
});
754+
709755
it("normalizes non-Error inactive reconnect cleanup delete failures through onError", async function () {
710756
const errors: TriggerChatTransportError[] = [];
711757
const runStore = new FailingCleanupDeleteValueRunStore("cleanup delete string failure");
@@ -3624,11 +3670,13 @@ class FailingCleanupDeleteValueRunStore extends InMemoryTriggerChatRunStore {
36243670
super();
36253671
}
36263672

3627-
public delete(_chatId: string): void {
3673+
public delete(chatId: string): void {
36283674
this.deleteCalls += 1;
36293675
if (this.deleteCalls === 1) {
36303676
throw this.thrownValue;
36313677
}
3678+
3679+
super.delete(chatId);
36323680
}
36333681
}
36343682

0 commit comments

Comments
 (0)