{"record":{"id":"a615aeb54216ab05","repo":"mastra-ai/mastra","slug":"execution-flow-of-workflow-is-not-defined-add-ste","errorCode":null,"errorMessage":"Execution flow of workflow is not defined. Add steps to the workflow via .then(), .branch(), etc.","messagePattern":"Execution flow of workflow is not defined\\. Add steps to the workflow via \\.then\\(\\), \\.branch\\(\\), etc\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/evented/workflow.ts","lineNumber":1723,"sourceCode":"   * normalized array. Used by the Mastra scheduler to register declarative\n   * schedules at boot. Returns an empty array when no schedule is declared.\n   */\n  getScheduleConfigs(): WorkflowScheduleConfig[] {\n    return this.#schedules.map(cfg => ({ ...cfg }));\n  }\n\n  __registerMastra(mastra: Mastra) {\n    super.__registerMastra(mastra);\n    this.executionEngine.__registerMastra(mastra);\n  }\n\n  async createRun(options?: {\n    runId?: string;\n    resourceId?: string;\n    disableScorers?: boolean;\n  }): Promise<Run<TEngineType, TSteps, TState, TInput, TOutput>> {\n    if (this.stepFlow.length === 0) {\n      throw new Error(\n        'Execution flow of workflow is not defined. Add steps to the workflow via .then(), .branch(), etc.',\n      );\n    }\n    if (!this.executionGraph.steps) {\n      throw new Error('Uncommitted step flow changes detected. Call .commit() to register the steps.');\n    }\n\n    const runIdToUse = options?.runId || randomUUID();\n\n    const workflowsStore = await this.mastra?.getStorage()?.getStore('workflows');\n\n    const supportsConcurrentUpdates = workflowsStore?.supportsConcurrentUpdates?.() ?? false;\n    if (workflowsStore && !supportsConcurrentUpdates) {\n      throw new MastraError({\n        id: 'ATOMIC_STORAGE_OPERATIONS_NOT_SUPPORTED',\n        domain: ErrorDomain.MASTRA,\n        category: ErrorCategory.USER,\n        text:","sourceCodeStart":1705,"sourceCodeEnd":1741,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/evented/workflow.ts#L1705-L1741","documentation":"`workflow.createRun()` checks `this.stepFlow.length === 0` and throws because no execution flow was ever attached to the workflow. A workflow with zero steps has nothing to execute; the engine refuses to create a run. The developer must build the flow using composition methods like `.then()`, `.branch()`, `.parallel()`, or `.dowhile()` before creating runs.","triggerScenarios":"Calling `workflow.createRun()` (directly or via `workflow.start()`) on a `Workflow` instance that was constructed without chaining any step-composition calls, leaving `stepFlow` empty (workflow.ts:1722-1727).","commonSituations":"Creating a workflow only to register it for scheduled/evented triggers and forgetting steps are still required; a typo'd method name silently skipping chaining (e.g. calling a helper that does nothing); refactoring that moved `.then()` calls behind a conditional branch that never ran.","solutions":["Chain at least one step onto the workflow, e.g. `workflow.then(stepA).commit()`.","If the workflow should only exist for triggers, still define a minimal step that performs the intended work.","Log/inspect the workflow construction path to find why no `.then()`/`.branch()` call executed.","Add a construction-time assertion in test code that `serializedStepGraph.length > 0` before deploying."],"exampleFix":"// before\nconst wf = new Workflow({ id: 'pipeline', mastra });\nawait wf.start({ inputData }); // throws: no flow\n\n// after\nconst wf = new Workflow({ id: 'pipeline', mastra });\nwf.then(fetchStep).then(processStep).commit();\nawait wf.start({ inputData });","handlingStrategy":"validation","validationCode":"function assertWorkflowReady(wf: Workflow): void {\n  if ((wf as any).stepFlow?.length === 0) {\n    throw new Error('Workflow has no steps; chain .then()/.branch() before createRun()');\n  }\n}\nassertWorkflowReady(workflow);\nconst run = workflow.createRun();","typeGuard":"function hasSteps(w: Workflow): boolean {\n  return (w as any).stepFlow?.length > 0;\n}","tryCatchPattern":"try {\n  const run = workflow.createRun();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Execution flow of workflow is not defined')) {\n    throw new Error('Define workflow steps with .then()/.branch() before createRun()', { cause: e });\n  } else throw e;\n}","preventionTips":["Always finish workflow definitions with at least one chained step plus .commit().","Keep workflow construction in one factory function so chaining cannot be skipped.","Add a boot-time test that createRun() succeeds for every registered workflow."],"tags":["workflow","configuration","definition","missing-steps"],"backgroundTag":"empty-workflow-definition","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}