DEV Community

Cover image for Resolving "This workflow run was not suspended" in Nested Mastra Workflows
Ahmad Abdulaziz
Ahmad Abdulaziz

Posted on

Resolving "This workflow run was not suspended" in Nested Mastra Workflows

If you are building nested workflows with Mastra and encountering the error "This workflow run was not suspended," it is likely because you are attempting to resume the child workflow directly instead of through the parent.

The Problem

When a nested workflow hits a suspension point like a manual trigger or user input step, the entire execution state is tied to the main parent workflow.

//mainworkflow.ts
export const mainWorkflow = createWorkflow({
  id: "benki",
})
  .then(childWorkflow).commit();
Enter fullscreen mode Exit fullscreen mode
//childworkflow.ts

//nested workflow
export const childWorkflow = createWorkflow({
  id: "child-workflow",
  description: "Workflow for processing transfers",
  inputSchema: z.object({
    message: z.string(),
  }),
  outputSchema: z.object({
    message: z.string(),
  })
})
  .then(resolveStep)
  .then(requestInfoFormUserStep) //suspend step to get info from the user
  .then(finalExecutionStep)
  .commit();
Enter fullscreen mode Exit fullscreen mode
// app.ts
import { mastra } from "../mastra";

const workflow = mastra.getWorkflow("mainWorkflow");
const workflowRun = await workflow.createRun();
Enter fullscreen mode Exit fullscreen mode

In the example below, even though the suspension happens inside childWorkflow, attempting to resume it using mastra.getWorkflow("childWorkflow") will fail because that specific run context doesn't exist independently of the parent.

const resumeWorkflow = mastra.getWorkflow("childWorkflow");
const workflowRun = await resumeWorkflow.createRun({ runId });


// Resume the workflow from the suspended step
await workflowRun.resume({
  step: ["child-workflow", "request-data"],
  resumeData: { /* ... */ },
});
Enter fullscreen mode Exit fullscreen mode

The Solution

You must access the main workflow that initiated the run. The step property in the resume object should then use an array representing the suspendedPaths to point to the correct step inside the nested workflow.

const resumeWorkflow = mastra.getWorkflow("mainWorkflow"); //main workflow
const workflowRun = await resumeWorkflow.createRun({ runId });

await workflowRun.resume({
  step: ["child-workflow", "request-data"],
  resumeData: { /* ... */ },
});
Enter fullscreen mode Exit fullscreen mode

Note: Ensure the strings in your step array exactly match the id fields defined in your workflow configuration.

Top comments (0)