Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/void-ipc-acks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Fix a ~6-second delay between a task finishing and its run completing (and a ~31-second delay when cancelling a run) in projects that use zod 4.4 or newer. Run cost and billed usage was not impacted by this issue.
4 changes: 3 additions & 1 deletion packages/core/src/v3/zodIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ const Packet = discriminatedUnion("type", [
}),
z.object({
type: z.literal("ACK"),
message: z.any(),
// Optional: a void callback acks with `message: undefined`, and `process.send`
// drops undefined keys when serializing, so the key is absent on arrival.
message: z.any().optional(),
id: z.number(),
}),
z.object({
Expand Down
14 changes: 14 additions & 0 deletions packages/core/test/fixtures/zodIpcCatalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from "zod/v4";

export const ParentToChild = {
FLUSH: {
message: z.object({ timeoutInMs: z.number() }),
callback: z.void(),
},
PING: {
message: z.object({ value: z.string() }),
callback: z.object({ echoed: z.string() }),
},
};

export const ChildToParent = {};
13 changes: 13 additions & 0 deletions packages/core/test/fixtures/zodIpcChild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ZodIpcConnection } from "../../src/v3/zodIpc.js";
import { ChildToParent, ParentToChild } from "./zodIpcCatalog.js";

// Forked by zodIpc.test.ts: answers the parent's messages over the real IPC channel.
new ZodIpcConnection({
listenSchema: ParentToChild,
emitSchema: ChildToParent,
process,
handlers: {
FLUSH: async () => {},
PING: async ({ value }) => ({ echoed: value }),
},
});
44 changes: 44 additions & 0 deletions packages/core/test/zodIpc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { fork, type ChildProcess } from "node:child_process";
import { fileURLToPath } from "node:url";
import { afterEach, describe, expect, it } from "vitest";
import { ZodIpcConnection } from "../src/v3/zodIpc.js";
Comment thread
NERLOE marked this conversation as resolved.
import { ChildToParent, ParentToChild } from "./fixtures/zodIpcCatalog.js";

const childPath = fileURLToPath(new URL("./fixtures/zodIpcChild.ts", import.meta.url));

let child: ChildProcess | undefined;

afterEach(() => {
child?.kill();
child = undefined;
});

// Node's default IPC serialization is JSON, so an ack with `message: undefined`
// arrives without the `message` key, exactly as it does between a worker and its task run process.
function forkChild() {
child = fork(childPath, { execArgv: ["--import", "tsx"], stdio: "inherit" });

return new ZodIpcConnection({
listenSchema: ChildToParent,
emitSchema: ParentToChild,
process: child,
});
}

describe("ZodIpcConnection", () => {
it("resolves sendWithAck for a void callback", async () => {
const connection = forkChild();

await expect(connection.sendWithAck("FLUSH", { timeoutInMs: 1000 }, 2000)).resolves.toBe(
undefined
);
});

it("resolves sendWithAck with the callback payload", async () => {
const connection = forkChild();

await expect(connection.sendWithAck("PING", { value: "hello" }, 2000)).resolves.toEqual({
echoed: "hello",
});
});
});
Loading