@mastra/core 1.86.0 → 1.87.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (481) hide show
  1. package/dist/_types/@ai-sdk_anthropic@3.0.137/dist/index.d.ts +2 -2
  2. package/dist/_types/@ai-sdk_google@3.0.140/dist/index.d.ts +2 -2
  3. package/dist/_types/@ai-sdk_openai@3.0.135/dist/index.d.ts +2 -2
  4. package/dist/a2a/index.cjs +1 -1
  5. package/dist/a2a/index.js +1 -1
  6. package/dist/agent/durable/constants.d.ts +2 -0
  7. package/dist/agent/durable/evented-execution.d.ts +7 -0
  8. package/dist/agent/durable/execution-engine.d.ts +1 -0
  9. package/dist/agent/durable/execution-fence.d.ts +2 -0
  10. package/dist/agent/durable/index.cjs +4 -1
  11. package/dist/agent/durable/index.d.ts +2 -1
  12. package/dist/agent/durable/index.js +2 -2
  13. package/dist/agent/durable/run-registry.d.ts +13 -0
  14. package/dist/agent/durable/segment-spans.d.ts +54 -1
  15. package/dist/agent/durable/types.d.ts +12 -0
  16. package/dist/agent/durable/workflows/durable-loop-builder.d.ts +57 -2
  17. package/dist/agent/durable/workflows/finalize-run.d.ts +4 -1
  18. package/dist/agent/durable/workflows/shared/index.d.ts +1 -1
  19. package/dist/agent/durable/workflows/shared/reported-cost.d.ts +7 -0
  20. package/dist/agent/durable/workflows/shared/schemas.d.ts +16 -1
  21. package/dist/agent/durable/workflows/shared/tool-call-concurrency.d.ts +6 -0
  22. package/dist/agent/durable/workflows/steps/llm-execution.d.ts +5 -0
  23. package/dist/agent/durable/workflows/steps/llm-mapping.d.ts +6 -0
  24. package/dist/agent/durable/workflows/steps/tool-call.d.ts +20 -0
  25. package/dist/agent/index.cjs +3 -3
  26. package/dist/agent/index.js +3 -3
  27. package/dist/agent/message-list/index.cjs +1 -1
  28. package/dist/agent/message-list/index.js +1 -1
  29. package/dist/agent/request-context-snapshot.d.ts +3 -2
  30. package/dist/agent/streams/run-records.d.ts +9 -1
  31. package/dist/agent/thread-stream-runtime.d.ts +3 -1
  32. package/dist/agent-builder/ee/index.cjs +1 -1
  33. package/dist/agent-builder/ee/index.js +1 -1
  34. package/dist/agent-controller/index.cjs +1 -1
  35. package/dist/agent-controller/index.js +1 -1
  36. package/dist/agent-controller/session-run-engine.d.ts +5 -2
  37. package/dist/agent-controller/session.d.ts +2 -0
  38. package/dist/agent-controller/types.d.ts +23 -0
  39. package/dist/{agent-controller-D_5Dc8d3.cjs → agent-controller-BTIxiD1u.cjs} +44 -14
  40. package/dist/{agent-controller-D5EKeS1H.js → agent-controller-C1bK0CXm.js} +44 -14
  41. package/dist/background-tasks/index.cjs +1 -1
  42. package/dist/background-tasks/index.js +1 -1
  43. package/dist/background-tasks/manager.d.ts +4 -1
  44. package/dist/{background-tasks-idnlMbqD.js → background-tasks-BbVsBghi.js} +139 -51
  45. package/dist/{background-tasks-BVxb0VGV.cjs → background-tasks-CVl6e0Jo.cjs} +139 -51
  46. package/dist/browser/index.cjs +1 -1
  47. package/dist/browser/index.js +1 -1
  48. package/dist/{builder-CBWoYNck.cjs → builder-BRJPSTig.cjs} +2 -2
  49. package/dist/{builder-Cuq-j2w3.js → builder-C8XzrtBQ.js} +2 -2
  50. package/dist/cache/base.d.ts +40 -10
  51. package/dist/cache/index.cjs +1 -1
  52. package/dist/cache/index.js +1 -1
  53. package/dist/capabilities/302ai.json +213 -213
  54. package/dist/capabilities/abliteratedllm.json +30 -30
  55. package/dist/capabilities/abliteration-ai.json +6 -6
  56. package/dist/capabilities/above.json +19 -19
  57. package/dist/capabilities/adaption.json +16 -16
  58. package/dist/capabilities/adzuki.json +19 -19
  59. package/dist/capabilities/agentrouter.json +11 -11
  60. package/dist/capabilities/agnes.json +2 -2
  61. package/dist/capabilities/ai-router.json +6 -6
  62. package/dist/capabilities/aiand.json +20 -20
  63. package/dist/capabilities/aigrow.json +14 -14
  64. package/dist/capabilities/aimlapi.json +146 -150
  65. package/dist/capabilities/aixy.json +21 -21
  66. package/dist/capabilities/aki-io.json +14 -14
  67. package/dist/capabilities/alibaba-cn.json +96 -96
  68. package/dist/capabilities/alibaba-coding-plan-cn.json +4 -4
  69. package/dist/capabilities/alibaba-coding-plan.json +4 -4
  70. package/dist/capabilities/alibaba-token-plan-cn.json +50 -50
  71. package/dist/capabilities/alibaba-token-plan.json +49 -49
  72. package/dist/capabilities/alibaba.json +69 -69
  73. package/dist/capabilities/ambient.json +12 -12
  74. package/dist/capabilities/amd.json +8 -8
  75. package/dist/capabilities/anthropic.json +43 -43
  76. package/dist/capabilities/anyapi.json +17 -17
  77. package/dist/capabilities/apiko.json +2 -2
  78. package/dist/capabilities/arcee.json +11 -11
  79. package/dist/capabilities/augure.json +6 -6
  80. package/dist/capabilities/auriko.json +24 -24
  81. package/dist/capabilities/bailing.json +5 -5
  82. package/dist/capabilities/baseten.json +35 -35
  83. package/dist/capabilities/bee.json +5 -5
  84. package/dist/capabilities/berget.json +8 -8
  85. package/dist/capabilities/bothub.json +15 -15
  86. package/dist/capabilities/boundless.json +36 -36
  87. package/dist/capabilities/bumo.json +47 -47
  88. package/dist/capabilities/byteplus.json +30 -30
  89. package/dist/capabilities/cerebras.json +4 -4
  90. package/dist/capabilities/cheapaimodel.json +10 -10
  91. package/dist/capabilities/cheapest-token.json +32 -32
  92. package/dist/capabilities/chutes.json +11 -14
  93. package/dist/capabilities/cline-pass.json +33 -33
  94. package/dist/capabilities/cloudcode.json +9 -9
  95. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  96. package/dist/capabilities/cloudflare-workers-ai.json +17 -78
  97. package/dist/capabilities/commandcode.json +155 -155
  98. package/dist/capabilities/concentrate.json +286 -277
  99. package/dist/capabilities/cortecs.json +114 -114
  100. package/dist/capabilities/crossmodel.json +189 -189
  101. package/dist/capabilities/crusoe.json +8 -8
  102. package/dist/capabilities/daoxe.json +6 -6
  103. package/dist/capabilities/databricks.json +129 -129
  104. package/dist/capabilities/deepinfra.json +132 -69
  105. package/dist/capabilities/deepseek.json +4 -4
  106. package/dist/capabilities/digitalocean.json +112 -112
  107. package/dist/capabilities/dothoosh.json +31 -31
  108. package/dist/capabilities/doubleword.json +26 -26
  109. package/dist/capabilities/edenai.json +902 -1760
  110. package/dist/capabilities/empiriolabs.json +156 -158
  111. package/dist/capabilities/engy.json +18 -18
  112. package/dist/capabilities/entrim.json +6 -6
  113. package/dist/capabilities/evroc.json +16 -16
  114. package/dist/capabilities/ezkielyna.json +7 -7
  115. package/dist/capabilities/fastrouter.json +73 -73
  116. package/dist/capabilities/fireworks-ai.json +86 -65
  117. package/dist/capabilities/freemodel.json +24 -24
  118. package/dist/capabilities/friendli.json +2 -2
  119. package/dist/capabilities/frogbot.json +96 -96
  120. package/dist/capabilities/gisoo.json +17 -17
  121. package/dist/capabilities/gmicloud.json +10 -10
  122. package/dist/capabilities/google.json +50 -50
  123. package/dist/capabilities/graphn.json +12 -12
  124. package/dist/capabilities/greenpt.json +35 -35
  125. package/dist/capabilities/groq.json +8 -8
  126. package/dist/capabilities/helicone.json +77 -77
  127. package/dist/capabilities/hostinger-router.json +11 -11
  128. package/dist/capabilities/hpc-ai.json +14 -14
  129. package/dist/capabilities/huawei-maas.json +16 -16
  130. package/dist/capabilities/hubris.json +30 -30
  131. package/dist/capabilities/huggingface.json +101 -91
  132. package/dist/capabilities/hyper.json +24 -24
  133. package/dist/capabilities/impossibl.json +135 -135
  134. package/dist/capabilities/inception.json +2 -2
  135. package/dist/capabilities/inceptron.json +8 -8
  136. package/dist/capabilities/inco.json +4 -4
  137. package/dist/capabilities/infer.json +13 -13
  138. package/dist/capabilities/inferall.json +4 -4
  139. package/dist/capabilities/inference-coop.json +9 -9
  140. package/dist/capabilities/inferenceapis.json +26 -26
  141. package/dist/capabilities/inferris.json +3 -3
  142. package/dist/capabilities/infersia.json +14 -14
  143. package/dist/capabilities/inferx.json +3 -3
  144. package/dist/capabilities/infomaniak.json +2 -2
  145. package/dist/capabilities/io-net.json +5 -5
  146. package/dist/capabilities/iteracompute.json +55 -55
  147. package/dist/capabilities/jad-ai.json +2 -2
  148. package/dist/capabilities/jalapeno.json +11 -11
  149. package/dist/capabilities/jiekou.json +64 -64
  150. package/dist/capabilities/joingonka.json +4 -4
  151. package/dist/capabilities/jzstoken.json +40 -40
  152. package/dist/capabilities/keln.json +25 -25
  153. package/dist/capabilities/kenari.json +123 -123
  154. package/dist/capabilities/kilo.json +639 -623
  155. package/dist/capabilities/kimi-code-plan-cn.json +4 -4
  156. package/dist/capabilities/kimi-code-plan-global.json +4 -4
  157. package/dist/capabilities/kitani.json +6 -6
  158. package/dist/capabilities/klavo.json +23 -23
  159. package/dist/capabilities/korouter.json +31 -31
  160. package/dist/capabilities/kunavo.json +10 -10
  161. package/dist/capabilities/liquid.json +10 -10
  162. package/dist/capabilities/lithosai.json +2 -2
  163. package/dist/capabilities/llmgateway-providers.json +895 -886
  164. package/dist/capabilities/llmgateway.json +344 -336
  165. package/dist/capabilities/llmtr.json +26 -26
  166. package/dist/capabilities/logits.json +2 -2
  167. package/dist/capabilities/longcat.json +2 -2
  168. package/dist/capabilities/lowrouter.json +49 -49
  169. package/dist/capabilities/lyceum.json +11 -11
  170. package/dist/capabilities/melious.json +12 -12
  171. package/dist/capabilities/merge-gateway.json +259 -258
  172. package/dist/capabilities/meta.json +8 -8
  173. package/dist/capabilities/minimax-cn-coding-plan.json +2 -2
  174. package/dist/capabilities/minimax-cn.json +5 -5
  175. package/dist/capabilities/minimax-coding-plan.json +2 -2
  176. package/dist/capabilities/minimax.json +5 -5
  177. package/dist/capabilities/mistral.json +18 -18
  178. package/dist/capabilities/mixlayer.json +5 -5
  179. package/dist/capabilities/modal.json +10 -10
  180. package/dist/capabilities/model-oracle-ai.json +26 -26
  181. package/dist/capabilities/modelis.json +13 -13
  182. package/dist/capabilities/modelscope.json +2 -2
  183. package/dist/capabilities/modular.json +8 -8
  184. package/dist/capabilities/moneo.json +13 -13
  185. package/dist/capabilities/moonshotai-cn.json +3 -3
  186. package/dist/capabilities/moonshotai.json +3 -3
  187. package/dist/capabilities/morph.json +11 -11
  188. package/dist/capabilities/munito-eu.json +6 -6
  189. package/dist/capabilities/munito.json +10 -10
  190. package/dist/capabilities/nan.json +24 -24
  191. package/dist/capabilities/nano-gpt.json +583 -548
  192. package/dist/capabilities/nearai.json +82 -82
  193. package/dist/capabilities/nebius.json +33 -33
  194. package/dist/capabilities/neon.json +135 -135
  195. package/dist/capabilities/neuralwatt.json +37 -37
  196. package/dist/capabilities/nokeep.json +5 -5
  197. package/dist/capabilities/novita-ai.json +153 -153
  198. package/dist/capabilities/nvidia.json +25 -57
  199. package/dist/capabilities/oathbreaker.json +2 -2
  200. package/dist/capabilities/obscurify.json +27 -27
  201. package/dist/capabilities/oci.json +16 -7
  202. package/dist/capabilities/ofox.json +358 -358
  203. package/dist/capabilities/ollama-cloud.json +50 -50
  204. package/dist/capabilities/openai.json +79 -47
  205. package/dist/capabilities/opencode-go.json +88 -88
  206. package/dist/capabilities/openreason.json +5 -5
  207. package/dist/capabilities/openrouter.json +543 -533
  208. package/dist/capabilities/opper.json +28 -28
  209. package/dist/capabilities/orcarouter.json +238 -238
  210. package/dist/capabilities/outerlabs.json +30 -30
  211. package/dist/capabilities/ovhcloud.json +61 -7
  212. package/dist/capabilities/pareto.json +4 -4
  213. package/dist/capabilities/pendra.json +4 -4
  214. package/dist/capabilities/perplexity-agent.json +59 -59
  215. package/dist/capabilities/perplexity.json +2 -2
  216. package/dist/capabilities/phala.json +34 -34
  217. package/dist/capabilities/pioneer.json +26 -26
  218. package/dist/capabilities/poe.json +99 -99
  219. package/dist/capabilities/poolside.json +2 -2
  220. package/dist/capabilities/powerspring.json +12 -12
  221. package/dist/capabilities/primalabs.json +10 -10
  222. package/dist/capabilities/prime.json +117 -101
  223. package/dist/capabilities/privatemode-ai.json +11 -11
  224. package/dist/capabilities/proxystacks.json +6 -6
  225. package/dist/capabilities/qiniu-ai.json +13 -13
  226. package/dist/capabilities/refuseless.json +8 -8
  227. package/dist/capabilities/regolo-ai.json +11 -11
  228. package/dist/capabilities/requesty.json +171 -171
  229. package/dist/capabilities/ruapi.json +19 -19
  230. package/dist/capabilities/runcrate.json +17 -17
  231. package/dist/capabilities/runinfra.json +16 -16
  232. package/dist/capabilities/sakana.json +5 -5
  233. package/dist/capabilities/sambanova.json +6 -6
  234. package/dist/capabilities/sandbase.json +22 -22
  235. package/dist/capabilities/sarvam.json +12 -12
  236. package/dist/capabilities/scaleway.json +17 -17
  237. package/dist/capabilities/scnet-token-plan.json +14 -14
  238. package/dist/capabilities/scx-ai.json +29 -29
  239. package/dist/capabilities/sensenova.json +10 -10
  240. package/dist/capabilities/siliconflow-cn.json +58 -58
  241. package/dist/capabilities/siliconflow.json +61 -61
  242. package/dist/capabilities/snowflake-cortex.json +24 -24
  243. package/dist/capabilities/sokkan.json +9 -9
  244. package/dist/capabilities/sparrowcodes.json +18 -18
  245. package/dist/capabilities/standardcompute.json +94 -94
  246. package/dist/capabilities/steadyrouter.json +42 -42
  247. package/dist/capabilities/stepfun-ai-step-plan.json +6 -6
  248. package/dist/capabilities/stepfun-ai.json +5 -5
  249. package/dist/capabilities/stepfun-step-plan.json +5 -5
  250. package/dist/capabilities/stepfun.json +5 -5
  251. package/dist/capabilities/stepping-stone.json +20 -20
  252. package/dist/capabilities/superbot-gg.json +4 -4
  253. package/dist/capabilities/synthetic.json +12 -12
  254. package/dist/capabilities/synthorai.json +21 -21
  255. package/dist/capabilities/teamorouter.json +24 -24
  256. package/dist/capabilities/teapot-router.json +13 -13
  257. package/dist/capabilities/tencent-token-plan.json +56 -32
  258. package/dist/capabilities/tencent-tokenhub.json +43 -43
  259. package/dist/capabilities/tensorx.json +48 -48
  260. package/dist/capabilities/tenstorrent.json +2 -2
  261. package/dist/capabilities/the-grid-ai.json +33 -33
  262. package/dist/capabilities/thinkingmachines.json +78 -78
  263. package/dist/capabilities/tinfoil.json +10 -10
  264. package/dist/capabilities/toapis.json +2 -2
  265. package/dist/capabilities/togetherai.json +52 -50
  266. package/dist/capabilities/tokengo.json +19 -19
  267. package/dist/capabilities/tokenify.json +10 -10
  268. package/dist/capabilities/trustedrouter.json +5 -5
  269. package/dist/capabilities/trustedtokens.json +16 -16
  270. package/dist/capabilities/umans-ai-coding-plan.json +16 -16
  271. package/dist/capabilities/umans-ai.json +10 -10
  272. package/dist/capabilities/unrestricted.json +8 -8
  273. package/dist/capabilities/uplinkswitch.json +19 -19
  274. package/dist/capabilities/upstage.json +8 -8
  275. package/dist/capabilities/vancine.json +20 -20
  276. package/dist/capabilities/vercel.json +539 -539
  277. package/dist/capabilities/vivgrid.json +85 -85
  278. package/dist/capabilities/volcengine-coding-plan.json +36 -27
  279. package/dist/capabilities/volcengine.json +26 -26
  280. package/dist/capabilities/vultr.json +30 -30
  281. package/dist/capabilities/wafer.ai.json +19 -19
  282. package/dist/capabilities/wallaby.json +5 -5
  283. package/dist/capabilities/wally.json +8 -8
  284. package/dist/capabilities/wandb.json +19 -19
  285. package/dist/capabilities/watt.json +23 -23
  286. package/dist/capabilities/xai.json +7 -7
  287. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  288. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  289. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  290. package/dist/capabilities/xiaomi.json +2 -2
  291. package/dist/capabilities/xpersona.json +12 -12
  292. package/dist/capabilities/xxapi.json +30 -30
  293. package/dist/capabilities/zai-coding-plan.json +17 -17
  294. package/dist/capabilities/zai.json +28 -26
  295. package/dist/capabilities/zenifra.json +27 -27
  296. package/dist/capabilities/zenmux.json +164 -164
  297. package/dist/capabilities/zerogpu.json +11 -11
  298. package/dist/capabilities/zhipuai-coding-plan.json +4 -4
  299. package/dist/capabilities/zhipuai.json +22 -22
  300. package/dist/capabilities/zro.json +3 -3
  301. package/dist/channels/agent-channels.d.ts +9 -1
  302. package/dist/channels/attach-file-tool.d.ts +22 -0
  303. package/dist/channels/formatting.d.ts +8 -0
  304. package/dist/channels/index.cjs +13 -2
  305. package/dist/channels/index.d.ts +11 -1
  306. package/dist/channels/index.js +3 -3
  307. package/dist/channels/reply-guidance-processor.d.ts +26 -0
  308. package/dist/channels/reply-mode.d.ts +66 -0
  309. package/dist/channels/reply-reminder-processor.d.ts +23 -0
  310. package/dist/channels/reply-tool.d.ts +43 -0
  311. package/dist/channels/thread-link-processor.d.ts +48 -0
  312. package/dist/channels/thread-lookup.d.ts +16 -0
  313. package/dist/channels/tool-announcement-processor.d.ts +29 -0
  314. package/dist/channels/types.d.ts +30 -3
  315. package/dist/{channels-D7bBM9xD.cjs → channels-Cl-pRrWB.cjs} +122 -1
  316. package/dist/{channels-DSOCNoab.js → channels-DegTNzaq.js} +99 -2
  317. package/dist/coding-agent/index.cjs +1 -1
  318. package/dist/coding-agent/index.js +1 -1
  319. package/dist/datasets/experiment/index.d.ts +1 -1
  320. package/dist/datasets/experiment/item.d.ts +4 -3
  321. package/dist/datasets/experiment/scorer.d.ts +34 -11
  322. package/dist/datasets/index.cjs +3 -2
  323. package/dist/datasets/index.js +3 -3
  324. package/dist/{dist-ByO0vuJJ-BjMue5_p.cjs → dist-CufwpBZM-CwERFaas.cjs} +4 -4
  325. package/dist/{dist-ByO0vuJJ-CCXLBnvJ.js → dist-CufwpBZM-DK14Qe0Z.js} +4 -4
  326. package/dist/docs/SKILL.md +2 -1
  327. package/dist/docs/assets/SOURCE_MAP.json +817 -817
  328. package/dist/docs/references/docs-agents-resumable-streams.md +15 -6
  329. package/dist/docs/references/docs-channels.md +43 -0
  330. package/dist/docs/references/docs-deployment-workers.md +3 -1
  331. package/dist/docs/references/docs-evals-experiments.md +13 -3
  332. package/dist/docs/references/docs-harness-background-tasks.md +4 -4
  333. package/dist/docs/references/docs-harness-durable-agents.md +39 -48
  334. package/dist/docs/references/docs-knowledge-importers.md +1 -1
  335. package/dist/docs/references/docs-mastra-platform-observability-overview.md +1 -1
  336. package/dist/docs/references/docs-sandbox-overview.md +1 -0
  337. package/dist/docs/references/docs-server-pubsub.md +1 -1
  338. package/dist/docs/references/docs-workflows-overview.md +67 -3
  339. package/dist/docs/references/integrations-agentic-ui-assistant-ui.md +2 -0
  340. package/dist/docs/references/integrations-frameworks-angular.md +39 -0
  341. package/dist/docs/references/integrations-frameworks-astro.md +5 -2
  342. package/dist/docs/references/integrations-frameworks-electron.md +40 -0
  343. package/dist/docs/references/integrations-frameworks-next-js.md +5 -2
  344. package/dist/docs/references/integrations-frameworks-nuxt.md +5 -2
  345. package/dist/docs/references/integrations-frameworks-sveltekit.md +5 -2
  346. package/dist/docs/references/integrations-frameworks-vite-react.md +40 -0
  347. package/dist/docs/references/integrations.md +3 -0
  348. package/dist/docs/references/reference-agent-controller-agent-controller-class.md +6 -0
  349. package/dist/docs/references/reference-agents-channels.md +1 -1
  350. package/dist/docs/references/reference-agents-durable-agent.md +5 -3
  351. package/dist/docs/references/reference-agents-generate.md +2 -0
  352. package/dist/docs/references/reference-channels-thread-link.md +67 -0
  353. package/dist/docs/references/reference-configuration.md +1 -1
  354. package/dist/docs/references/reference-core-mastra-class.md +2 -0
  355. package/dist/docs/references/reference-knowledge-knowledge-class.md +1 -1
  356. package/dist/docs/references/reference-knowledge-knowledge-tools.md +11 -5
  357. package/dist/docs/references/reference-pubsub-caching-pubsub.md +2 -2
  358. package/dist/docs/references/reference-pubsub-redis-streams.md +2 -2
  359. package/dist/docs/references/reference-pubsub-valkey-streams.md +2 -2
  360. package/dist/docs/references/reference-workers-overview.md +2 -0
  361. package/dist/docs/references/reference-workflows-workflow-methods-create-run.md +2 -0
  362. package/dist/docs/references/reference-workflows-workflow.md +2 -0
  363. package/dist/docs/references/reference-workspace-factory-sandbox.md +2 -1
  364. package/dist/docs/references/reference.md +2 -0
  365. package/dist/error/index.cjs +2 -1
  366. package/dist/error/index.d.ts +1 -1
  367. package/dist/error/index.js +2 -2
  368. package/dist/error/provider-error.d.ts +2 -1
  369. package/dist/{error-BLwEXqOK.js → error-BC9Au-22.js} +13 -1
  370. package/dist/{error-BdEvO8za.cjs → error-L1V4uUbd.cjs} +18 -0
  371. package/dist/evals/index.cjs +1 -1
  372. package/dist/evals/index.js +1 -1
  373. package/dist/evals/scoreTraces/index.cjs +1 -1
  374. package/dist/evals/scoreTraces/index.js +1 -1
  375. package/dist/events/caching-pubsub.d.ts +28 -0
  376. package/dist/events/index.cjs +4 -1
  377. package/dist/events/index.js +2 -2
  378. package/dist/events/topics.d.ts +55 -9
  379. package/dist/harness/index.cjs +1 -1
  380. package/dist/harness/index.js +1 -1
  381. package/dist/index.cjs +1 -1
  382. package/dist/index.js +1 -1
  383. package/dist/{inmemory-BDD0w8gx.js → inmemory-BK3zLwvM.js} +42 -12
  384. package/dist/{inmemory-fgR8sq-U.cjs → inmemory-Dc86VWGB.cjs} +42 -12
  385. package/dist/knowledge/changes.d.ts +17 -5
  386. package/dist/knowledge/importers/runner.d.ts +6 -0
  387. package/dist/knowledge/index.cjs +78 -16
  388. package/dist/knowledge/index.d.ts +2 -2
  389. package/dist/knowledge/index.js +78 -16
  390. package/dist/knowledge/search-snippet.d.ts +30 -0
  391. package/dist/llm/index.cjs +3 -3
  392. package/dist/llm/index.js +3 -3
  393. package/dist/llm/model/provider-types.generated.d.ts +8175 -8296
  394. package/dist/{llm-BOQR5g0t.cjs → llm-BKxlS9Kk.cjs} +3 -3
  395. package/dist/{llm-DMNEZIV9.js → llm-CMkzIFAk.js} +3 -3
  396. package/dist/loop/index.cjs +2 -2
  397. package/dist/loop/index.js +2 -2
  398. package/dist/{manager-BzNynLwT.js → manager-C-eQXmRq.js} +120 -70
  399. package/dist/{manager-CyCR9IpR.cjs → manager-CasaT35Q.cjs} +125 -69
  400. package/dist/mastra/index.cjs +1 -1
  401. package/dist/mastra/index.js +1 -1
  402. package/dist/{mastra-CqBmnzjM.js → mastra-5EEmN3Ok.js} +28 -18
  403. package/dist/{mastra-D2B01_gg.cjs → mastra-C7Tj4U8c.cjs} +28 -18
  404. package/dist/memory/index.cjs +3 -3
  405. package/dist/memory/index.js +3 -3
  406. package/dist/{message-list-Cj0Sq_JP.cjs → message-list-DfN9mWeN.cjs} +121 -121
  407. package/dist/{message-list-KRbg-TnI.js → message-list-wI71UGxk.js} +1 -1
  408. package/dist/{model-CrXDhcbw.cjs → model-9HA-W0tg.cjs} +1 -1
  409. package/dist/{model-3AeJKHLU.js → model-DCLUL-8a.js} +1 -1
  410. package/dist/{netlify-DTXLQiG1.cjs → netlify-Cq3H-A9I.cjs} +12 -12
  411. package/dist/{netlify-DUPSTzi6.js → netlify-DaWURNSU.js} +11 -11
  412. package/dist/notifications/index.cjs +1 -1
  413. package/dist/notifications/index.js +1 -1
  414. package/dist/observability/index.cjs +1 -0
  415. package/dist/observability/index.d.ts +1 -1
  416. package/dist/observability/index.js +2 -2
  417. package/dist/{output-helpers-CedRCE17.js → output-helpers-CVzhy1Y0.js} +126 -56
  418. package/dist/{output-helpers-1Zu4Vt9C.cjs → output-helpers-DgsH4aTb.cjs} +143 -55
  419. package/dist/processor-provider/index.cjs +1 -1
  420. package/dist/processor-provider/index.js +1 -1
  421. package/dist/processors/index.cjs +2 -2
  422. package/dist/processors/index.js +2 -2
  423. package/dist/processors/runner.d.ts +2 -0
  424. package/dist/{provider-registry-BeB8RQO8.js → provider-registry-DWixjFX7.js} +21915 -22166
  425. package/dist/{provider-registry-B_rC-5aL.cjs → provider-registry-a649fS5r.cjs} +21915 -22166
  426. package/dist/provider-registry.json +22772 -23030
  427. package/dist/{registry-generator-Cv6GnxLG.js → registry-generator-BYJC7p8M.js} +1 -1
  428. package/dist/{registry-generator-DbBoIOby.cjs → registry-generator-BuKC7UKd.cjs} +1 -1
  429. package/dist/{rehydrate-3f-i1Ga2.js → rehydrate-DPhmASM6.js} +2 -2
  430. package/dist/{rehydrate-BWaa2eGN.cjs → rehydrate-DR2_WAz2.cjs} +2 -2
  431. package/dist/relevance/index.cjs +2 -2
  432. package/dist/relevance/index.js +2 -2
  433. package/dist/{run-registry-Bx06ZIN_.js → run-registry-D3X7XvUL.js} +2464 -731
  434. package/dist/{run-registry-Bk6QxNE4.cjs → run-registry-oUNF6szW.cjs} +2584 -785
  435. package/dist/storage/domains/inmemory-db.d.ts +1 -0
  436. package/dist/storage/domains/knowledge/base.d.ts +5 -0
  437. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  438. package/dist/storage/domains/knowledge/pages-inmemory.d.ts +10 -2
  439. package/dist/storage/domains/knowledge/pages.d.ts +30 -0
  440. package/dist/storage/index.cjs +2 -2
  441. package/dist/storage/index.js +2 -2
  442. package/dist/storage/run-fencing.d.ts +5 -0
  443. package/dist/stream/index.cjs +2 -2
  444. package/dist/stream/index.js +2 -2
  445. package/dist/{stream-BIXX67WE.cjs → stream-DQC1vpvl.cjs} +4 -4
  446. package/dist/{stream-DVy0Z-m0.js → stream-DoZ6F41o.js} +4 -4
  447. package/dist/test-utils/llm-mock.cjs +1 -1
  448. package/dist/test-utils/llm-mock.js +1 -1
  449. package/dist/tool-loop-agent/index.cjs +1 -1
  450. package/dist/tool-loop-agent/index.js +1 -1
  451. package/dist/{tool-loop-agent-PSKeNhuT.js → tool-loop-agent-C9YkvDRd.js} +4 -4
  452. package/dist/{tool-loop-agent-DDeKGwtr.cjs → tool-loop-agent-Cy4NDOMS.cjs} +4 -4
  453. package/dist/{utils-BJiQF8Pi.js → utils-9JyiKu5r.js} +1 -1
  454. package/dist/{utils-CAnUlnUm.cjs → utils-Bs2IYyOb.cjs} +1 -1
  455. package/dist/utils.cjs +1 -1
  456. package/dist/utils.js +1 -1
  457. package/dist/{validate-BAVwAgtT.js → validate-8j0phWFV.js} +1 -1
  458. package/dist/{validate-BMNxfs4Z.cjs → validate-BE3mVxVy.cjs} +1 -1
  459. package/dist/vector/index.cjs +2 -2
  460. package/dist/vector/index.js +2 -2
  461. package/dist/worker/index.cjs +1 -1
  462. package/dist/worker/index.js +1 -1
  463. package/dist/{worker-BlvJM_Hu.js → worker-BfWFqSH2.js} +2 -2
  464. package/dist/{worker-CFUKBBCF.cjs → worker-BiK1kfMa.cjs} +2 -2
  465. package/dist/{worker-CVoD3tts.js → worker-DIRdEwih.js} +2 -2
  466. package/dist/{worker-Brwa-HqM.cjs → worker-DwdgU6E9.cjs} +2 -2
  467. package/dist/{workflow-zvQGBMCM.cjs → workflow-CxQMcTbT.cjs} +4 -4
  468. package/dist/{workflow-BSLS7_vB.js → workflow-ni-keg2i.js} +4 -4
  469. package/dist/workflows/builder/index.cjs +1 -1
  470. package/dist/workflows/builder/index.js +1 -1
  471. package/dist/workflows/evented/index.cjs +1 -1
  472. package/dist/workflows/evented/index.js +1 -1
  473. package/dist/workflows/index.cjs +4 -4
  474. package/dist/workflows/index.js +4 -4
  475. package/dist/workflows/run-ownership.d.ts +74 -8
  476. package/dist/workflows/types.d.ts +16 -0
  477. package/dist/workflows/workflow.d.ts +4 -0
  478. package/package.json +5 -5
  479. package/src/llm/model/provider-types.generated.d.ts +8175 -8296
  480. /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/dist/index.d.ts +0 -0
  481. /package/dist/_types/{@ai-sdk_provider-utils@4.0.66 → @ai-sdk_provider-utils@4.0.67}/package.json +0 -0
@@ -18,7 +18,12 @@ Resumable streams don't make the run itself durable. Reconnecting isn't crash re
18
18
  | Plain agent with `durable: false` | Off, including registered agents |
19
19
  | Explicit `createDurableAgent()` wrapper | Always published; pass `cache: false` to the factory to disable the replay cache, not transport history |
20
20
 
21
- A registered agent, durable or not, publishes on `mastra.pubsub` and caches events in `mastra.serverCache`, or an in-memory cache when the server has none. Every `Mastra` instance that shares that PubSub and cache can observe the run. An agent-level `pubsub` takes precedence, except on the evented engine, whose steps always publish on `mastra.pubsub`.
21
+ Mastra resolves the stream transport and replay cache separately:
22
+
23
+ - **Transport:** For the plain loop and the default durable engine, Mastra uses the first configured option: the agent's `durable.pubsub`, the agent's top-level `pubsub`, or `mastra.pubsub`. Evented steps publish on `mastra.pubsub` so workers can publish to the same stream.
24
+ - **Replay cache:** Mastra uses the agent's `durable.cache`, then `mastra.serverCache`, then an in-memory cache. Evented runs use the shared Mastra cache when replay caching is enabled. If the transport is already a `CachingPubSub`, Mastra reuses its cache. Set `durable.cache: false` to skip adding a replay cache without changing the transport or its retained history.
25
+
26
+ For deployments with more than one process, see [PubSub setup for resumable streams](https://mastra.ai/docs/server/pubsub).
22
27
 
23
28
  ## Configure streams
24
29
 
@@ -48,7 +53,9 @@ export const supportAgent = new Agent({
48
53
 
49
54
  `durable: true` turns streams on with these defaults, including for standalone agents.
50
55
 
51
- On a plain `Agent`, `durable` configures resumable streams only. For checkpoint-backed execution, wrap the agent explicitly with `createDurableAgent({ agent })`. To recover in-flight runs after a crash, also configure persistent workflow storage and `recovery: { durableAgents: 'auto' }`. For manual recovery instead, pass a `shouldPersistSnapshot` policy that includes `running` snapshots and call `recoverActiveRuns()` yourself. See [crash recovery](https://mastra.ai/docs/harness/durable-agents) for setup and persistence policies.
56
+ To checkpoint execution as well as publish run frames, set `durable.executionEngine` to `'default'` or `'evented'` on the agent, or inherit the setting from `Mastra`. Without an engine setting, `durable: true` only enables stream publication.
57
+
58
+ To continue an in-flight run after a crash, configure [crash recovery](https://mastra.ai/docs/harness/durable-agents) separately.
52
59
 
53
60
  Configure the wrapper's stream cache and transport through the factory's `cache`, `pubsub`, `shouldCache`, and `cleanupTimeoutMs` options.
54
61
 
@@ -72,15 +79,17 @@ To keep live observation but skip the replay cache, pass `durable: { cache: fals
72
79
 
73
80
  ### How long runs stay available
74
81
 
75
- After a run finishes, the executing process schedules cleanup of its events and ownership record after `cleanupTimeoutMs`. The timer allows the process to exit before cleanup. Shared cache data then remains until expiry or eviction. Redis Streams retains its native topic data until `clearTopic()` succeeds or its idle TTL expires. The transport's default idle TTL is seven days. Configure `streamIdleTtlMs` to change it, or set it to `0` to disable transport expiry. A run parked on a tool approval or suspension isn't cleared by that timer, because resuming it continues on the same topic.
82
+ When a run finishes, the executing process schedules deletion of its events and ownership record after `cleanupTimeoutMs` (30 seconds by default). That's the fast path. Everything is also bounded by idle retention, refreshed on every append, so a process that restarts before the deletion timer fires can't leave a run's state behind indefinitely. A run parked on a tool approval or suspension isn't deleted, because resuming it continues on the same topic.
76
83
 
77
- The cache bounds everything else:
84
+ The retentions that apply:
78
85
 
79
- - Run logs and ownership records ask the cache for a 24-hour TTL. The in-memory cache uses at least this TTL for indexed run logs, unless cache expiry is disabled. Cache entry limits can evict data sooner.
86
+ - A run's replay cache requests a minimum 24-hour lifetime after the last append (`runLogTtlMs` on [`CachingPubSub`](https://mastra.ai/reference/pubsub/caching-pubsub)). Redis and Valkey Streams use a separate 24-hour transport default for run topics. These defaults match the run record's own 24-hour lifetime, deliberately: a run parked on a tool approval appends nothing while it waits, so its retention is never refreshed, and the events must outlive every moment the record still authorizes an `observe()` or resume. For thread streams, `threadStreamLogTtlMs` requests one hour in the cache while the transport independently defaults to one hour, enough for an idle thread's tail to survive a reconnect. Cache TTL overrides leave the transport defaults unchanged, though `streamIdleTtlMs` can shorten them. The replay cache's retention is stamped only when an event is appended. The transport's is also refreshed when a reader subscribes.
87
+ - A run's ownership record keeps a 24-hour lifetime, so a run parked overnight on an approval stays authorizable for observe and resume, and because its events share that lifetime, the approval request is still there to replay. The run log is a delivery buffer and messages live in storage: once both expire, `observe()` returns 404 rather than replaying, and a client fetches the conversation from storage.
88
+ - Topics that don't belong to a single run or thread, such as work queues and application feeds, keep the transport's own idle TTL, seven days by default for [Redis Streams](https://mastra.ai/reference/pubsub/redis-streams) and [Valkey Streams](https://mastra.ai/reference/pubsub/valkey-streams). They need it: a grouped consumer that was offline must still find its backlog. Configure `streamIdleTtlMs` to change it, or set it to `0` to disable transport expiry. Lowering it also lowers the retention on run topics.
80
89
  - The in-memory cache holds 1,000 entries by default. Each run uses several entries (its event log, a counter and its ownership record), so heavy traffic evicts older runs sooner.
81
90
  - The server's observe and abort routes return 404 when a run's ownership record is evicted or expires. Evicted run events can't be replayed.
82
91
 
83
- Use a shared cache such as Redis, sized for your traffic, when runs must stay observable across servers or for long approval waits.
92
+ A run log recreated after its retention lapsed normally numbers above the indices it issued before. An attached observer then keeps receiving the new frames. Treat that as the common case rather than a guarantee: the built-in Redis, Valkey and in-memory caches derive the numbering from a clock, Convex numbers densely instead, and the fallback that detects a restarted log only recognizes one that restarts at zero. An observer attached across a log recreated below its cursor can miss new frames. Reattaching without the old offset can replay the entries still retained in the new log, while reusing that offset can skip them. Storage remains the source of truth for a run's messages. Use a shared cache such as Redis, sized for your traffic, when runs must stay observable across servers or for long approval waits.
84
93
 
85
94
  ## Follow a run
86
95
 
@@ -243,6 +243,49 @@ Tool display, approval prompts, error messages, and typing status are unaffected
243
243
 
244
244
  The channel instructions Mastra adds to the agent's prompt follow this setting: with text hidden, the agent is told that only what it posts with tools reaches the conversation, and that it can skip a message by not posting anything.
245
245
 
246
+ ### Reply mode
247
+
248
+ Set `replyMode: 'tool'` to have the agent post only through a `reply_in_thread` tool. Mastra installs the tool and everything around it:
249
+
250
+ - Reply text and tool calls stay out of the thread. `textDisplay` and `toolDisplay` default to `'hidden'`.
251
+ - The typing status names the agent's current step, for example "is listing repo root", using each tool call's `description` argument.
252
+ - With `streaming: true` on the adapter, `reply_in_thread` streams into the thread while the model writes it. Without it, each reply posts once it's complete.
253
+ - The agent's prompt tells it to post a one-line opener on long work, then the outcome, and to write for people rather than agents.
254
+ - If the agent goes five minutes without posting, it's reminded to post a status.
255
+
256
+ Add [`threadLink`](https://mastra.ai/reference/channels/thread-link) to end the first reply of each new thread with a link to your web UI. A full example:
257
+
258
+ ```typescript
259
+ import { Agent } from '@mastra/core/agent'
260
+ import { createSlackAdapter } from '@chat-adapter/slack'
261
+
262
+ export const yourAgent = new Agent({
263
+ id: 'your-agent',
264
+ name: 'Your Agent',
265
+ instructions: 'You help the team with their work.',
266
+ model: 'openai/gpt-6.1-sol',
267
+ channels: {
268
+ adapters: {
269
+ slack: {
270
+ adapter: createSlackAdapter(),
271
+ streaming: true,
272
+ replyMode: {
273
+ instructions: ['Link tickets as [ABC-123](<ticket url>).'],
274
+ reminderAfterMs: 10 * 60_000,
275
+ },
276
+ threadLink: ({ threadId }) => `https://app.example.com/threads/${threadId}`,
277
+ },
278
+ },
279
+ },
280
+ })
281
+ ```
282
+
283
+ `instructions` adds your own lines to the reply prompt. Pass a function, `({ canReply }) => string[]`, to vary them by whether the run can post. If you set `textDisplay: 'show'`, the agent's text posts directly and gets the same prompt, but no `reply_in_thread` tool. Settings you set on the adapter yourself, such as `toolDisplay`, win over the reply mode defaults.
284
+
285
+ Runs that didn't start from a message, such as a schedule or a web chat on a thread that started in a channel, find the thread from their memory thread and post there too.
286
+
287
+ > **Note:** Reply mode has only been tested with Slack. The typing status is cut to 50 characters to fit Slack's inline status.
288
+
246
289
  ## Runs that don't start from a message
247
290
 
248
291
  A thread that started in a channel can also run from elsewhere, such as a schedule, a Studio prompt, or a signal waking the agent. Those runs get the same channel instructions as a run started by a message. The agent knows its identity in the channel and whether its text replies are posted there. Because the system prompt is identical for both kinds of run, it stays cached.
@@ -60,7 +60,9 @@ Extra scheduler instances add availability, not throughput. Each one polls stora
60
60
 
61
61
  ### Background task worker
62
62
 
63
- Executes agent tool calls marked with `background: { enabled: true }`. When an agent invokes a background tool, the API dispatches the task to this worker instead of blocking the response stream.
63
+ Executes agent tool calls marked with `background: { enabled: true }` without blocking the response stream.
64
+
65
+ A background tool call is bound to the agent run that made it, so it runs on the process that executes the agent loop. An API server with `MASTRA_WORKERS=false` doesn't hand its agents' tool calls to a dedicated background task worker: a durable agent runs the tool inline, and a regular agent returns a dispatch error as the tool result unless you pass `disableBackgroundTasks: true`. See [BackgroundTaskWorker](https://mastra.ai/reference/workers/overview).
64
66
 
65
67
  The background task worker manages concurrency limits, task lifecycle, and result delivery through the PubSub bus.
66
68
 
@@ -244,11 +244,21 @@ await dataset.updateItem({
244
244
 
245
245
  Omitting `scorerIds` from an update preserves its current value. Each item version stores its scorer ID list, including an empty list. Scorer definitions aren't copied into the item version and continue to use their existing registry or Editor behavior.
246
246
 
247
- Mastra resolves each item's scorer IDs before running its target. It checks registered scorers first, then asks the Editor to hydrate a stored scorer. A stale item-level ID produces the `EXPERIMENT_ITEM_SCORER_NOT_FOUND` code for that item. Mastra skips target execution without retrying that item, while the rest of the experiment continues.
247
+ Mastra resolves scorer IDs the same way at every level by checking registered scorers first and then asking the Editor to load a stored scorer, so stored scorers work even in a durable run's worker that never loaded them. Mastra doesn't resolve IDs from lower-priority sources that the precedence rules ignore.
248
248
 
249
- A missing ID in the selected run-level or dataset-level source fails experiment setup. Mastra doesn't resolve IDs from lower-priority sources that the precedence rules ignore.
249
+ An unknown ID in the experiment's `scorers` option rejects `startExperiment()`, `startExperimentAsync()`, or `createExperiment()` with the `EXPERIMENT_SCORER_NOT_FOUND` code before Mastra creates the experiment. The server returns a `400` response for this error.
250
250
 
251
- Workflow step scorers are available only through a run-level categorized `scorers` configuration. Item-level IDs apply to the flat agent, workflow, and trajectory scorer dispatch.
251
+ If an item's scorer can't be found once the experiment is running, that item fails with the `EXPERIMENT_ITEM_SCORER_NOT_FOUND` code. This happens for a stale item-level or dataset-level ID, or for a scorer deleted after the experiment started. Mastra skips target execution without retrying that item, while the rest of the experiment continues.
252
+
253
+ A scorer lookup that fails for another reason, such as unavailable storage, isn't reported as a missing ID. Mastra surfaces the original error instead. Where you see it depends on when the lookup runs:
254
+
255
+ - `startExperiment()` and `createExperiment()` reject when the lookup for the experiment's `scorers` option fails. `startExperiment()` also rejects when the lookup for the dataset's scorers fails.
256
+ - `startExperimentAsync()` rejects when the lookup for the experiment's `scorers` option fails. The other lookups run after the call returns. A failure in one of them marks the experiment `failed`.
257
+ - If a lookup for an item's scorers fails while `startExperiment()` runs items, Mastra marks the experiment `failed`. `startExperiment()` returns a summary with `status: 'failed'` instead of rejecting, and the `experiment.run.finished` event carries the original error when an event observer is configured.
258
+ - In a durable experiment, a failed lookup marks the experiment `failed`.
259
+ - `runExperimentItem()` rejects with the original error and doesn't mark the experiment `failed`. The caller decides whether to retry the item.
260
+
261
+ Workflow step scorers are available only through a run-level categorized `scorers` configuration, and their IDs follow the same lookup and start-time check as the other run-level IDs. Item-level IDs apply to the flat agent, workflow, and trajectory scorer dispatch.
252
262
 
253
263
  ## Control persistence per run
254
264
 
@@ -496,7 +496,7 @@ Every Mastra process with background tasks enabled runs its own manager. You can
496
496
  ### Deployment requirements
497
497
 
498
498
  - Every manager must use the same storage backend, and its `updateTask` must apply the write conditions atomically. Mastra's storage adapters do. In-memory storage is only shared within one process.
499
- - `leaseExpiresAt` is a timestamp written with the owner's clock and compared against the clock of the manager that reads it. Keep server clocks synchronized, for example with Network Time Protocol (NTP), to well under `leaseDurationMs`. If a reader's clock runs ahead by more than the lease, it can recover a task whose owner is still alive. If it runs behind, recovery is delayed. The startup scan recovers a task as soon as its lease has expired by the reader's clock. Follow-up scans wait about one second past the expiry to absorb small differences.
499
+ - `leaseExpiresAt` is a timestamp written with the owner's clock and compared against the clock of the manager that reads it. Keep server clocks synchronized, for example with Network Time Protocol (NTP), to well under `leaseDurationMs`. If a reader's clock runs ahead by more than the lease, it can recover a task whose owner is still alive. If it runs behind, recovery is delayed. The startup scan and the periodic check recover a task as soon as its lease has expired by the reader's clock. Follow-up scans wait about one second past the expiry to absorb small differences.
500
500
  - A longer [`leaseDurationMs`](https://mastra.ai/reference/configuration) delays recovery after a crash. A shorter one adds storage writes and makes it more likely that a stalled owner loses its lease while still running. The default is 30 seconds and the minimum is 3000 ms.
501
501
 
502
502
  ### Lease guarantees and repeated tool calls
@@ -519,17 +519,17 @@ Before a manager runs a task, it claims the task with a conditional write. The w
519
519
 
520
520
  While the task runs, the owner renews the lease every `leaseDurationMs / 3`, with a minimum of one second. Each renewal is conditional on the task still being `running` under the same owner. The task's final writes, such as `completed`, `failed`, `timed_out`, or `suspended`, carry the same condition, so a manager that lost the task can't overwrite the result of the manager that replaced it.
521
521
 
522
- The owner stops renewing when the task completes, fails, or suspends. On shutdown, the manager releases the leases it still holds, so other managers can recover those tasks without waiting for the lease to expire. A lease that isn't released, for example because the process crashed, expires on its own.
522
+ The owner stops renewing when the task completes, fails, or suspends. On shutdown, the manager releases the leases it still holds, so other managers can recover those tasks without waiting for the lease to expire. A running task with `maxRetries: 0` can't run again, so shutdown fails it with `Worker process terminated before task completed`, the same ending as a crash, rather than cancelling it. A lease that isn't released, for example because the process crashed, expires on its own.
523
523
 
524
524
  ### Recover a task from a dead owner
525
525
 
526
526
  A manager treats a `running` task as abandoned only after its lease expires.
527
527
 
528
- When `recoverStaleTasksOnStart` is `true`, the default, each manager that runs tasks scans for abandoned tasks on startup. If the scan finds a lease that hasn't expired yet, the manager scans again shortly after that lease expires, and repeats until no live lease is left. A task that a manager starts after that and then abandons waits for the next startup scan. For each task the scan recovers:
528
+ When `recoverStaleTasksOnStart` is `true`, the default, each manager that runs tasks scans for abandoned tasks on startup. If the scan finds a lease that hasn't expired yet, the manager scans again shortly after that lease expires, and repeats until no live lease is left. After startup, the manager also checks for running tasks with an expired lease every `leaseDurationMs`, so a task whose worker dies later is recovered without a restart. Each check reads up to `globalConcurrency` running tasks (at least 100, at most 1,000), which normally covers all of them, so the task is recovered within about one `leaseDurationMs` after its lease expires. When more tasks are running than that, for example because other servers use a higher `globalConcurrency`, each further page of running tasks adds one `leaseDurationMs`. For each task the scan recovers:
529
529
 
530
530
  - If the task's worker shut down gracefully, it returns to `pending` and is dispatched again without using a retry.
531
531
  - If the worker died and the task's `retryCount` is below `maxRetries`, it uses a retry, returns to `pending`, and is dispatched again.
532
- - Otherwise, it fails with `Worker process terminated before task completed`.
532
+ - Otherwise, it fails with `Worker process terminated before task completed`. The failure fires `task.failed` and `onTaskFailed` like any other failure.
533
533
 
534
534
  Only a crash counts against `maxRetries`, so a task that keeps taking its worker down stops after its retries are used, while a deploy doesn't use one.
535
535
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
10
10
 
11
- A durable agent wraps a regular [`Agent`](https://mastra.ai/docs/agents/overview) so the agentic loop runs inside a workflow. Events flow through [PubSub](https://mastra.ai/docs/server/pubsub), which means a client can disconnect and reconnect without missing chunks. The run state is persisted, so it survives process restarts.
11
+ A durable agent runs the [agentic loop](https://mastra.ai/docs/agents/overview) inside a workflow. Clients can reconnect over [PubSub](https://mastra.ai/docs/server/pubsub) and replay retained stream events. With persistent storage and recovery configured, the agent can continue from a checkpoint after a process restart.
12
12
 
13
13
  ## When to use durable agents
14
14
 
@@ -23,46 +23,42 @@ For short-lived, request-scoped calls where the client stays connected, a regula
23
23
 
24
24
  ## Quickstart
25
25
 
26
- Wrap an existing agent with `createDurableAgent()` from `@mastra/core/agent/durable`:
26
+ Set `durable.executionEngine` to `'default'` on your agent to run it in the current process. This example uses an `OPENAI_API_KEY` for the model:
27
27
 
28
28
  ```typescript
29
29
  import { Agent } from '@mastra/core/agent'
30
- import { createDurableAgent } from '@mastra/core/agent/durable'
31
30
 
32
- const agent = new Agent({
31
+ export const researcher = new Agent({
33
32
  id: 'researcher',
34
33
  name: 'Researcher',
35
34
  instructions: 'You research topics thoroughly.',
36
35
  model: 'openai/gpt-6.1-sol',
36
+ durable: { executionEngine: 'default' },
37
37
  })
38
-
39
- export const durableResearcher = createDurableAgent({ agent })
40
38
  ```
41
39
 
42
- Register the durable agent with Mastra and call `stream()`:
40
+ Register the agent with Mastra and call `stream()`:
43
41
 
44
42
  ```typescript
45
43
  import { Mastra } from '@mastra/core'
46
- import { durableResearcher } from './agents/researcher'
44
+ import { researcher } from './agents/researcher'
47
45
 
48
- const mastra = new Mastra({
49
- agents: { durableResearcher },
46
+ export const mastra = new Mastra({
47
+ agents: { researcher },
50
48
  })
51
49
 
52
- const { output, runId, cleanup } = await durableResearcher.stream(
53
- 'Research quantum computing advances in 2025',
54
- )
50
+ const output = await mastra
51
+ .getAgent('researcher')
52
+ .stream('Research quantum computing advances in 2025')
55
53
 
56
54
  for await (const chunk of output.fullStream) {
57
55
  // Process each chunk as it arrives
58
56
  }
59
-
60
- // Release PubSub subscriptions and clear the run from the registry.
61
- // If you skip this, an automatic cleanup timer fires after the stream ends.
62
- cleanup()
63
57
  ```
64
58
 
65
- The returned `runId` identifies the execution. Pass it to `observe()` to reconnect from a different client. Visit the [DurableAgent reference](https://mastra.ai/reference/agents/durable-agent) for the full configuration and method API.
59
+ The native `stream()` returns the model output directly. Use `output.runId` to [reconnect](#resumable-streams). With a wrapper, `stream()` returns a handle with the model output in `.output`. See the [wrapper example](https://mastra.ai/reference/agents/durable-agent).
60
+
61
+ To continue a run after a process restart, configure persistent storage and [crash recovery](#crash-recovery).
66
62
 
67
63
  ## How it works
68
64
 
@@ -76,32 +72,23 @@ A durable agent adds three layers on top of a regular agent:
76
72
 
77
73
  ## Execution variants
78
74
 
79
- Mastra provides three factory functions that produce durable agents. They differ in how the workflow is executed:
75
+ Choose the engine based on where the agent should run:
80
76
 
81
- | Factory | Package | Best for |
82
- | ---------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
- | `createDurableAgent()` | `@mastra/core` | Local development and single-process servers. You get a stream you can await directly. |
84
- | `createEventedAgent()` | `@mastra/core` | Background execution. The workflow starts without blocking, and you consume chunks through PubSub. Running it on several processes needs a [supported PubSub backend and storage adapter](https://mastra.ai/docs/server/pubsub). |
85
- | `createInngestAgent()` | `@mastra/inngest` | Production deployments. Inngest adds step memoization, retries, and a monitoring dashboard. |
77
+ | Native agent setting | Wrapper equivalent | Best for |
78
+ | ------------------------------------ | -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `durable.executionEngine: 'default'` | `createDurableAgent()` from `@mastra/core/agent/durable` | Local development and single-process servers. You get a stream you can await directly. |
80
+ | `durable.executionEngine: 'evented'` | `createEventedAgent()` from `@mastra/core/agent/durable` | Runs in the background, and you can follow the run through PubSub. It can run in one process or across multiple processes with a [supported PubSub backend and storage adapter](https://mastra.ai/docs/server/pubsub). |
81
+ | No native setting | `createInngestAgent()` from `@mastra/inngest` | On Inngest, with step memoization, retries, and a monitoring dashboard. |
86
82
 
87
- All three return an object you register with `Mastra` the same way as a regular agent. `createDurableAgent()` and `createEventedAgent()` return class instances that extend `Agent`. `createInngestAgent()` returns a Proxy-backed object that forwards `Agent` methods to the underlying agent. When a signal wakes an idle thread, all three start that run with the durable `stream()`. `sendSignal()` and `sendNotificationSignal()` both work this way.
83
+ To set a default for registered native agents, use `durable.executionEngine` on [Mastra](https://mastra.ai/reference/core/mastra-class). An explicit agent setting overrides it. The choice is fixed at registration or first execution. Wrapper factories select their own engine without changing the wrapped agent's selection.
88
84
 
89
- ### In-process with `createDurableAgent()`
85
+ Before switching engines, stop sending new runs to the old engine and let its active runs finish. Resolve suspended runs on the old engine too. Don't rely on the new engine to resume or recover them.
90
86
 
91
- Wrap your agent and call `stream()`. You get a `DurableAgentStreamResult` back in the same process. No external infrastructure is required, so this is the fastest way to get started:
92
-
93
- ```typescript
94
- import { Agent } from '@mastra/core/agent'
95
- import { createDurableAgent } from '@mastra/core/agent/durable'
87
+ Register a wrapper with `Mastra` the same way as a regular agent. The Core wrappers return `Agent` subclasses. `createInngestAgent()` returns a proxy that forwards `Agent` methods to the underlying agent. When `sendSignal()` or `sendNotificationSignal()` wakes an idle thread, the registered agent starts a run with its configured engine.
96
88
 
97
- const agent = new Agent({
98
- id: 'helper',
99
- instructions: 'You are a helpful assistant.',
100
- model: 'openai/gpt-6.1-sol',
101
- })
89
+ ### In-process with `createDurableAgent()`
102
90
 
103
- export const durableHelper = createDurableAgent({ agent })
104
- ```
91
+ For wrapper setup, see [`createDurableAgent()`](https://mastra.ai/reference/agents/durable-agent) in the API reference.
105
92
 
106
93
  ### Fire-and-forget with `createEventedAgent()`
107
94
 
@@ -124,7 +111,9 @@ In one process, an evented agent runs on the default PubSub backend with no extr
124
111
 
125
112
  ### Resumable streams for stored agents
126
113
 
127
- Agents created with [`createStoredAgent()`](https://mastra.ai/reference/client-js/agents) use the `durable` field to configure resumable streams only. The server hydrates a plain `Agent` with stream publishing and replay enabled:
114
+ Stored agents inherit the server's `Mastra.durable.executionEngine` default when registered, unless their `durable` field is `false`. Loading a specific `versionId` of an already registered stored agent creates a separate instance that doesn't inherit the engine default. When no engine default applies, `durable: true` enables resumable streams without checkpointing.
115
+
116
+ Enable the stored agent's `durable` setting with [`createStoredAgent()`](https://mastra.ai/reference/client-js/agents):
128
117
 
129
118
  ```typescript
130
119
  await mastraClient.createStoredAgent({
@@ -136,7 +125,7 @@ await mastraClient.createStoredAgent({
136
125
  })
137
126
  ```
138
127
 
139
- `durable` also accepts `{ cleanupTimeoutMs }`. Cache and pubsub are inherited from the server's `Mastra` instance. Existing stored agents with `durable: true` now load with resumable streams but without durable execution or checkpoint recovery. To retain durable execution, define a code agent wrapped with `createDurableAgent({ agent })` and pass `maxSteps` and snapshot persistence options to the factory.
128
+ `durable` also accepts `{ cleanupTimeoutMs }`. Stored agents inherit the server's replay cache and PubSub transport. To select an engine per agent, use a [code-defined agent](#quickstart).
140
129
 
141
130
  ### Inngest-powered with `createInngestAgent()`
142
131
 
@@ -162,10 +151,10 @@ Visit the [`createInngestAgent()` reference](https://mastra.ai/reference/agents/
162
151
 
163
152
  ## Resumable streams
164
153
 
165
- Durable agents support resumable streams through PubSub and an event cache. When a client disconnects mid-stream, the cache continues storing events. The same client can reconnect by calling `observe()` with the `runId`:
154
+ Durable agents support resumable streams through PubSub and an event cache. When a client disconnects mid-stream, the cache continues storing events. To reconnect, pass the run ID to `observe()` and read the stream from the returned handle's `.output`:
166
155
 
167
156
  ```typescript
168
- const { output } = await durableResearcher.observe(runId)
157
+ const { output } = await mastra.getAgent('researcher').observe(runId)
169
158
 
170
159
  for await (const chunk of output.fullStream) {
171
160
  // Chunks from the run, including any missed while disconnected
@@ -176,12 +165,12 @@ Calling `observe(runId)` without an offset is the supported general reconnect fl
176
165
 
177
166
  The optional `offset` is a run-log position, which chunks report as `chunk.index`. To resume after a dropped connection, pass `index + 1` of the last chunk that has an `index`, or omit `offset` if nothing arrived. This works the same with `stream()` and `observe()`, over HTTP, and in `@mastra/client-js`. See [`observe(runId, options?)`](https://mastra.ai/reference/agents/durable-agent) for which chunks carry no index, structured output, and transport limits.
178
167
 
179
- Replay isn't a permanent execution archive. Events remain available only until [cleanup](#cleanup) clears them or the cache removes them. A workflow snapshot can't reconstruct cleared stream events, and disabling caching prevents historical replay.
168
+ Replay isn't a permanent execution archive. Events remain available only until [cleanup](#cleanup) clears them or the cache removes them. A workflow snapshot can't reconstruct cleared stream events, and disabling the replay cache doesn't disable history retained by a transport such as Redis Streams.
180
169
 
181
170
  Observing doesn't own the run. When the loop ends, or you leave it early with `break`, `return`, or an error, the observer unsubscribes and the run keeps going for anyone else watching it. To stop observing from outside the loop, for example when the client disconnects, call `detach()`:
182
171
 
183
172
  ```typescript
184
- const { output, detach } = await durableResearcher.observe(runId)
173
+ const { output, detach } = await mastra.getAgent('researcher').observe(runId)
185
174
 
186
175
  request.signal.addEventListener('abort', detach, { once: true })
187
176
 
@@ -255,11 +244,11 @@ Background tasks have their own execution lease, stored on each task record, sep
255
244
 
256
245
  ## Cleanup
257
246
 
258
- Every `stream()` and `observe()` call returns a `cleanup` function that tears the run down: it unsubscribes from PubSub, removes the run from the internal registry, and deletes the run's cached events so nobody can replay it afterward.
247
+ Call `cleanup()` from the process that started the run to release its resources and clear its cached stream events. Wrapper `stream()` and `observe()` handles expose `cleanup()`. On native durable stream output, use the optional `cleanup()` method on [`AgentStreamOutput`](https://mastra.ai/reference/agents/durable-agent).
259
248
 
260
249
  When you don't call `cleanup()` yourself, Mastra calls it `cleanupTimeoutMs` after the run finishes, errors, or is aborted. The default is 30 seconds, so completed-run replay is limited to that window unless you configure a different value or call `cleanup()` sooner. Detaching an observer or reaching a plain `idleTimeoutMs` doesn't start this timer. Set `cleanupTimeoutMs: 0` to turn the timer off. The cache's own TTL and eviction still apply.
261
250
 
262
- Call `cleanup()` from the process that started the run. To stop watching a run from `observe()`, use `detach()` or leave the loop instead.
251
+ To stop watching a run from `observe()` without clearing it, call `detach()` or leave the loop.
263
252
 
264
253
  ## Tool approval
265
254
 
@@ -331,7 +320,7 @@ export const mastra = new Mastra({
331
320
  })
332
321
  ```
333
322
 
334
- On startup, this discovers every registered durable agent with runs stuck in `running` status and re-drives them from the last persisted snapshot.
323
+ At boot, Mastra recovers `running` runs for registered durable agents from their last persisted snapshots. If a stored agent loads after boot recovery, follow the [manual recovery](#manual-recovery) steps.
335
324
 
336
325
  Recovery processes up to five agents concurrently, with up to five run waits per agent. Each wait covers both `recover()` setup and settlement of the whole recovered workflow and lasts at most 30 seconds. If it expires, the attempt continues in the background and frees a slot for another run. These limits bound waiting, not the number of live executions. Discovery and overridden custom recovery methods aren't bounded by this budget.
337
326
 
@@ -362,7 +351,9 @@ for (const run of recovered) {
362
351
  await durableAgent.recoverActiveRuns({ runId: 'run-abc-123' })
363
352
  ```
364
353
 
365
- `recoverAllDurableAgents()` returns counts and schedules eligible ownership re-checks itself. `recoverActiveRuns()` returns each run's outcome as `success`, `failed`, or `skipped`, and doesn't re-check skipped runs. A run skipped because another process drives it carries `retryAt`, the time after which its claim lapses unless renewed. A timed-out attempt instead returns `status: 'skipped'` with `reason: 'recovery-timeout'` and no `retryAt`, so Mastra doesn't automatically retry it. Only the `skipped` count includes this attempt; the `recovered`, `succeeded`, and `failed` counts exclude it even if it settles later.
354
+ To recover a stored agent that wasn't registered at boot, first load it with `await mastra.getEditor()?.agent.getById(agentId)` without a `versionId`. Once it loads, call `mastra.recoverAllDurableAgents()`.
355
+
356
+ `recoverActiveRuns()` reports `success`, `failed`, or `skipped` for each run. If a skipped run returns `retryAt`, schedule your own re-check when calling `recoverActiveRuns()` directly. `mastra.recoverAllDurableAgents()` schedules that re-check for you and counts timed-out attempts only as `skipped`.
366
357
 
367
358
  Manual recovery reads the same `running` checkpoints as automatic recovery. For a `DurableAgent` using the default snapshot policy with `recovery.durableAgents` set to `'off'`, in-flight runs are only checkpointed at step boundaries reached after `mastra.shutdown()` starts. A run that crashes before then, or doesn't reach a step boundary during the drain, has no checkpoint, so `listActiveRuns()` and `recoverActiveRuns()` don't find it. See [snapshot persistence](#snapshot-persistence).
368
359
 
@@ -98,7 +98,7 @@ export class HelpDeskImporter extends KnowledgeImporter({
98
98
 
99
99
  `htmlToMarkdown()` stands in for your own conversion. A few things the example relies on:
100
100
 
101
- - **Await every `ctx.items` call.** Items are buffered and sent in batches, so a call can wait for the previous batch to land.
101
+ - **Await every `ctx.items` call.** Items are buffered and sent in batches, so a call can wait for the previous batch to land. A batch is sent when 200 items are waiting, when you call `ctx.state.set()`, when `import` returns, or once the oldest waiting item has waited 30 seconds, so items from a slow source still land during the run. A batch sent on the timer carries only items: the cursor moves only with `ctx.state.set()`. If the run ends early, the next run resends those items from the saved cursor, and writing the same `sourceId` again is safe. If the host can't take a batch (an item with an empty `sourceId`, say), the run fails there and saves no cursor after it, even if you catch the error.
102
102
  - **`ctx.state.set()` saves the cursor with the items before it.** Call it after the items it covers, never before.
103
103
  - **Use `ctx.fetch` and watch `ctx.signal`.** The signal fires when the run is canceled or reaches its time limit. `ctx.fetch` always uses that signal. If you pass your own `signal`, for example `AbortSignal.timeout()`, it's combined with the run's: either one aborts the fetch, so a run that's canceled or out of time never leaves a fetch running. `ctx.fetch` doesn't retry, so handle rate limits and server errors yourself, for example by waiting for the source's `Retry-After` header before trying again.
104
104
  - **Throw `KnowledgeImporterSourceError` with the HTTP status** when the source fails. The run ends with a fixed error code, such as `source_auth_failed` for 401 or 403 and `source_rate_limited` for 429, and your error text stays in your own logs.
@@ -208,7 +208,7 @@ Platform adds these fields and grouping options:
208
208
  | `aggregateTraces()` | Supports `groupBy: ['projectId']` and `countDistinct.projectId`. |
209
209
  | `aggregateSpans()` | Supports `groupBy: ['projectId']`, but not `countDistinct.projectId`. |
210
210
 
211
- Data retention depends on your plan: 15 days for Free, 60 days for Starter, 180 days for Team, and custom retention for Enterprise. See [pricing](https://mastra.ai/pricing) for current plan limits.
211
+ All traces are retained for six months. This retention period is subject to change for all month-to-month plans. See [pricing](https://mastra.ai/pricing) for current plan limits.
212
212
 
213
213
  ### Other observability data
214
214
 
@@ -146,6 +146,7 @@ Use a remote or container sandbox when commands need a stronger boundary from th
146
146
  - [Railway](https://mastra.ai/integrations/sandboxes/railway)
147
147
  - [Fly.io Sprites](https://mastra.ai/integrations/sandboxes/sprites)
148
148
  - [Vercel](https://mastra.ai/integrations/sandboxes/vercel)
149
+ - [WBX Sandbox](https://mastra.ai/integrations/sandboxes/wbx)
149
150
 
150
151
  If Mastra doesn't support your sandbox provider, implement the [sandbox provider interface](https://mastra.ai/reference/workspace/sandbox) to add it.
151
152
 
@@ -107,7 +107,7 @@ export const mastra = new Mastra({
107
107
 
108
108
  ## Evented workflows and agents
109
109
 
110
- Workflows on the [evented execution engine](https://mastra.ai/docs/workflows/scheduled-workflows) and agents created with [`createEventedAgent()`](https://mastra.ai/docs/harness/durable-agents) advance a run one event at a time. Any worker can take the next event, which lets several processes share one run. That only holds when the deployment has both of the following:
110
+ Workflows on the [evented execution engine](https://mastra.ai/docs/workflows/scheduled-workflows) and agents using [evented durable execution](https://mastra.ai/docs/harness/durable-agents) advance a run one event at a time. Any worker can take the next event, which lets several processes share one run. That only holds when the deployment has both of the following:
111
111
 
112
112
  - **A PubSub backend that redelivers unacknowledged events**: When a worker stops in the middle of a step, the backend gives the step's event to another worker.
113
113
  - **A storage adapter with workflow step guards**: The backend can deliver the same event more than once, and the step guard keeps a later delivery from saving the step's result a second time. A step can still run more than once, so [make steps with side effects idempotent](https://mastra.ai/docs/workflows/overview).
@@ -498,9 +498,11 @@ workflow.restartAllActiveWorkflowRuns()
498
498
 
499
499
  Runs restart concurrently, up to `recovery.workflowConcurrency` at a time (default `5`). Set it to `1` in the Mastra config if your runs share side effects that must not run in parallel.
500
500
 
501
- To exclude a workflow from automatic boot-time restarts triggered by `Mastra.restartAllActiveWorkflowRuns()`, set `autoRestartActiveRuns: false` in the workflow's `options`. This is useful for workflows with side effects that must not be re-driven by a blanket restart. Durable agent workflows set this automatically because their recovery is owned by the opt-in `recovery.durableAgents: 'auto'` path.
501
+ To exclude a workflow from automatic boot-time restarts triggered by `Mastra.restartAllActiveWorkflowRuns()`, set `autoRestartActiveRuns: false` in the workflow's `options`. This is useful for workflows with side effects that must not be re-driven by a blanket restart. Such a workflow's runs also hold no storage lease, so their saves aren't refused after another instance restarts them. Durable agent workflows set this automatically because their recovery is owned by the opt-in `recovery.durableAgents: 'auto'` path.
502
502
 
503
- While a run executes, Mastra holds a storage lease on it and renews it in the background. `restart()` refuses to take over a run whose lease hasn't expired: it throws a `WORKFLOW_RESTART_RUN_OWNED` error and the sweep skips the run. The lease is advisory and doesn't fence writes. If a process stops renewing its lease but keeps executing a step, for example because its event loop is blocked for longer than the lease TTL, recovery can run that step a second time. `workflow.restartAllActiveWorkflowRuns()` skips such a run without a recheck, so call it after the lease expires if you need to recover that run. Storage adapters without run-ownership support keep the previous behavior and restart every active run.
503
+ While a run executes, Mastra holds a storage lease on it and renews it in the background. `restart()` refuses to take over a run whose lease hasn't expired: it throws a `WORKFLOW_RESTART_RUN_OWNED` error and the sweep skips the run. `workflow.restartAllActiveWorkflowRuns()` skips such a run without a recheck, so call it after the lease expires if you need to recover that run. Storage adapters without run-ownership support keep the previous behavior and restart every active run.
504
+
505
+ If a process stops renewing its lease but keeps executing, for example because its event loop is blocked for longer than the lease TTL, recovery on another instance can take the run over. From then on, storage refuses the stalled process's saves to the run, and its `start()`, `resume()`, `restart()` or `timeTravel()` call rejects with a `STORAGE_RUN_FENCE_CONFLICT` error. Over HTTP, a request that waits for such a run gets a 409 with that `code`. A run started with `startAsync()` that was already dispatched only logs a warning, and on `stream()`, `resumeStream()` and `timeTravelStream()` the stream closes and its `result` rejects with the same error. The step it was running can still finish, so recovery can run that step a second time. Keep steps idempotent, as described below. To see the run as the instance that took it over drives it, read it with `getWorkflowRunById()`. This applies to default-engine runs that hold a lease, on storage adapters with run-ownership support. Other runs save as before.
504
506
 
505
507
  `mastra.restartAllActiveWorkflowRuns()`, which the server calls on boot, restarts a default-engine run only once it stopped: no instance holds its lease, and neither the run nor its lease changed for `recovery.workflowGraceMs` (2 seconds by default). A run that's still running, or stopped more recently, is left to the [recovery loop](#recovery-loop).
506
508
 
@@ -520,7 +522,7 @@ For tools that agents call, see [make tools safe to repeat](https://mastra.ai/do
520
522
 
521
523
  ### Recovery loop
522
524
 
523
- `mastra.startWorkers()` also starts a recovery loop on an instance that runs the orchestration worker. Every `recovery.workflowScanIntervalMs` (60 seconds by default, give or take a fifth), it restarts the default-engine runs that stopped, by the same rule as `restartAllActiveWorkflowRuns()`. A run whose instance crashed is restarted at the first pass after its lease expired (`MASTRA_AGENT_THREAD_LEASE_TTL_MS`, 15 seconds by default) and `recovery.workflowGraceMs` passed. When a pass finds a run in its grace period, the next pass runs once that period ends, but no sooner than a second later.
525
+ `mastra.startWorkers()` also starts a recovery loop on an instance that runs the orchestration worker. Every `recovery.workflowScanIntervalMs` (60 seconds by default, give or take a fifth), it restarts the default-engine runs that stopped, by the same rule as `restartAllActiveWorkflowRuns()`. A run whose instance crashed is restarted at the first pass after its lease expired (the workflow's `leaseTtlMs`, 15 seconds by default) and `recovery.workflowGraceMs` passed. When a pass finds a run in its grace period, the next pass runs once that period ends, but no sooner than a second later.
524
526
 
525
527
  Instances that share a storage adapter elect one loop leader through a lease row in storage. Only the leader's loop lists runs. The loops of the other instances only try to take its place. The leader keeps the role until its `stopWorkers()` or `shutdown()` hands it back, or until its lease expires after a crash. With `restartAllActiveWorkflowRuns()` at boot, each instance still restarts its own stopped default-engine runs, whichever instance leads. Between boots, the loop recovers only the workflows the leader registers, so instances that register different workflows on one storage get loop recovery for the leader's workflows only and the others' runs at their next boot. A run the loop restarts executes on the leader.
526
528
 
@@ -532,6 +534,68 @@ export const mastra = new Mastra({
532
534
 
533
535
  The loop never restarts evented runs. A broker that redelivers unacknowledged events recovers them, and on other pubsubs `restartAllActiveWorkflowRuns()` restarts them at boot. The loop also leaves workflows that set `autoRestartActiveRuns: false` alone, and an instance that registers no other default-engine workflow never claims the leader row. It doesn't run when `recovery.workflows` is `'off'`, on an instance started with `workers: false` or a `MASTRA_WORKERS` filter without `orchestration`, or on a storage adapter without run-ownership support. A process that calls `restartAllActiveWorkflowRuns()` but never `startWorkers()` runs no loop.
534
536
 
537
+ ### Steps that block the event loop
538
+
539
+ A run's lease is renewed from the event loop of the process that runs it, every third of the lease. A step that blocks the event loop for longer than the lease (15 seconds by default) stops those renewals. Other instances then see the run as stopped: recovery restarts it elsewhere, and storage refuses the blocked process's result. If the step blocks every time, the next instance can lose the run the same way.
540
+
541
+ Keep the event loop free first. Move CPU-heavy or synchronous work to a worker thread, a child process or another service, or split it into chunks that yield between them:
542
+
543
+ ```typescript
544
+ import { Worker } from 'node:worker_threads'
545
+ import { createStep } from '@mastra/core/workflows'
546
+ import { z } from 'zod'
547
+
548
+ export const render = createStep({
549
+ id: 'render',
550
+ inputSchema: z.object({ pages: z.number() }),
551
+ outputSchema: z.object({ pdf: z.string() }),
552
+ execute: async ({ inputData }) =>
553
+ new Promise<{ pdf: string }>((resolve, reject) => {
554
+ const worker = new Worker(new URL('./render-worker.js', import.meta.url), {
555
+ workerData: inputData,
556
+ })
557
+ worker.once('message', resolve)
558
+ worker.once('error', reject)
559
+ }),
560
+ })
561
+ ```
562
+
563
+ The worker does the blocking work and sends the step's output back:
564
+
565
+ ```javascript
566
+ import { parentPort, workerData } from 'node:worker_threads'
567
+
568
+ // Synchronous work here blocks this thread only, not the event loop that renews the lease.
569
+ const pdf = `report with ${workerData.pages} pages`
570
+
571
+ parentPort.postMessage({ pdf })
572
+ ```
573
+
574
+ If the work has to block, split it into several steps that each block for well under half the lease, for example a third of it. On Postgres, two blocks can pass between renewals. Start each blocking step with `await new Promise(resolve => setImmediate(resolve))` too, because stores that don't wait on the network, such as the in-memory store or a local LibSQL file, give the renewal no other chance to run between steps.
575
+
576
+ Raise the lease only when neither is possible. Set `leaseTtlMs` on the workflow, or on one run. This example reuses the `render` step above:
577
+
578
+ ```typescript
579
+ import { createWorkflow } from '@mastra/core/workflows'
580
+ import { z } from 'zod'
581
+ import { render } from './render'
582
+
583
+ const report = createWorkflow({
584
+ id: 'report',
585
+ inputSchema: z.object({ pages: z.number() }),
586
+ outputSchema: z.object({ pdf: z.string() }),
587
+ options: { leaseTtlMs: 60_000 },
588
+ })
589
+ .then(render)
590
+ .commit()
591
+
592
+ const run = await report.createRun({ leaseTtlMs: 120_000 })
593
+ ```
594
+
595
+ A longer lease delays the recovery of an instance that crashed by the same amount. A run's own `leaseTtlMs` isn't saved with the run, so another instance that restarts it uses the workflow's.
596
+
597
+ When a restart takes over a run whose lease lapsed, it logs a warning and doubles the length of that lease, up to 8 times the run's `leaseTtlMs`. Doubling needs a storage adapter that reports when the lease last changed: the in-memory store, `@mastra/pg` and `@mastra/libsql` today. On other adapters with run-ownership support, the restart uses the base length. A process that went a whole lease without renewing, found by its next renewal or when the run ends, logs one warning per stall with how long that took. Either warning means a step can run again on another instance, so keep steps idempotent.
598
+
535
599
  ### Restarting an active workflow run with `restart()`
536
600
 
537
601
  Use `restart()` to restart an active workflow run from the last active step. This will resume execution from the last active step, and the workflow will continue from there.
@@ -149,6 +149,8 @@ Run Mastra as a standalone server and connect your Next.js frontend (with Assist
149
149
 
150
150
  Now, the Assistant UI frontend will send chat requests directly to your running Mastra server.
151
151
 
152
+ > **Note:** This setup doesn't save conversations in [Mastra memory](https://mastra.ai/docs/memory/overview). To save them, send a `memory` object with a `thread` ID for the conversation and a `resource` ID for the user with each request. Visit [Using Mastra Memory](https://mastra.ai/integrations/agentic-ui/ai-sdk-ui) for an example.
153
+
152
154
  6. You're ready to connect the pieces! Ensure both the Mastra server and the Assistant UI frontend are running. Start the Next.js development server:
153
155
 
154
156
  ```bash