{"record":{"id":"efc0efcdf50cd840","repo":"mastra-ai/mastra","slug":"create-workflow-failed-save-workflow-threw-save","errorCode":null,"errorMessage":"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}","messagePattern":"create-workflow failed: save-workflow threw (.+?) error\\(s\\):\n- (.+?)\n\nSub-agent summary \\(unreliable, save did not succeed\\):\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/tools/workflows/create-workflow.ts","lineNumber":101,"sourceCode":"        }\n        if (value?.type === 'tool-error' && typeof value.payload?.toolName === 'string') {\n          toolErrors.push({ toolName: value.payload.toolName, error: stringifyError(value.payload.error) });\n        }\n      }\n    } finally {\n      if (!streamCompleted) {\n        await reader.cancel().catch(() => undefined);\n      }\n      reader.releaseLock();\n    }\n\n    const summary = await stream.text;\n\n    // If save-workflow errored, surface that error explicitly — do NOT return\n    // the sub-agent's summary as if things were fine.\n    const saveErrors = toolErrors.filter(e => e.toolName === 'save-workflow');\n    if (saveErrors.length > 0 && !saveSucceeded) {\n      throw new Error(\n        `create-workflow failed: save-workflow threw ${saveErrors.length} error(s):\\n- ${saveErrors\n          .map(e => e.error)\n          .join('\\n- ')}\\n\\nSub-agent summary (unreliable, save did not succeed):\\n${summary}`,\n      );\n    }\n\n    // If save-workflow was never called, the sub-agent gave up (or hallucinated\n    // success). Fail loudly so the caller doesn't think a workflow exists.\n    if (!saveAttempted) {\n      const otherErrors = toolErrors.length\n        ? `\\n\\nOther sub-agent tool errors:\\n- ${toolErrors.map(e => `${e.toolName}: ${e.error}`).join('\\n- ')}`\n        : '';\n      throw new Error(\n        `create-workflow failed: the workflow-builder sub-agent never called save-workflow. No workflow was persisted.${otherErrors}\\n\\nSub-agent summary:\\n${summary}`,\n      );\n    }\n\n    // Save was attempted but never returned ok (no tool-result with { ok: true, id }).","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/tools/workflows/create-workflow.ts#L83-L119","documentation":"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.","triggerScenarios":"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.","commonSituations":"Storage backend down or misconfigured; sub-agent produced an invalid workflow (bad step graph) rejected by validation; permission issues writing workflows.","solutions":["Read the embedded '- <error>' lines to find the underlying save-workflow failure and fix that root cause.","Verify the workflow storage backend is reachable and writable.","Re-run create-workflow with a clearer prompt so the builder produces a valid workflow that passes save-workflow validation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Ensure workflow storage is reachable and writable before invoking create-workflow.","Treat the sub-agent summary in the message as diagnostics only — fix the listed save errors.","Check storage permissions and backend health routinely."],"tags":["workflows","persistence","sub-agent"],"backgroundTag":"workflow-save-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}