{"record":{"id":"d18f4767095384b7","repo":"mastra-ai/mastra","slug":"dynamic-workflow-references-nested-workflow-wor","errorCode":null,"errorMessage":"Dynamic workflow references nested workflow \"${workflowId}\" which is not registered on this Mastra instance.","messagePattern":"Dynamic workflow references nested workflow \"(.+?)\" which is not registered on this Mastra instance\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/dynamic/rehydrate.ts","lineNumber":398,"sourceCode":"  if (typeof (mastra as any).getWorkflowById === 'function') {\n    try {\n      return (mastra as any).getWorkflowById(id);\n    } catch {\n      // fall through to registration-key lookup\n    }\n  }\n  if (typeof (mastra as any).getWorkflow !== 'function') return undefined;\n  try {\n    return (mastra as any).getWorkflow(id);\n  } catch {\n    return undefined;\n  }\n}\n\nfunction assertWorkflowExists(mastra: Mastra, workflowId: string): any {\n  const wf = tryGetWorkflowById(mastra, workflowId);\n  if (!wf) {\n    throw new Error(\n      `Dynamic workflow references nested workflow \"${workflowId}\" which is not registered on this Mastra instance.`,\n    );\n  }\n  return wf;\n}\n","sourceCodeStart":380,"sourceCodeEnd":404,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/dynamic/rehydrate.ts#L380-L404","documentation":"`assertWorkflowExists` is the shared lookup used when a stored dynamic workflow references a nested workflow by `workflowId`. If `tryGetWorkflowById` finds nothing on the Mastra instance, rehydration aborts with this error because nested workflow execution requires the actual registered workflow object.","triggerScenarios":"rehydrateWorkflow (or a nested entry via rehydrateSingleEntry case 'workflow') references `entry.workflowId` that is absent from `new Mastra({ workflows: {...} })` — removed, renamed, or deployed to an instance that never registered it.","commonSituations":"Multi-service deployments where the nested workflow lives in another service; renaming workflow ids in refactors; conditional registration of workflows per environment.","solutions":["Register the nested workflow: `new Mastra({ workflows: { '<workflowId>': nestedWf } })` before rehydrating.","Verify stored `workflowId` values match registered keys exactly after renames.","Ensure all services that rehydrate the graph register the full set of referenced workflows.","Pre-validate: for each stored workflow entry, assert `mastra.getWorkflow(workflowId)` exists."],"exampleFix":"// before\nconst mastra = new Mastra({}); // graph nests workflowId 'childWf'\n\n// after\nconst mastra = new Mastra({ workflows: { childWf } });","handlingStrategy":"validation","validationCode":"function assertNestedWorkflowsRegistered(stored, mastra) {\n  const visit = (e) => {\n    if (!e) return;\n    if (e.type === 'workflow' && !mastra.getWorkflow?.(e.workflowId)) {\n      throw new Error(`Nested workflow \"${e.workflowId}\" must be registered before rehydration`);\n    }\n    (e.steps ?? []).forEach(visit);\n  };\n  stored.entries.forEach(visit);\n}","typeGuard":"function nestedWorkflowResolves(mastra: Mastra, workflowId: string): boolean {\n  return !!mastra.getWorkflow?.(workflowId);\n}","tryCatchPattern":"try {\n  const wf = rehydrateWorkflow(stored, mastra);\n} catch (err) {\n  const m = err instanceof Error && err.message.match(/nested workflow \"([^\"]+)\" which is not registered/);\n  if (m) throw new Error(`Register nested workflow '${m[1]}' on this Mastra instance.`);\n  throw err;\n}","preventionTips":["Register all nested workflows in the Mastra constructor of every service that rehydrates the parent.","Keep workflow id renames and stored graphs in sync via migration scripts.","Add a deploy-time audit that walks stored graphs and verifies every workflowId."],"tags":["workflow","nested-workflow","registration","rehydration"],"backgroundTag":"unregistered-resource-reference","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}