-
Notifications
You must be signed in to change notification settings - Fork 287
Backport #2055 + #2415 to stable: [world-vercel] v4 event wire format + lazy metadata-only listings #2414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Backport #2055 + #2415 to stable: [world-vercel] v4 event wire format + lazy metadata-only listings #2414
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18ee97c
[world-vercel] Switch event endpoints to v4 wire format (#2055)
github-actions[bot] 33cbef8
[world-vercel] Carry stable-line structured errors on the v4 wire
VaguelySerious e622a6b
[world-vercel] Keep hook_created isWebhook on the v4 wire
VaguelySerious 2904cad
[world-vercel] Send remoteRefBehavior=lazy on v4 metadata-only listings
VaguelySerious 3783179
Apply suggestion from @VaguelySerious
VaguelySerious 6b696e9
[world-vercel] Update structured-error decode test for remoteRefBehavior
VaguelySerious a276de0
fix(world-vercel): cancel v4 event frame stream on early exit
smaeda-ks cdf8843
Merge branch 'stable' into backport/pr-2055-to-stable
VaguelySerious 10dd0d4
Revert "fix(world-vercel): cancel v4 event frame stream on early exit"
VaguelySerious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@workflow/world-vercel": minor | ||
| "@workflow/world": patch | ||
| --- | ||
|
|
||
| New internal API format: separately encode event metadata from user payloads. Eliminates the need for calling separate endpoints for ref resolution, which improves performance especially on longer runs. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@workflow/world-vercel": patch | ||
| --- | ||
|
|
||
| Skip transferring event payload bytes when listing events with `resolveData: 'none'` using the v4 API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| import { | ||
| EntityConflictError, | ||
| RunExpiredError, | ||
| ThrottleError, | ||
| TooEarlyError, | ||
| WorkflowWorldError, | ||
| } from '@workflow/errors'; | ||
| import { encode } from 'cbor-x'; | ||
| import { MockAgent } from 'undici'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| createWorkflowRunEventV4, | ||
| getWorkflowRunEventsV4, | ||
| throwForErrorResponse, | ||
| } from './events-v4.js'; | ||
| import { encodeFrame, V4_FRAME_CONTENT_TYPE } from './frames.js'; | ||
|
|
||
| /** | ||
| * The v4 client must preserve the typed-error contract of the v3 | ||
| * `makeRequest` path — the workflow runtime branches on these types | ||
| * (`RunExpiredError.is`, `TooEarlyError.is`, the 404 → HookNotFoundError | ||
| * translation in events.ts) for core retry/terminal-state control flow. | ||
| */ | ||
| describe('throwForErrorResponse', () => { | ||
| const call = ( | ||
| status: number, | ||
| body = '{"message":"boom"}', | ||
| headers: Record<string, string> = {} | ||
| ) => throwForErrorResponse(status, headers, body, 'createEvent', 'http://x'); | ||
|
|
||
| it('maps 409 to EntityConflictError', () => { | ||
| expect(() => call(409)).toThrowError(EntityConflictError); | ||
| }); | ||
|
|
||
| it('maps 410 to RunExpiredError (terminal run — runtime must not retry)', () => { | ||
| expect(() => call(410)).toThrowError(RunExpiredError); | ||
| }); | ||
|
|
||
| it('maps 425 to TooEarlyError with retryAfter from the header', () => { | ||
| try { | ||
| call(425, '{"message":"too early"}', { 'retry-after': '7' }); | ||
| expect.unreachable(); | ||
| } catch (err) { | ||
| expect(TooEarlyError.is(err)).toBe(true); | ||
| expect((err as TooEarlyError).retryAfter).toBe(7); | ||
| } | ||
| }); | ||
|
|
||
| it('maps 429 to ThrottleError with retryAfter from the header', () => { | ||
| try { | ||
| call(429, '{"message":"slow down"}', { 'retry-after': '30' }); | ||
| expect.unreachable(); | ||
| } catch (err) { | ||
| expect(ThrottleError.is(err)).toBe(true); | ||
| expect((err as ThrottleError).retryAfter).toBe(30); | ||
| } | ||
| }); | ||
|
|
||
| it('maps 404 to WorkflowWorldError with status (hook → HookNotFoundError translation keys off this)', () => { | ||
| try { | ||
| call(404, '{"message":"hook not found","code":"not_found"}'); | ||
| expect.unreachable(); | ||
| } catch (err) { | ||
| expect(WorkflowWorldError.is(err)).toBe(true); | ||
| expect((err as WorkflowWorldError).status).toBe(404); | ||
| expect((err as WorkflowWorldError).code).toBe('not_found'); | ||
| expect((err as WorkflowWorldError).message).toBe('hook not found'); | ||
| } | ||
| }); | ||
|
|
||
| it('maps 5xx to WorkflowWorldError with status (runtime treats as retryable)', () => { | ||
| try { | ||
| call(503); | ||
| expect.unreachable(); | ||
| } catch (err) { | ||
| expect(WorkflowWorldError.is(err)).toBe(true); | ||
| expect((err as WorkflowWorldError).status).toBe(503); | ||
| } | ||
| }); | ||
|
|
||
| it('keeps a useful message when the body is not JSON', () => { | ||
| expect(() => call(500, 'plain text oops')).toThrowError( | ||
| /createEvent failed: HTTP 500 plain text oops/ | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * Full HTTP round-trip through getWorkflowRunEventsV4 — exercises the | ||
| * undici response-body → decodeFrames path that previously crashed in | ||
| * Next.js webpack bundles (node:stream Readable.toWeb), and verifies | ||
| * `config.dispatcher` is honored (it was silently ignored before). | ||
| */ | ||
| describe('getWorkflowRunEventsV4 over HTTP', () => { | ||
| it('parses a frame stream fetched via a custom dispatcher', async () => { | ||
| const origin = 'https://vercel-workflow.com'; | ||
| const agent = new MockAgent(); | ||
| agent.disableNetConnect(); | ||
|
|
||
| const body = new TextEncoder().encode('payload-bytes'); | ||
| const frames = Buffer.concat([ | ||
| encodeFrame( | ||
| { | ||
| eventId: 'evnt_1', | ||
| runId: 'wrun_1', | ||
| eventType: 'run_created', | ||
| createdAt: '2026-06-10T00:00:00.000Z', | ||
| eventData: {}, | ||
| }, | ||
| body | ||
| ), | ||
| encodeFrame({ _end: 1, next: 'cursor-2' }, new Uint8Array(0)), | ||
| ]); | ||
|
|
||
| agent | ||
| .get(origin) | ||
| .intercept({ path: '/api/v4/runs/wrun_1/events', method: 'GET' }) | ||
| .reply(200, frames, { | ||
| headers: { 'content-type': V4_FRAME_CONTENT_TYPE }, | ||
| }); | ||
|
|
||
| const result = await getWorkflowRunEventsV4( | ||
| 'wrun_1', | ||
| {}, | ||
| { token: 'test-token', dispatcher: agent } | ||
| ); | ||
|
|
||
| expect(result.events).toHaveLength(1); | ||
| expect(result.events[0].event.eventId).toBe('evnt_1'); | ||
| expect(new Uint8Array(result.events[0].body)).toEqual(body); | ||
| expect(result.next).toBe('cursor-2'); | ||
| agent.assertNoPendingInterceptors(); | ||
| }); | ||
|
|
||
| it('throws when the stream ends without the end sentinel (truncated response)', async () => { | ||
| const origin = 'https://vercel-workflow.com'; | ||
| const agent = new MockAgent(); | ||
| agent.disableNetConnect(); | ||
|
|
||
| // A complete event frame but NO `{_end: 1}` sentinel — what a response | ||
| // truncated on a frame boundary looks like. Returning this as a | ||
| // successful page would silently drop events with hasMore=false. | ||
| const frames = encodeFrame( | ||
| { | ||
| eventId: 'evnt_1', | ||
| runId: 'wrun_1', | ||
| eventType: 'run_created', | ||
| createdAt: '2026-06-10T00:00:00.000Z', | ||
| eventData: {}, | ||
| }, | ||
| new Uint8Array(0) | ||
| ); | ||
|
|
||
| agent | ||
| .get(origin) | ||
| .intercept({ path: '/api/v4/runs/wrun_1/events', method: 'GET' }) | ||
| .reply(200, frames, { | ||
| headers: { 'content-type': V4_FRAME_CONTENT_TYPE }, | ||
| }); | ||
|
|
||
| await expect( | ||
| getWorkflowRunEventsV4( | ||
| 'wrun_1', | ||
| {}, | ||
| { token: 'test-token', dispatcher: agent } | ||
| ) | ||
| ).rejects.toThrow(/end-of-stream sentinel/); | ||
| }); | ||
| }); | ||
|
|
||
| describe('createWorkflowRunEventV4 over HTTP', () => { | ||
| it('POSTs to the /events/:eventType alias and decodes the response', async () => { | ||
| const origin = 'https://vercel-workflow.com'; | ||
| const agent = new MockAgent(); | ||
| agent.disableNetConnect(); | ||
|
|
||
| agent | ||
| .get(origin) | ||
| .intercept({ | ||
| // The event type rides in the URL purely as an observability hint | ||
| // (access logs / traces); the frame meta stays authoritative. | ||
| path: '/api/v4/runs/wrun_1/events/step_completed', | ||
| method: 'POST', | ||
| }) | ||
| .reply(200, encode({ step: { stepId: 'step_1', status: 'completed' } }), { | ||
| headers: { | ||
| 'x-wf-event-id': 'evnt_1', | ||
| 'x-wf-run-id': 'wrun_1', | ||
| 'x-wf-created-at': '2026-06-10T00:00:00.000Z', | ||
| }, | ||
| }); | ||
|
|
||
| const result = await createWorkflowRunEventV4( | ||
| { | ||
| runId: 'wrun_1', | ||
| eventType: 'step_completed', | ||
| specVersion: 2, | ||
| correlationId: 'step_1', | ||
| payload: new TextEncoder().encode('"result"'), | ||
| }, | ||
| { token: 'test-token', dispatcher: agent } | ||
| ); | ||
|
|
||
| expect(result.eventId).toBe('evnt_1'); | ||
| expect(result.runId).toBe('wrun_1'); | ||
| expect(result.createdAt).toBe('2026-06-10T00:00:00.000Z'); | ||
| expect(result.body.step).toMatchObject({ stepId: 'step_1' }); | ||
| agent.assertNoPendingInterceptors(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review: Checked that PR #2414 is a stable backport of #2055, #2415, and #2547; all three source PRs are closed and merged into main, and each had review/approval activity before merge. I also checked that the stable-only adaptations called out in this PR body are limited to the v4 event wire-format/schema compatibility needed for the backport.