{"record":{"id":"77e52ef825ca6b25","repo":"mastra-ai/mastra","slug":"dynamic-workflow-bundle-contains-more-than-one-def","errorCode":null,"errorMessage":"Dynamic workflow bundle contains more than one definition with id \"${def.id}\". Ids must be unique within a bundle.","messagePattern":"Dynamic workflow bundle contains more than one definition with id \"(.+?)\"\\. Ids must be unique within a bundle\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/mastra/index.ts","lineNumber":4974,"sourceCode":"   * `addDynamicWorkflow()` is the single-member case.\n   *\n   * @example\n   * ```typescript\n   * await mastra.addDynamicWorkflows([\n   *   { id: 'lookup-first-customer', ... },  // helper — order is derived, not assumed\n   *   { id: 'parallel-customer-lookup', ... }, // root, nests the helper above\n   * ]);\n   * ```\n   */\n  public async addDynamicWorkflows(\n    defs: readonly (DynamicWorkflowGraph | WorkflowBuilderDefinitionInput)[],\n  ): Promise<void> {\n    if (defs.length === 0) return;\n\n    const seen = new Set<string>();\n    for (const def of defs) {\n      if (seen.has(def.id)) {\n        throw new Error(\n          `Dynamic workflow bundle contains more than one definition with id \"${def.id}\". Ids must be unique within a bundle.`,\n        );\n      }\n      seen.add(def.id);\n    }\n\n    // Save-path is strict (boot-time load is lenient — see #loadDynamicWorkflows).\n    // Normalization coerces the wire shape; one validation call per member\n    // covers structure, JSON-Schema keywords, references, and schema-flow.\n    const members = defs.map(def => ({\n      normalized: normalizeWorkflowBuilderDefinition({\n        id: def.id,\n        description: def.description,\n        metadata: def.metadata,\n        inputSchema: def.inputSchema,\n        outputSchema: def.outputSchema,\n        stateSchema: def.stateSchema,\n        requestContextSchema: def.requestContextSchema,","sourceCodeStart":4956,"sourceCodeEnd":4992,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/mastra/index.ts#L4956-L4992","documentation":"When loading a dynamic workflow bundle, Mastra validates that every definition id in the bundle is unique by inserting ids into a Set and throwing a plain Error on the first duplicate. Duplicate ids would make member lookup and nested-workflow resolution ambiguous, so they are rejected up front.","triggerScenarios":"Calling the dynamic workflow bundle loader with a defs array containing two or more definitions whose def.id is the same string — e.g. the same workflow object included twice, or two factories emitting workflows with the same id.","commonSituations":"Globbing workflow files where two files export workflows with a shared id; concatenating bundles from multiple sources without deduplication; forgetting to version/rename a workflow id when copying one to create a variant.","solutions":["Find the definitions sharing the id (the message names it) and give each a unique workflow id at creation.","Deduplicate the defs array before passing it (filter by id, keeping one occurrence).","Rename the copied workflow's id parameter so variants get distinct ids.","Fix the file/glob gathering logic so a single workflow is not included twice."],"exampleFix":"// before\nconst defs = [makeWorkflow({ id: 'deploy' }), makeWorkflow({ id: 'deploy' })];\nawait registerDynamicWorkflowBundle(defs);\n// after\nconst defs = [makeWorkflow({ id: 'deploy-staging' }), makeWorkflow({ id: 'deploy-prod' })];\nawait registerDynamicWorkflowBundle(defs);","handlingStrategy":"validation","validationCode":"const ids = defs.map(d => d.id);\nconst dupes = ids.filter((id, i) => ids.indexOf(id) !== i);\nif (dupes.length > 0) {\n  throw new Error(`Duplicate workflow ids in bundle: ${[...new Set(dupes)].join(', ')}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await registerDynamicWorkflowBundle(defs);\n} catch (e) {\n  if (e instanceof Error && /more than one definition with id/.test(e.message)) {\n    console.error('Deduplicate defs before registering:', e.message);\n  } else throw e;\n}","preventionTips":["Deduplicate defs by id (e.g. new Map(defs.map(d => [d.id, d])).values()) before registering.","Give workflow variants unique ids at creation time, not at registration time.","Check globbed workflow files for duplicate exports."],"tags":["workflow","duplicate-id","validation"],"backgroundTag":"duplicate-identifier","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}