{"record":{"id":"024c65a04cdfd6ce","repo":"mastra-ai/mastra","slug":"failure-in-discover-units-step-discoverresult-e","errorCode":null,"errorMessage":"Failure in discover units step: ${discoverResult.error || 'Unit discovery failed'}","messagePattern":"Failure in discover units step: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent-builder/src/workflows/template-builder/template-builder.ts","lineNumber":1625,"sourceCode":"    // Check for failure in clone step\n    if (shouldAbortWorkflow(cloneResult)) {\n      throw new Error(`Critical failure in clone step: ${cloneResult.error}`);\n    }\n\n    return cloneResult;\n  })\n  .parallel([analyzePackageStep, discoverUnitsStep])\n  .map(async ({ getStepResult }) => {\n    const analyzeResult = getStepResult(analyzePackageStep);\n    const discoverResult = getStepResult(discoverUnitsStep);\n\n    // Check for failures in parallel steps\n    if (shouldAbortWorkflow(analyzeResult)) {\n      throw new Error(`Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'}`);\n    }\n\n    if (shouldAbortWorkflow(discoverResult)) {\n      throw new Error(`Failure in discover units step: ${discoverResult.error || 'Unit discovery failed'}`);\n    }\n\n    return discoverResult;\n  })\n  .then(orderUnitsStep)\n  .map(async ({ getStepResult, getInitData }) => {\n    const cloneResult = getStepResult(cloneTemplateStep);\n    const initData = getInitData<AgentBuilderInputSchemaType>();\n    return {\n      commitSha: cloneResult.commitSha,\n      slug: cloneResult.slug,\n      targetPath: initData.targetPath,\n    };\n  })\n  .then(prepareBranchStep)\n  .map(async ({ getStepResult, getInitData }) => {\n    const cloneResult = getStepResult(cloneTemplateStep);\n    const packageResult = getStepResult(analyzePackageStep);","sourceCodeStart":1607,"sourceCodeEnd":1643,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/agent-builder/src/workflows/template-builder/template-builder.ts#L1607-L1643","documentation":"The sibling check to the analyze-step failure: if discoverUnitsStep (which scans the cloned template for units/components) aborts, this error is thrown with the step's error or 'Unit discovery failed'. The workflow cannot order or install units without a successful discovery, so it aborts.","triggerScenarios":"discoverUnitsStep aborted while scanning the template directory: unit definition files missing or malformed, unreadable directories, or discovery conventions not met by the template layout.","commonSituations":"Templates restructured to a layout the discoverer doesn't recognize, unit files with schema-invalid frontmatter/metadata, or a bad clone (wrong ref) that omits the unit directories entirely.","solutions":["Read discoverResult.error in the message for the specific discovery failure and correct the template's unit files/layout","Confirm the expected units/ directories and definition files exist in the cloned template at the chosen ref","Validate unit definition files against the expected schema before publishing the template","If 'Unit discovery failed' appears with no detail, enable step logging to capture the underlying exception"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"export function assertUnitsPresent(dir: string, unitsDir = 'units') {\n  const fs = require('node:fs');\n  if (!fs.existsSync(`${dir}/${unitsDir}`)) throw new Error(`template missing ${unitsDir}/ directory`);\n}\n// check the cloned template layout before running discovery-dependent workflows","typeGuard":"export function discoverySucceeded(r: { units?: unknown[]; error?: string }): r is { units: unknown[]; error?: undefined } {\n  return Array.isArray(r?.units) && !r.error;\n}","tryCatchPattern":"try {\n  await run.start({ ... });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failure in discover units step:')) {\n    const detail = e.message.split(': ').slice(1).join(': ');\n    // if detail === 'Unit discovery failed', enable step logging to find the real cause\n  }\n  throw e;\n}","preventionTips":["Follow the documented template directory/unit conventions exactly","Validate unit definition files against the schema in template CI","Confirm the chosen ref includes the unit directories before building","Keep step logging enabled so discoverResult.error details are never lost"],"tags":["workflow","template-builder","discovery"],"backgroundTag":"workflow-step-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}