Cleanup inactive reconnect state entries on access

Co-authored-by: Eric Allam <eric@trigger.dev>
This commit is contained in:
Cursor Agent
2026-02-15 00:34:25 +00:00
parent 227290b3da
commit 5efba1394d
2 changed files with 33 additions and 1 deletions
+27
View File
@@ -476,6 +476,33 @@ describe("TriggerChatTransport", function () {
expect(stream).toBeNull();
});
it("removes inactive run entries during reconnect attempts", async function () {
const runStore = new TrackedRunStore();
runStore.set({
chatId: "chat-inactive",
runId: "run_inactive",
publicAccessToken: "pk_inactive",
streamKey: "chat-stream",
lastEventId: "10-0",
isActive: false,
});
const transport = new TriggerChatTransport({
task: "chat-task",
stream: "chat-stream",
accessToken: "pk_trigger",
runStore,
});
const stream = await transport.reconnectToStream({
chatId: "chat-inactive",
});
expect(stream).toBeNull();
expect(runStore.deleteCalls).toContain("chat-inactive");
expect(runStore.get("chat-inactive")).toBeUndefined();
});
it("supports custom payload mapping and trigger options resolver", async function () {
let receivedTriggerBody: Record<string, unknown> | undefined;
let receivedResolverChatId: string | undefined;
+6 -1
View File
@@ -195,7 +195,12 @@ export class TriggerChatTransport<
): Promise<ReadableStream<UIMessageChunk> | null> {
const runState = await this.runStore.get(options.chatId);
if (!runState || !runState.isActive) {
if (!runState) {
return null;
}
if (!runState.isActive) {
await this.runStore.delete(options.chatId);
return null;
}