mastra-ai/mastra · error

create-workflow failed: save-workflow threw ${saveErrors.len

Error message

create-workflow failed: save-workflow threw ${saveErrors.length} error(s):
- ${saveErrors.map(e => e.error).join('
- ')}

Sub-agent summary (unreliable, save did not succeed):
${summary}

What it means

After the workflow-builder sub-agent streams, create-workflow inspects recorded tool errors. If any save-workflow call errored and no save ultimately succeeded, it throws with the count, each underlying error, and the sub-agent's (unreliable) summary. This prevents reporting success when persistence failed.

Source

Thrown at mastracode/sdk/src/tools/workflows/create-workflow.ts:101

        }
        if (value?.type === 'tool-error' && typeof value.payload?.toolName === 'string') {
          toolErrors.push({ toolName: value.payload.toolName, error: stringifyError(value.payload.error) });
        }
      }
    } finally {
      if (!streamCompleted) {
        await reader.cancel().catch(() => undefined);
      }
      reader.releaseLock();
    }

    const summary = await stream.text;

    // If save-workflow errored, surface that error explicitly — do NOT return
    // the sub-agent's summary as if things were fine.
    const saveErrors = toolErrors.filter(e => e.toolName === 'save-workflow');
    if (saveErrors.length > 0 && !saveSucceeded) {
      throw new Error(
        `create-workflow failed: save-workflow threw ${saveErrors.length} error(s):\n- ${saveErrors
          .map(e => e.error)
          .join('\n- ')}\n\nSub-agent summary (unreliable, save did not succeed):\n${summary}`,
      );
    }

    // If save-workflow was never called, the sub-agent gave up (or hallucinated
    // success). Fail loudly so the caller doesn't think a workflow exists.
    if (!saveAttempted) {
      const otherErrors = toolErrors.length
        ? `\n\nOther sub-agent tool errors:\n- ${toolErrors.map(e => `${e.toolName}: ${e.error}`).join('\n- ')}`
        : '';
      throw new Error(
        `create-workflow failed: the workflow-builder sub-agent never called save-workflow. No workflow was persisted.${otherErrors}\n\nSub-agent summary:\n${summary}`,
      );
    }

    // Save was attempted but never returned ok (no tool-result with { ok: true, id }).

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Read the embedded '- <error>' lines to find the underlying save-workflow failure and fix that root cause.
  2. Verify the workflow storage backend is reachable and writable.
  3. Re-run create-workflow with a clearer prompt so the builder produces a valid workflow that passes save-workflow validation.
Defensive patterns

Strategy: try-catch

Try / catch

try { const { summary, workflowId } = await createWorkflowTool.execute({ request }, { mastra }); } catch (e) { if (e.message.startsWith('create-workflow failed: save-workflow threw')) { /* parse the '- <error>' lines for root cause and fix storage/validation */ } else throw e; }

Prevention

When it happens

Trigger: Sub-agent called save-workflow, every attempt errored (saveErrors.length > 0) and saveSucceeded is false — e.g. storage write failures or invalid workflow definitions rejected by save-workflow.

Common situations: Storage backend down or misconfigured; sub-agent produced an invalid workflow (bad step graph) rejected by validation; permission issues writing workflows.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/efc0efcdf50cd840. Report an issue: GitHub.