Skip to content
Draft
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
17 changes: 16 additions & 1 deletion rivetkit-typescript/packages/workflow-engine/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,27 @@ export class WorkflowContextImpl implements WorkflowContextInterface {
return stepData.output as T;
}

// Check if we should retry
// Check if we should retry.
//
// Important: steps that *return undefined* (i.e. "void" steps) are valid and
// must still be treated as completed on restart. Since JSON omits properties
// with value `undefined`, we cannot rely on `stepData.output !== undefined`
// to determine completion. Prefer metadata.status for completion tracking.
const metadata = await loadMetadata(
this.storage,
this.driver,
existing.id,
);

if (metadata.status === "completed") {
this.log("debug", {
msg: "replaying completed step from metadata",
step: config.name,
key,
});
return stepData.output as T;
}

const maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;

if (metadata.attempts >= maxRetries) {
Expand Down
34 changes: 34 additions & 0 deletions rivetkit-typescript/packages/workflow-engine/tests/steps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ for (const mode of modes) {
expect(callCount).toBe(1);
});

it("should treat void step outputs as completed on restart", async () => {
let callCount = 0;

const workflow = async (ctx: WorkflowContextInterface) => {
await ctx.step("void-step", async () => {
callCount += 1;
// return undefined (void)
});
return "done";
};

const first = await runWorkflow(
"wf-void",
workflow,
undefined,
driver,
{ mode },
).result;
expect(first.state).toBe("completed");
expect(first.output).toBe("done");
expect(callCount).toBe(1);

const second = await runWorkflow(
"wf-void",
workflow,
undefined,
driver,
{ mode },
).result;
expect(second.state).toBe("completed");
expect(second.output).toBe("done");
expect(callCount).toBe(1);
});

it("should execute multiple steps in sequence", async () => {
const workflow = async (ctx: WorkflowContextInterface) => {
const a = await ctx.step("step-a", async () => 1);
Expand Down
Loading