@@ -114,6 +114,7 @@ export function workflowEntrypoint(
114114 runId,
115115 traceCarrier : traceContext ,
116116 requestedAt,
117+ runInput,
117118 } = WorkflowInvokePayloadSchema . parse ( message_ ) ;
118119 const { requestId } = metadata ;
119120 // Extract the workflow name from the topic name
@@ -239,7 +240,7 @@ export function workflowEntrypoint(
239240 let workflowStartedAt = - 1 ;
240241 let workflowRun : WorkflowRun | undefined ;
241242 // Pre-loaded events from the run_started response.
242- // When present, we skip the events.list call to reduce TTFB .
243+ // When present, we skip the events.list call.
243244 let preloadedEvents : Event [ ] | undefined ;
244245
245246 // --- Infrastructure: prepare the run state ---
@@ -257,7 +258,25 @@ export function workflowEntrypoint(
257258 runId ,
258259 {
259260 eventType : 'run_started' ,
260- specVersion : SPEC_VERSION_CURRENT ,
261+ // Use the spec version from the original start() call
262+ // when available, so the resilient start path creates
263+ // the run with the correct version (not always current).
264+ specVersion :
265+ runInput ?. specVersion ?? SPEC_VERSION_CURRENT ,
266+ // Pass run input from queue so the server can
267+ // create the run if run_created was missed.
268+ // Uint8Array values survive the queue natively
269+ // (CBOR on world-vercel, JSON reviver on world-local).
270+ ...( runInput
271+ ? {
272+ eventData : {
273+ input : runInput . input ,
274+ deploymentId : runInput . deploymentId ,
275+ workflowName : runInput . workflowName ,
276+ executionContext : runInput . executionContext ,
277+ } ,
278+ }
279+ : { } ) ,
261280 } ,
262281 { requestId }
263282 ) ;
@@ -268,7 +287,7 @@ export function workflowEntrypoint(
268287 }
269288 workflowRun = result . run ;
270289
271- // If the world returned events, use them to skip
290+ // If the response includes events, use them to skip
272291 // the initial events.list call and reduce TTFB.
273292 if ( result . events && result . events . length > 0 ) {
274293 preloadedEvents = result . events ;
@@ -282,13 +301,16 @@ export function workflowEntrypoint(
282301 } catch ( err ) {
283302 // Run was concurrently completed/failed/cancelled
284303 if ( EntityConflictError . is ( err ) || RunExpiredError . is ( err ) ) {
304+ // EntityConflictError: run was concurrently
305+ // completed/failed/cancelled during setup.
306+ // RunExpiredError: run already in terminal state.
307+ // In both cases, skip processing this message.
285308 runtimeLogger . info (
286309 'Run already finished during setup, skipping' ,
287310 { workflowRunId : runId , message : err . message }
288311 ) ;
289312 return ;
290- }
291- if ( err instanceof WorkflowRuntimeError ) {
313+ } else if ( err instanceof WorkflowRuntimeError ) {
292314 runtimeLogger . error (
293315 'Fatal runtime error during workflow setup' ,
294316 { workflowRunId : runId , error : err . message }
@@ -319,9 +341,11 @@ export function workflowEntrypoint(
319341 throw failErr ;
320342 }
321343 return ;
344+ } else {
345+ throw err ;
322346 }
323- throw err ;
324347 }
348+
325349 workflowStartedAt = + workflowRun . startedAt ;
326350
327351 span ?. setAttributes ( {
0 commit comments