{"record":{"id":"ccc1878d0217e3b0","repo":"mastra-ai/mastra","slug":"unknown-stored-step-type-json-stringify-exhaus","errorCode":null,"errorMessage":"Unknown stored step type: ${JSON.stringify(_exhaustive)}","messagePattern":"Unknown stored step type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/workflows/dynamic/rehydrate.ts","lineNumber":205,"sourceCode":"      const step = rehydrateSingleEntry(entry.step, mastra, schemaOpts);\n      const serializedCondition = entry.serializedCondition ?? {\n        id: `${getSingleStepEntryId(step)}-condition`,\n        fn: derivePredicateLabel(predicate),\n      };\n      const live: StepFlowEntry = {\n        type: 'loop',\n        step,\n        condition: predicateToCondition(predicate),\n        loopType,\n        serializedCondition,\n        predicate,\n      };\n      wf.__pushStepFlowEntry(live, { ...entry, serializedCondition });\n      return;\n    }\n    default: {\n      const _exhaustive: never = entry;\n      throw new Error(`Unknown stored step type: ${JSON.stringify(_exhaustive)}`);\n    }\n  }\n}\n\n/**\n * Reconstruct the options bag `.agent()` accepts from a serialized entry.\n * Restores `structuredOutput.schema` from `outputSchema` (JSON Schema → Zod)\n * and merges in `retries` / `metadata`. Returns `undefined` when nothing to\n * restore so `.agent(agentId)` stays a clean call.\n */\nfunction rebuildAgentOptions(\n  entry: {\n    outputSchema?: Record<string, any>;\n    options?: SerializedStepOptions;\n  },\n  schemaOpts?: JsonSchemaToZodOptions,\n): Record<string, any> | undefined {\n  const opts: Record<string, any> = {};","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workflows/dynamic/rehydrate.ts#L187-L223","documentation":"applyGraphEntry uses a TypeScript exhaustive switch over the stored entry `type` discriminant. Reaching the `default` branch means the entry's type is not one of the known stored step types, which should be impossible for correctly typed data — so the `never` assignment is a compile-time exhaustiveness guard and the throw is a runtime backstop against corrupt or newer-format stored graphs.","triggerScenarios":"rehydrateWorkflow processes a stored graph JSON containing an entry whose `type` value is unrecognized — e.g. data produced by a newer library version with new entry types, a corrupted/hand-edited stored graph, or unvalidated JSON from external storage cast to the entry type.","commonSituations":"Loading workflows stored by a newer mastra/core version into an older runtime; manual edits or migrations that introduced an invalid `type`; storage backends holding arbitrary JSON that was never validated against the stored-entry schema.","solutions":["Upgrade @mastra/core to the same (or newer) version that wrote the stored graph so the entry type is recognized.","Inspect the stored graph JSON and find the offending entry's `type` value; fix or remove it.","Validate stored graph JSON against the expected schema before calling rehydrateWorkflow.","Re-serialize the workflow from its source definition using the current runtime version."],"exampleFix":"// before: loading v-next stored data on older runtime\nconst entry = stored.entries[3]; // type: 'wait-event' (unknown here)\n\n// after: upgrade core, or guard\nif (!isKnownStoredEntryType(entry.type)) throw new Error('Incompatible stored workflow version; upgrade @mastra/core');","handlingStrategy":"validation","validationCode":"const KNOWN_TYPES = new Set(['step', 'agent', 'tool', 'mapping', 'sleep', 'sleepUntil', 'conditional', 'loop', 'parallel', 'branch', 'foreach', 'waitUntil', 'sleepEvent']);\nfunction validateStoredTypes(graph) {\n  for (const e of graph.entries) {\n    if (!KNOWN_TYPES.has(e.type)) throw new Error(`Incompatible stored entry type: ${e.type}`);\n  }\n}","typeGuard":"function isKnownStoredEntry(type: string): boolean {\n  return ['step','agent','tool','mapping','sleep','sleepUntil','conditional','loop','parallel','branch','foreach'].includes(type);\n}","tryCatchPattern":"try {\n  const wf = rehydrateWorkflow(stored, mastra);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Unknown stored step type')) {\n    throw new Error('Stored workflow was written by a newer/other version; upgrade @mastra/core and retry.');\n  }\n  throw err;\n}","preventionTips":["Keep the serialization and rehydration runtime versions in lockstep across services.","Schema-validate stored graph JSON before passing it to rehydrateWorkflow.","Never cast untrusted storage JSON blindly to internal entry types."],"tags":["workflow","serialization","exhaustiveness","version-mismatch"],"backgroundTag":"unsupported-serialized-workflow-entry-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}