I might have identified a bug related to

I might have identified a bug related to waitForEvent. Here's the relevant code:
export class SimpleWorkflow extends WorkflowEntrypoint<
Env,
SimpleWorkflowPayload
> {
async run(event: WorkflowEvent<SimpleWorkflowPayload>, step: WorkflowStep) {
console.log("Simple workflow started", event.payload);

await step.do("testing timeout", async () => {
console.log(`Initializing test: ${event.payload.name}`);
const eventResponse = await step.waitForEvent("waiting for event", {
type: "test",
timeout: 10000,
});
console.log("Test event received", eventResponse);
return { status: "initialized" };
});

console.log("workflow complete");
}
}
export class SimpleWorkflow extends WorkflowEntrypoint<
Env,
SimpleWorkflowPayload
> {
async run(event: WorkflowEvent<SimpleWorkflowPayload>, step: WorkflowStep) {
console.log("Simple workflow started", event.payload);

await step.do("testing timeout", async () => {
console.log(`Initializing test: ${event.payload.name}`);
const eventResponse = await step.waitForEvent("waiting for event", {
type: "test",
timeout: 10000,
});
console.log("Test event received", eventResponse);
return { status: "initialized" };
});

console.log("workflow complete");
}
}
Whenever waitForEvent fails due to a timeout exception, the step is retried as expected. However, once the step re-runs, I’m no longer able to send events—the workflow appears to be running, but the event cannot be received or triggered anymore.
7 Replies
Boragorn
BoragornOP2mo ago
Here's how it receives the events in my worker:
app.post("/event", async (c) => {
try {
const data = await c.req.json<TestEvent>();
const { testId, type, payload } = TestEventSchema.parse(data);

const instance = await c.env.SIMPLE_WORKFLOW.get(testId);

console.log("Sending event to instance", instance);

const eventResponse = await instance.sendEvent({
type,
payload,
});

console.log("Event sent to instance", eventResponse);

return c.json({
message: `Event ${type} sent to test instance ${testId}`,
});
} catch (error: any) {
console.log("Error sending event:", error);
return c.json({ error: error.message }, 500);
}
});
app.post("/event", async (c) => {
try {
const data = await c.req.json<TestEvent>();
const { testId, type, payload } = TestEventSchema.parse(data);

const instance = await c.env.SIMPLE_WORKFLOW.get(testId);

console.log("Sending event to instance", instance);

const eventResponse = await instance.sendEvent({
type,
payload,
});

console.log("Event sent to instance", eventResponse);

return c.json({
message: `Event ${type} sent to test instance ${testId}`,
});
} catch (error: any) {
console.log("Error sending event:", error);
return c.json({ error: error.message }, 500);
}
});
Diogo Ferreira
Diogo Ferreira2mo ago
Thanks for reporting. We will take a look at it!
Boragorn
BoragornOP5w ago
sure thing hey @Diogo Ferreira were you able to reproduce this bug?
Diogo Ferreira
Hi @Boragorn, sorry, we will take a look at this issue soon. rest assured, it is not forgotten
Boragorn
BoragornOP4w ago
thank you sir
Diogo Ferreira
Hi @Boragorn I new release was deployed containing a fix for this issue. Please give it a try!
Boragorn
BoragornOP3w ago
Will do Thank you so much @Diogo Ferreira !

Did you find this page helpful?