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
6 changes: 6 additions & 0 deletions .changeset/lazy-terminal-run-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@workflow/world": patch
"@workflow/core": patch
---

Accept lazy completed and failed runs whose payload is represented by a remote reference.
7 changes: 6 additions & 1 deletion packages/core/src/runtime/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ export class Run<TResult> {
}

if (run.status === 'failed') {
throw new WorkflowRunFailedError(this.runId, run.error);
// Terminal run data can be returned lazily, so the error payload
// may not be materialized. Fall back to a generic message.
throw new WorkflowRunFailedError(
this.runId,
run.error ?? { message: 'Workflow run failed' }
);
}

throw new WorkflowRunNotCompletedError(this.runId, run.status);
Expand Down
27 changes: 27 additions & 0 deletions packages/world/src/runs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import { WorkflowRunSchema } from './runs.js';

describe('WorkflowRunSchema', () => {
it('accepts terminal runs without materialized payloads', () => {
const completedSchema = WorkflowRunSchema.options[2];
const failedSchema = WorkflowRunSchema.options[3];
const run = {
runId: 'wrun_1',
deploymentId: 'dpl_1',
workflowName: 'workflow_1',
createdAt: new Date(),
updatedAt: new Date(),
completedAt: new Date(),
};

expect(completedSchema.shape.output).toBeInstanceOf(z.ZodOptional);
expect(failedSchema.shape.error).toBeInstanceOf(z.ZodOptional);
expect(
WorkflowRunSchema.safeParse({ ...run, status: 'completed' }).success
).toBe(true);
expect(
WorkflowRunSchema.safeParse({ ...run, status: 'failed' }).success
).toBe(true);
});
});
4 changes: 2 additions & 2 deletions packages/world/src/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ export const WorkflowRunSchema = z.discriminatedUnion('status', [
// Completed state - output can be v1 or v2 format
WorkflowRunBaseSchema.extend({
status: z.literal('completed'),
output: SerializedDataSchema,
output: SerializedDataSchema.optional(),
error: z.undefined().optional(),
completedAt: z.coerce.date(),
}),
// Failed state
WorkflowRunBaseSchema.extend({
status: z.literal('failed'),
output: z.undefined().optional(),
error: StructuredErrorSchema,
error: StructuredErrorSchema.optional(),
completedAt: z.coerce.date(),
}),
]);
Expand Down