mastra-ai/mastra · critical
Critical failure in clone step: ${cloneResult.error}
Error message
Critical failure in clone step: ${cloneResult.error} What it means
After the cloneTemplateStep runs, the workflow checks shouldAbortWorkflow(cloneResult); if the clone step reported a failure it throws a fatal 'Critical failure in clone step' error carrying the step's own error message. This aborts the entire template build before analysis/unit-discovery run, because nothing downstream can proceed without a cloned template directory.
Source
Thrown at packages/agent-builder/src/workflows/template-builder/template-builder.ts:1609
steps: [
cloneTemplateStep,
analyzePackageStep,
discoverUnitsStep,
orderUnitsStep,
packageMergeStep,
installStep,
programmaticFileCopyStep,
intelligentMergeStep,
validationAndFixStep,
],
})
.then(cloneTemplateStep)
.map(async ({ getStepResult }) => {
const cloneResult = getStepResult(cloneTemplateStep);
// Check for failure in clone step
if (shouldAbortWorkflow(cloneResult)) {
throw new Error(`Critical failure in clone step: ${cloneResult.error}`);
}
return cloneResult;
})
.parallel([analyzePackageStep, discoverUnitsStep])
.map(async ({ getStepResult }) => {
const analyzeResult = getStepResult(analyzePackageStep);
const discoverResult = getStepResult(discoverUnitsStep);
// Check for failures in parallel steps
if (shouldAbortWorkflow(analyzeResult)) {
throw new Error(`Failure in analyze package step: ${analyzeResult.error || 'Package analysis failed'}`);
}
if (shouldAbortWorkflow(discoverResult)) {
throw new Error(`Failure in discover units step: ${discoverResult.error || 'Unit discovery failed'}`);
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Read the underlying cloneResult.error appended to this message and fix that root cause (bad URL, auth, network)
- Verify the template repository URL and requested ref (branch/tag/commit) exist and are reachable with git clone <url> manually
- Ensure credentials are available (SSH key, GITHUB_TOKEN/PAT) for private templates
- Check the destination directory: free disk space, write permissions, and that the path is not already occupied
- Retry on transient network failures
Defensive patterns
Strategy: retry
Validate before calling
const { execSync } = require('node:child_process');
export function assertRepoClonable(url: string, ref?: string) {
execSync(`git ls-remote ${JSON.stringify(url)}${ref ? ' ' + ref : ''}`, { stdio: 'ignore' });
}
// call before starting the workflow; throws if URL/ref is unreachable or unauthorized Type guard
export function cloneSucceeded(r: { templateDir?: string; error?: string }) {
return typeof r?.templateDir === 'string' && r.templateDir.length > 0 && !r.error;
} Try / catch
try {
await run.start({ repoUrl, ref, ... });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Critical failure in clone step:')) {
const cause = e.message.replace('Critical failure in clone step: ', '');
// inspect cause: auth vs network vs bad ref, then retry with backoff
}
throw e;
} Prevention
- Validate the repo URL and ref with git ls-remote before starting the workflow
- Configure credentials (PAT/SSH keys) in the environment for private templates
- Pre-check destination path: exists, writable, sufficient disk space
- Add bounded retries with backoff for transient network failures
When it happens
Trigger: cloneTemplateStep returns a failure result — typically the git clone of the template repository failed: unreachable/incorrect repo URL, missing or expired credentials for a private repo, nonexistent branch/tag/commit, or no write access to the destination directory.
Common situations: Private template repos without a token in the environment, typos in the template slug/repo URL, corporate proxies blocking git over HTTPS, SSH keys not configured, or the destination path already existing and being non-empty.
Related errors
- Repository URL or path is required
- Failure in analyze package step: ${analyzeResult.error || 'P
- Failure in discover units step: ${discoverResult.error || 'U
- Failure in install step: ${installResult.error || 'Install f
- Workflow ${workflowId} not found
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/c240fa815f516589.
Report an issue: GitHub.