mastra-ai/mastra · error

create-workflow failed: save-workflow was called but did not

Error message

create-workflow failed: save-workflow was called but did not return { ok: true }.${otherErrors}

Sub-agent summary:
${summary}

What it means

When save-workflow was called but no tool result ever returned { ok: true, id }, create-workflow throws this error. A save attempt without a successful ok result means the workflow may not be durably persisted, so the tool fails loudly instead of returning a summary.

Source

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

    }

    // 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 }).
    if (!saveSucceeded) {
      const otherErrors = toolErrors.length
        ? `\n\nSub-agent tool errors:\n- ${toolErrors.map(e => `${e.toolName}: ${e.error}`).join('\n- ')}`
        : '';
      throw new Error(
        `create-workflow failed: save-workflow was called but did not return { ok: true }.${otherErrors}\n\nSub-agent summary:\n${summary}`,
      );
    }

    return { summary, workflowId };
  },
});

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Inspect 'Sub-agent tool errors' in the message for the save-workflow failure reason.
  2. Re-run create-workflow and confirm a final successful save.
  3. Verify save-workflow's output schema/ok contract matches the version in use (version drift can break ok detection).
Defensive patterns

Strategy: try-catch

Type guard

function isSaveOk(r: unknown): r is { ok: true; id: string } { return !!r && typeof r === 'object' && (r as any).ok === true && typeof (r as any).id === 'string'; }

Try / catch

try { const res = await createWorkflowTool.execute({ request }, { mastra }); } catch (e) { if (e.message.includes('did not return { ok: true }')) { /* inspect sub-agent tool errors, then retry */ } else throw e; }

Prevention

When it happens

Trigger: saveAttempted is true but saveSucceeded is false — save-workflow tool results never contained { ok: true } (errored, returned a different shape, or results were lost).

Common situations: save-workflow partially failing (validation errors in result rather than thrown error); sub-agent output parsing dropping the tool result; storage returning non-ok responses.

Related errors


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