mastra-ai/mastra · error · Error
Execution flow of workflow is not defined. Add steps to the
Error message
Execution flow of workflow is not defined. Add steps to the workflow via .then(), .branch(), etc.
What it means
`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.
Source
Thrown at packages/core/src/workflows/evented/workflow.ts:1723
* normalized array. Used by the Mastra scheduler to register declarative
* schedules at boot. Returns an empty array when no schedule is declared.
*/
getScheduleConfigs(): WorkflowScheduleConfig[] {
return this.#schedules.map(cfg => ({ ...cfg }));
}
__registerMastra(mastra: Mastra) {
super.__registerMastra(mastra);
this.executionEngine.__registerMastra(mastra);
}
async createRun(options?: {
runId?: string;
resourceId?: string;
disableScorers?: boolean;
}): Promise<Run<TEngineType, TSteps, TState, TInput, TOutput>> {
if (this.stepFlow.length === 0) {
throw new Error(
'Execution flow of workflow is not defined. Add steps to the workflow via .then(), .branch(), etc.',
);
}
if (!this.executionGraph.steps) {
throw new Error('Uncommitted step flow changes detected. Call .commit() to register the steps.');
}
const runIdToUse = options?.runId || randomUUID();
const workflowsStore = await this.mastra?.getStorage()?.getStore('workflows');
const supportsConcurrentUpdates = workflowsStore?.supportsConcurrentUpdates?.() ?? false;
if (workflowsStore && !supportsConcurrentUpdates) {
throw new MastraError({
id: 'ATOMIC_STORAGE_OPERATIONS_NOT_SUPPORTED',
domain: ErrorDomain.MASTRA,
category: ErrorCategory.USER,
text:View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const wf = new Workflow({ id: 'pipeline', mastra });
await wf.start({ inputData }); // throws: no flow
// after
const wf = new Workflow({ id: 'pipeline', mastra });
wf.then(fetchStep).then(processStep).commit();
await wf.start({ inputData }); Defensive patterns
Strategy: validation
Validate before calling
function assertWorkflowReady(wf: Workflow): void {
if ((wf as any).stepFlow?.length === 0) {
throw new Error('Workflow has no steps; chain .then()/.branch() before createRun()');
}
}
assertWorkflowReady(workflow);
const run = workflow.createRun(); Type guard
function hasSteps(w: Workflow): boolean {
return (w as any).stepFlow?.length > 0;
} Try / catch
try {
const run = workflow.createRun();
} catch (e) {
if (e instanceof Error && e.message.includes('Execution flow of workflow is not defined')) {
throw new Error('Define workflow steps with .then()/.branch() before createRun()', { cause: e });
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Execution flow of workflow is not defined. Add steps to the
- @mastra/livekit: `workflowInput` is required when `workflow`
- save-workflow requires a Mastra context.
- InProcessStrategy: could not resolve step "${params.stepId}"
- Workflow "${params.id}" declares an array of schedules but o
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/a615aeb54216ab05.
Report an issue: GitHub.