Skip to content

Commit c1163eb

Browse files
[world-local] Reject run_failed on non-existent run (#1894)
1 parent 2f52d14 commit c1163eb

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/world-local": patch
3+
---
4+
5+
Throw `WorkflowRunNotFoundError` when `run_failed` is recorded against a run that doesn't exist, matching the behaviour of `world-postgres` and `world-vercel`.

packages/world-local/src/storage.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ describe('Storage', () => {
276276
expect(updated.error?.message).toBe('Something went wrong');
277277
expect(updated.completedAt).toBeInstanceOf(Date);
278278
});
279+
280+
it('should reject run_failed on non-existent run', async () => {
281+
await expect(
282+
updateRun(storage, 'wrun_nonexistent', 'run_failed', {
283+
error: 'Something went wrong',
284+
})
285+
).rejects.toMatchObject({ name: 'WorkflowRunNotFoundError' });
286+
});
279287
});
280288

281289
describe('list', () => {

packages/world-local/src/storage/events-storage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
RunExpiredError,
77
RunNotSupportedError,
88
TooEarlyError,
9+
WorkflowRunNotFoundError,
910
WorkflowWorldError,
1011
} from '@workflow/errors';
1112
import type {
@@ -226,6 +227,14 @@ export function createEventsStorage(
226227
}
227228
}
228229

230+
// run_failed on a non-existent run is rejected to match the
231+
// postgres and vercel worlds, which both surface this as a
232+
// WorkflowRunNotFoundError rather than silently persisting an
233+
// event for a run that was never created.
234+
if (data.eventType === 'run_failed' && !currentRun) {
235+
throw new WorkflowRunNotFoundError(effectiveRunId);
236+
}
237+
229238
// ============================================================
230239
// VERSION COMPATIBILITY: Check run spec version
231240
// ============================================================

0 commit comments

Comments
 (0)