@mastra/memory 1.41.2-alpha.2 → 1.41.3-alpha.0

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 (44) hide show
  1. package/dist/docs/SKILL.md +1 -1
  2. package/dist/docs/assets/SOURCE_MAP.json +94 -94
  3. package/dist/docs/references/docs-agents-human-in-the-loop.md +2 -2
  4. package/dist/docs/references/docs-agents-networks.md +1 -1
  5. package/dist/docs/references/docs-guides-context-engineering.md +1 -1
  6. package/dist/docs/references/docs-harness-background-tasks.md +60 -1
  7. package/dist/docs/references/docs-knowledge-overview.md +1 -1
  8. package/dist/docs/references/docs-memory-memory-processors.md +2 -2
  9. package/dist/docs/references/docs-memory-message-history.md +1 -1
  10. package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
  11. package/dist/docs/references/docs-memory-observational-memory.md +5 -5
  12. package/dist/docs/references/docs-memory-semantic-recall.md +10 -4
  13. package/dist/docs/references/docs-memory-working-memory.md +16 -16
  14. package/dist/docs/references/docs-signals-overview.md +1 -1
  15. package/dist/docs/references/integrations-channels-ring.md +6 -6
  16. package/dist/docs/references/integrations-databases-aurora-dsql.md +13 -13
  17. package/dist/docs/references/integrations-databases-dynamodb.md +8 -8
  18. package/dist/docs/references/integrations-databases-elasticsearch.md +6 -6
  19. package/dist/docs/references/integrations-databases-mongodb.md +2 -2
  20. package/dist/docs/references/integrations-databases-oracledb.md +2 -2
  21. package/dist/docs/references/integrations-databases-postgresql.md +14 -14
  22. package/dist/docs/references/integrations-databases-redis.md +7 -7
  23. package/dist/docs/references/integrations-databases-upstash.md +5 -5
  24. package/dist/docs/references/integrations-databases-valkey.md +1 -1
  25. package/dist/docs/references/reference-memory-listThreads.md +1 -1
  26. package/dist/docs/references/reference-memory-observational-memory.md +2 -2
  27. package/dist/docs/references/reference-processors-token-limiter-processor.md +1 -1
  28. package/dist/index.cjs +20 -1
  29. package/dist/index.d.ts +3 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/processors/index.cjs +1 -1
  33. package/dist/processors/index.js +1 -1
  34. package/dist/processors/observational-memory/observer-agent.d.ts +1 -1
  35. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  36. package/dist/{src-Xhctgeae.js → src-CTZXQELy.js} +765 -273
  37. package/dist/src-CTZXQELy.js.map +1 -0
  38. package/dist/{src-BLniLryu.cjs → src-ibq9d-g9.cjs} +763 -270
  39. package/dist/src-ibq9d-g9.cjs.map +1 -0
  40. package/package.json +9 -9
  41. package/dist/src-BLniLryu.cjs.map +0 -1
  42. package/dist/src-Xhctgeae.js.map +0 -1
  43. /package/dist/_types/{@internal_ai-sdk-v4@0.0.96 → @internal_ai-sdk-v4@0.0.98}/dist/index.d.ts +0 -0
  44. /package/dist/_types/{@internal_ai-sdk-v4@0.0.96 → @internal_ai-sdk-v4@0.0.98}/package.json +0 -0
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.41.2-alpha.2"
6
+ version: "1.41.3-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,243 +1,243 @@
1
1
  {
2
- "version": "1.41.2-alpha.2",
2
+ "version": "1.41.3-alpha.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "AUTO_MODEL_BY_PROVIDER": {
6
6
  "types": "dist/processors/observational-memory/auto-model.d.ts",
7
- "implementation": "dist/src-Xhctgeae.js",
8
- "line": 32213
7
+ "implementation": "dist/src-CTZXQELy.js",
8
+ "line": 32705
9
9
  },
10
10
  "Extractor": {
11
11
  "types": "dist/processors/observational-memory/extractor.d.ts",
12
- "implementation": "dist/src-Xhctgeae.js",
13
- "line": 23939
12
+ "implementation": "dist/src-CTZXQELy.js",
13
+ "line": 24432
14
14
  },
15
15
  "ModelByInputTokens": {
16
16
  "types": "dist/processors/observational-memory/model-by-input-tokens.d.ts",
17
- "implementation": "dist/src-Xhctgeae.js",
18
- "line": 31996
17
+ "implementation": "dist/src-CTZXQELy.js",
18
+ "line": 32488
19
19
  },
20
20
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
21
21
  "types": "dist/processors/observational-memory/constants.d.ts",
22
- "implementation": "dist/src-Xhctgeae.js",
23
- "line": 23675
22
+ "implementation": "dist/src-CTZXQELy.js",
23
+ "line": 24168
24
24
  },
25
25
  "OBSERVATION_CONTEXT_INSTRUCTIONS": {
26
26
  "types": "dist/processors/observational-memory/constants.d.ts",
27
- "implementation": "dist/src-Xhctgeae.js",
28
- "line": 23736
27
+ "implementation": "dist/src-CTZXQELy.js",
28
+ "line": 24229
29
29
  },
30
30
  "OBSERVATION_CONTEXT_PROMPT": {
31
31
  "types": "dist/processors/observational-memory/constants.d.ts",
32
- "implementation": "dist/src-Xhctgeae.js",
33
- "line": 23718
32
+ "implementation": "dist/src-CTZXQELy.js",
33
+ "line": 24211
34
34
  },
35
35
  "OBSERVATION_CONTEXT_PROMPT_THREAD": {
36
36
  "types": "dist/processors/observational-memory/constants.d.ts",
37
- "implementation": "dist/src-Xhctgeae.js",
38
- "line": 23723
37
+ "implementation": "dist/src-CTZXQELy.js",
38
+ "line": 24216
39
39
  },
40
40
  "OBSERVATION_CONTINUATION_HINT": {
41
41
  "types": "dist/processors/observational-memory/constants.d.ts",
42
- "implementation": "dist/src-Xhctgeae.js",
43
- "line": 23705
42
+ "implementation": "dist/src-CTZXQELy.js",
43
+ "line": 24198
44
44
  },
45
45
  "OBSERVER_SYSTEM_PROMPT": {
46
46
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
47
- "implementation": "dist/src-Xhctgeae.js",
48
- "line": 26300
47
+ "implementation": "dist/src-CTZXQELy.js",
48
+ "line": 26793
49
49
  },
50
50
  "ObservationalMemory": {
51
51
  "types": "dist/processors/observational-memory/observational-memory.d.ts",
52
- "implementation": "dist/src-Xhctgeae.js",
53
- "line": 37021
52
+ "implementation": "dist/src-CTZXQELy.js",
53
+ "line": 37513
54
54
  },
55
55
  "ObservationalMemoryProcessor": {
56
56
  "types": "dist/processors/observational-memory/processor.d.ts",
57
- "implementation": "dist/src-Xhctgeae.js",
58
- "line": 39769
57
+ "implementation": "dist/src-CTZXQELy.js",
58
+ "line": 40261
59
59
  },
60
60
  "TokenCounter": {
61
61
  "types": "dist/processors/observational-memory/token-counter.d.ts",
62
- "implementation": "dist/src-Xhctgeae.js",
63
- "line": 28818
62
+ "implementation": "dist/src-CTZXQELy.js",
63
+ "line": 29310
64
64
  },
65
65
  "WorkingMemoryExtractor": {
66
66
  "types": "dist/processors/observational-memory/working-memory-extractor.d.ts",
67
- "implementation": "dist/src-Xhctgeae.js",
68
- "line": 29837
67
+ "implementation": "dist/src-CTZXQELy.js",
68
+ "line": 30329
69
69
  },
70
70
  "buildObserverPrompt": {
71
71
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
72
- "implementation": "dist/src-Xhctgeae.js",
73
- "line": 26984
72
+ "implementation": "dist/src-CTZXQELy.js",
73
+ "line": 27477
74
74
  },
75
75
  "buildObserverSystemPrompt": {
76
76
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
77
- "implementation": "dist/src-Xhctgeae.js",
78
- "line": 26194
77
+ "implementation": "dist/src-CTZXQELy.js",
78
+ "line": 26687
79
79
  },
80
80
  "combineObservationGroupRanges": {
81
81
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
82
- "implementation": "dist/src-Xhctgeae.js",
83
- "line": 30316
82
+ "implementation": "dist/src-CTZXQELy.js",
83
+ "line": 30808
84
84
  },
85
85
  "deriveObservationGroupProvenance": {
86
86
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
87
- "implementation": "dist/src-Xhctgeae.js",
88
- "line": 30360
87
+ "implementation": "dist/src-CTZXQELy.js",
88
+ "line": 30852
89
89
  },
90
90
  "extractCurrentTask": {
91
91
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
92
- "implementation": "dist/src-Xhctgeae.js",
93
- "line": 27297
92
+ "implementation": "dist/src-CTZXQELy.js",
93
+ "line": 27790
94
94
  },
95
95
  "formatMessagesForObserver": {
96
96
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
97
- "implementation": "dist/src-Xhctgeae.js",
98
- "line": 26735
97
+ "implementation": "dist/src-CTZXQELy.js",
98
+ "line": 27228
99
99
  },
100
100
  "getObservationContextPrompt": {
101
101
  "types": "dist/processors/observational-memory/constants.d.ts",
102
- "implementation": "dist/src-Xhctgeae.js",
103
- "line": 23729
102
+ "implementation": "dist/src-CTZXQELy.js",
103
+ "line": 24222
104
104
  },
105
105
  "getObservationsAsOf": {
106
106
  "types": "dist/processors/observational-memory/observation-utils.d.ts",
107
- "implementation": "dist/src-Xhctgeae.js",
108
- "line": 40109
107
+ "implementation": "dist/src-CTZXQELy.js",
108
+ "line": 40601
109
109
  },
110
110
  "hasCurrentTaskSection": {
111
111
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
112
- "implementation": "dist/src-Xhctgeae.js",
113
- "line": 27285
112
+ "implementation": "dist/src-CTZXQELy.js",
113
+ "line": 27778
114
114
  },
115
115
  "injectAnchorIds": {
116
116
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
117
- "implementation": "dist/src-Xhctgeae.js",
118
- "line": 24916
117
+ "implementation": "dist/src-CTZXQELy.js",
118
+ "line": 25409
119
119
  },
120
120
  "optimizeObservationsForContext": {
121
121
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
122
- "implementation": "dist/src-Xhctgeae.js",
123
- "line": 27318
122
+ "implementation": "dist/src-CTZXQELy.js",
123
+ "line": 27811
124
124
  },
125
125
  "parseAnchorId": {
126
126
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
127
- "implementation": "dist/src-Xhctgeae.js",
128
- "line": 24900
127
+ "implementation": "dist/src-CTZXQELy.js",
128
+ "line": 25393
129
129
  },
130
130
  "parseObservationGroups": {
131
131
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
132
- "implementation": "dist/src-Xhctgeae.js",
133
- "line": 30271
132
+ "implementation": "dist/src-CTZXQELy.js",
133
+ "line": 30763
134
134
  },
135
135
  "parseObserverOutput": {
136
136
  "types": "dist/processors/observational-memory/observer-agent.d.ts",
137
- "implementation": "dist/src-Xhctgeae.js",
138
- "line": 26995
137
+ "implementation": "dist/src-CTZXQELy.js",
138
+ "line": 27488
139
139
  },
140
140
  "reconcileObservationGroupsFromReflection": {
141
141
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
142
- "implementation": "dist/src-Xhctgeae.js",
143
- "line": 30379
142
+ "implementation": "dist/src-CTZXQELy.js",
143
+ "line": 30871
144
144
  },
145
145
  "renderObservationGroupsForReflection": {
146
146
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
147
- "implementation": "dist/src-Xhctgeae.js",
148
- "line": 30345
147
+ "implementation": "dist/src-CTZXQELy.js",
148
+ "line": 30837
149
149
  },
150
150
  "resolveAutoModelId": {
151
151
  "types": "dist/processors/observational-memory/auto-model.d.ts",
152
- "implementation": "dist/src-Xhctgeae.js",
153
- "line": 32233
152
+ "implementation": "dist/src-CTZXQELy.js",
153
+ "line": 32725
154
154
  },
155
155
  "stripEphemeralAnchorIds": {
156
156
  "types": "dist/processors/observational-memory/anchor-ids.d.ts",
157
- "implementation": "dist/src-Xhctgeae.js",
158
- "line": 24939
157
+ "implementation": "dist/src-CTZXQELy.js",
158
+ "line": 25432
159
159
  },
160
160
  "stripObservationGroups": {
161
161
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
162
- "implementation": "dist/src-Xhctgeae.js",
163
- "line": 30288
162
+ "implementation": "dist/src-CTZXQELy.js",
163
+ "line": 30780
164
164
  },
165
165
  "summarizeConversation": {
166
166
  "types": "dist/processors/observational-memory/summarize.d.ts",
167
- "implementation": "dist/src-Xhctgeae.js",
168
- "line": 29449
167
+ "implementation": "dist/src-CTZXQELy.js",
168
+ "line": 29941
169
169
  },
170
170
  "wrapInObservationGroup": {
171
171
  "types": "dist/processors/observational-memory/observation-groups.d.ts",
172
- "implementation": "dist/src-Xhctgeae.js",
173
- "line": 30242
172
+ "implementation": "dist/src-CTZXQELy.js",
173
+ "line": 30734
174
174
  },
175
175
  "KnowledgeSemanticIndexCoordinator": {
176
176
  "types": "dist/removed-subconscious.d.ts",
177
- "implementation": "dist/src-Xhctgeae.js",
178
- "line": 29884
177
+ "implementation": "dist/src-CTZXQELy.js",
178
+ "line": 30376
179
179
  },
180
180
  "Memory": {
181
181
  "types": "dist/index.d.ts",
182
- "implementation": "dist/src-Xhctgeae.js",
183
- "line": 40320
182
+ "implementation": "dist/src-CTZXQELy.js",
183
+ "line": 40812
184
184
  },
185
185
  "SUMMARIZE_THREAD_DEFAULTS": {
186
186
  "types": "dist/processors/observational-memory/summarize.d.ts",
187
- "implementation": "dist/src-Xhctgeae.js",
188
- "line": 29405
187
+ "implementation": "dist/src-CTZXQELy.js",
188
+ "line": 29897
189
189
  },
190
190
  "StaleKnowledgeSemanticIndexError": {
191
191
  "types": "dist/removed-subconscious.d.ts",
192
- "implementation": "dist/src-Xhctgeae.js",
193
- "line": 29890
192
+ "implementation": "dist/src-CTZXQELy.js",
193
+ "line": 30382
194
194
  },
195
195
  "Subconscious": {
196
196
  "types": "dist/removed-subconscious.d.ts",
197
- "implementation": "dist/src-Xhctgeae.js",
198
- "line": 29878
197
+ "implementation": "dist/src-CTZXQELy.js",
198
+ "line": 30370
199
199
  },
200
200
  "WORKING_MEMORY_STATE_ID": {
201
201
  "types": "dist/processors/working-memory-state/processor.d.ts",
202
- "implementation": "dist/src-Xhctgeae.js",
203
- "line": 32042
202
+ "implementation": "dist/src-CTZXQELy.js",
203
+ "line": 32534
204
204
  },
205
205
  "WORKING_MEMORY_STATE_PROCESSOR_ID": {
206
206
  "types": "dist/processors/working-memory-state/processor.d.ts",
207
- "implementation": "dist/src-Xhctgeae.js",
208
- "line": 32043
207
+ "implementation": "dist/src-CTZXQELy.js",
208
+ "line": 32535
209
209
  },
210
210
  "WorkingMemoryStateProcessor": {
211
211
  "types": "dist/processors/working-memory-state/processor.d.ts",
212
- "implementation": "dist/src-Xhctgeae.js",
213
- "line": 32044
212
+ "implementation": "dist/src-CTZXQELy.js",
213
+ "line": 32536
214
214
  },
215
215
  "deepMergeWorkingMemory": {
216
216
  "types": "dist/tools/working-memory.d.ts",
217
- "implementation": "dist/src-Xhctgeae.js",
218
- "line": 29528
217
+ "implementation": "dist/src-CTZXQELy.js",
218
+ "line": 30020
219
219
  },
220
220
  "extractWorkingMemoryContent": {
221
221
  "types": "dist/index.d.ts",
222
- "implementation": "dist/src-Xhctgeae.js",
223
- "line": 40174
222
+ "implementation": "dist/src-CTZXQELy.js",
223
+ "line": 40666
224
224
  },
225
225
  "extractWorkingMemoryTags": {
226
226
  "types": "dist/index.d.ts",
227
- "implementation": "dist/src-Xhctgeae.js",
228
- "line": 40142
227
+ "implementation": "dist/src-CTZXQELy.js",
228
+ "line": 40634
229
229
  },
230
230
  "removeWorkingMemoryTags": {
231
231
  "types": "dist/index.d.ts",
232
- "implementation": "dist/src-Xhctgeae.js",
233
- "line": 40155
232
+ "implementation": "dist/src-CTZXQELy.js",
233
+ "line": 40647
234
234
  }
235
235
  },
236
236
  "modules": {
237
237
  "processors": {
238
238
  "index": "dist/processors/index.js",
239
239
  "chunks": [
240
- "src-Xhctgeae.js"
240
+ "src-CTZXQELy.js"
241
241
  ]
242
242
  }
243
243
  }
@@ -94,7 +94,7 @@ for await (const chunk of stream.fullStream) {
94
94
 
95
95
  #### Explaining a decline
96
96
 
97
- `declineToolCall()`, `declineToolCallGenerate()`, and `declineNetworkToolCall()` accept an optional `reason`. The reason is returned to the model in place of the tool result, so the model can adjust instead of retrying blindly. It's also stored on the tool call's `approval` metadata, so it's still there when the conversation is recalled.
97
+ `declineToolCall()`, `declineToolCallGenerate()`, and `declineNetworkToolCall()` accept an optional `reason`. The reason is returned to the model in place of the tool result, so the model can adjust instead of retrying the same way. It's also stored on the tool call's `approval` metadata, so it's still there when the conversation is recalled.
98
98
 
99
99
  ```typescript
100
100
  const declined = await agent.declineToolCall({
@@ -162,7 +162,7 @@ The runtime then combines that result with the tool's `requireApproval` setting.
162
162
 
163
163
  For sensitive tools, bind the approval to the exact tool name and arguments that were shown to the reviewer. If those arguments drift before execution, the tool shouldn't run under the old approval.
164
164
 
165
- The `tool-call-approval` chunk already includes `toolName`, `toolCallId`, and `args`. You can fingerprint those fields when the approval request is shown. The example below uses a JSON string as the fingerprint, but in production you should use a stable hash of the tool name and arguments:
165
+ The `tool-call-approval` chunk already includes `toolName`, `toolCallId`, and `args`. You can fingerprint those fields when the approval request is shown. The example below uses a JSON string as the fingerprint, but in production, use a stable hash of the tool name and arguments:
166
166
 
167
167
  ```typescript
168
168
  import { Agent } from '@mastra/core/agent'
@@ -159,7 +159,7 @@ for await (const chunk of resumedStream) {
159
159
 
160
160
  ### Automatic resumption
161
161
 
162
- Set `autoResumeSuspendedTools` to `true` so the network resumes suspended primitives based on the user's next message. This creates a conversational flow where users provide the required information naturally.
162
+ Set `autoResumeSuspendedTools` to `true` so the network resumes suspended primitives based on the user's next message. This creates a conversational flow where users provide the required information in conversation.
163
163
 
164
164
  ```typescript
165
165
  const stream = await routingAgent.network('Delete the old records', {
@@ -266,7 +266,7 @@ If you've used Claude Code, you may have seen compaction happen during a long se
266
266
 
267
267
  Compaction waits until a conversation reaches a token threshold. It then summarizes the transcript and replaces earlier messages. It's a blunt fallback. The compaction turn adds latency, and a single summary has to represent everything that came before. Repeated summaries can flatten chronology or lose details that later become important.
268
268
 
269
- Prefer [Observational Memory](#observational-memory) for long-running conversations. It can process history asynchronously in the background while preserving temporal context. Reflection revisits accumulated memories and naturally prunes details that no longer matter. Mastra doesn't provide compaction out of the box, though you could implement it with a custom [processor](https://mastra.ai/docs/agents/processors).
269
+ Prefer [Observational Memory](#observational-memory) for long-running conversations. It can process history asynchronously in the background while preserving temporal context. Reflection revisits accumulated memories and prunes details that no longer matter. Mastra doesn't provide compaction out of the box, though you could implement it with a custom [processor](https://mastra.ai/docs/agents/processors).
270
270
 
271
271
  ### Processors
272
272
 
@@ -16,7 +16,7 @@ Use background tasks when a tool call may take long enough that the user shouldn
16
16
  - Tool calls that hit slow external services, queues, or large data jobs.
17
17
  - Workflows triggered from a tool call that may take minutes to complete.
18
18
 
19
- For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
19
+ For tool calls that return fast, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
20
20
 
21
21
  > **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
22
22
 
@@ -341,6 +341,12 @@ await mastra.backgroundTaskManager?.resume(taskId, {
341
341
 
342
342
  On the resumed run, `context.agent.suspendPayload` holds the `data` the tool suspended with. Use it to tell which request an answer belongs to without encoding that in `resumeData`.
343
343
 
344
+ ### Suspend after a durable agent's run finished
345
+
346
+ On a [durable agent](https://mastra.ai/docs/harness/durable-agents), a background tool can call `suspend()` after the agent has replied and its run has finished. The task is marked `suspended` and resumes as usual when the storage adapter supports [run fencing](https://mastra.ai/docs/harness/durable-agents), for example `InMemoryStore`, `@mastra/libsql`, or `@mastra/pg`. These adapters record each claim on the run, so Mastra can check that no other execution claimed the run in the meantime.
347
+
348
+ The task still fails with a storage adapter that lacks run fencing, because run ownership is then only a PubSub lease, and a released lease can't show whether another execution claimed and finished the run since. On an agent from `createEventedAgent()`, the task also fails when an approval for another tool call resumed the run in the same turn, because the resume's claim counts as another execution.
349
+
344
350
  ### Answer a suspended task from a client
345
351
 
346
352
  While an agent's background tool call is suspended, the assistant message that holds the call records the open request under `metadata.suspendedTools[toolCallId]`. The entry carries `toolName`, `args`, `suspendPayload`, `taskId`, `runId`, and `suspendedAt`, so a chat that reloads the thread can still show the request. The entry is removed when the task resumes or is cancelled.
@@ -483,6 +489,59 @@ const { tasks, total } = await mastra.backgroundTaskManager?.listTasks({
483
489
 
484
490
  These read from storage rather than the pubsub stream, so they're suitable for paginated lists and detail views.
485
491
 
492
+ ## Execution ownership and recovery
493
+
494
+ Every Mastra process with background tasks enabled runs its own manager. You can run several processes or replicas against the same storage backend. The managers coordinate through an execution lease stored on each task record. A lease is a time-limited claim on a task that its owner must keep renewing. When the owner stops renewing it, another manager can take the task over.
495
+
496
+ ### Deployment requirements
497
+
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.
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
+
502
+ ### Lease guarantees and repeated tool calls
503
+
504
+ The lease guarantees that at most one manager can commit a task's state at a time. The tool itself can still run more than once when:
505
+
506
+ - The owner stalls, for example because its event loop is blocked or it can't reach storage, for longer than the lease. Another manager recovers the task while the first execution is still running.
507
+ - The owner crashes after the tool has acted on an external system but before the result is saved. The recovered task runs the tool again.
508
+ - A durable agent restarts the task with `restart()` while the previous execution is still running.
509
+
510
+ Make tools that change external systems safe to repeat, for example by passing the tool call ID as an idempotency key. See [make tools safe to repeat](https://mastra.ai/docs/harness/durable-agents).
511
+
512
+ A resume interrupted by shutdown is the one exception to the single-committer guarantee. It restores the previous `suspended` state with a write that checks only that the task is `running`, and that write can overwrite a manager that took the task over in the meantime.
513
+
514
+ ### Claim and renew a lease
515
+
516
+ Each manager gets a random owner ID when it's created. A restarted process gets a new ID and counts as a new owner.
517
+
518
+ Before a manager runs a task, it claims the task with a conditional write. The write sets the status to `running`, records the manager's `ownerId`, and sets `leaseExpiresAt` to the current time plus `leaseDurationMs`. It only applies if the task still has the status, owner, and lease that the manager last read. When two managers race for the same task, one claim succeeds and the other manager skips the task without running it.
519
+
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
+
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.
523
+
524
+ ### Recover a task from a dead owner
525
+
526
+ A manager treats a `running` task as abandoned only after its lease expires.
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:
529
+
530
+ - If the task has `maxRetries` above `0`, it returns to `pending` and is dispatched again.
531
+ - Otherwise, it fails with `Worker process terminated before task completed`.
532
+
533
+ The recovery write is conditional on the owner and lease that the scan read, so only one manager recovers each task.
534
+
535
+ If the pubsub redelivers the unacknowledged dispatch of an abandoned task, the redelivery claims the task once its lease expires and runs it again, even when `maxRetries` is `0`.
536
+
537
+ The manager that runs the recovered task needs an executor for it. See the known limitations under [non-agent owners](#non-agent-owners).
538
+
539
+ `manager.restart(taskId)` is an explicit takeover. It claims a `running` task even while another manager holds a live lease. Durable agents use it when a redelivered step finds the task for its tool call. The task's results then reach the new stream. A restart on the manager that already runs the task doesn't stop the earlier execution. Both executions share an owner ID, and the earlier one can commit first.
540
+
541
+ ### Stop work after losing a lease
542
+
543
+ When a lease renewal fails because the task is now owned by another manager or was cancelled, the previous owner aborts the `abortSignal` passed to the tool. After a takeover, `abortSignal.reason` is an error with the message `Background task execution ownership was taken over by another worker`. The abort is best effort. If the manager can't read the task at that point, it doesn't retry the abort. The previous owner normally notices at its next renewal. A stalled event loop or slow storage can delay that renewal. A tool that ignores `abortSignal` keeps running until it returns, but its result is rejected.
544
+
486
545
  ## Non-agent owners
487
546
 
488
547
  Code other than agents can run tasks through the manager. For example, an MCP server can run long tool calls as background tasks. The task's `agentId` is its owner key, and agent streams, `untilIdle`, and the end-of-step wait only see tasks whose `agentId` matches the agent. Use a namespaced owner key such as `mcp-server:<serverId>` so it can't collide with a real agent ID. Mastra doesn't enforce this.
@@ -8,7 +8,7 @@
8
8
 
9
9
  Knowledge gives agents a shared, organized place for information that lives outside any one conversation: policies, product docs, conventions, runbooks and what other agents have learned. Agents search, read and write it with tools. Pages you pin reach the agent's context through [signals](https://mastra.ai/docs/signals/overview) and stay current while it runs.
10
10
 
11
- > **Alpha:** Knowledge is in alpha. Its API may change between releases. Access is checked on every tool call, but the alpha doesn't guarantee isolation between scopes yet. Don't store anything in Knowledge that must never reach another customer or user. Knowledge also has no built-in importers or retention yet.
11
+ > **Alpha:** Knowledge is in alpha. Its API may change between releases. Each scope's data is kept separate, but an agent with access to more than one scope can leak content between them. Give each agent only the scopes it needs, as [Keep scopes apart](https://mastra.ai/docs/knowledge/scopes-and-access) explains. Knowledge has no built-in importers yet, but you can [write content through its API](https://mastra.ai/docs/knowledge/load-your-content), and Mastra Platform offers importers. Knowledge can't expire old pages yet.
12
12
 
13
13
  ## What Knowledge is
14
14
 
@@ -209,7 +209,7 @@ const agent = new Agent({
209
209
 
210
210
  Understanding the execution order is important when combining guardrails with memory:
211
211
 
212
- ### Input Processors
212
+ ### Input processors
213
213
 
214
214
  ```text
215
215
  [Memory Processors] → [Your inputProcessors]
@@ -220,7 +220,7 @@ Understanding the execution order is important when combining guardrails with me
220
220
 
221
221
  As a result, memory loads message history before your processors can validate or filter the input.
222
222
 
223
- ### Output Processors
223
+ ### Output processors
224
224
 
225
225
  ```text
226
226
  [Your outputProcessors] → [Memory Processors]
@@ -404,7 +404,7 @@ Message queries return `MastraDBMessage[]` format. To display messages in a fron
404
404
 
405
405
  ## Thread cloning
406
406
 
407
- Thread cloning creates a copy of an existing thread with its messages. This is useful for branching conversations or creating checkpoints before a potentially destructive operation, or alternatively testing variations of a conversation.
407
+ Thread cloning creates a copy of an existing thread with its messages. This is useful for branching conversations or creating checkpoints before a destructive operation, or alternatively testing variations of a conversation.
408
408
 
409
409
  ```typescript
410
410
  const { thread, clonedMessages } = await memory.cloneThread({
@@ -108,7 +108,7 @@ Pick the memory layer by how long the conversation needs to remember each partic
108
108
 
109
109
  `lastMessages` brings earlier messages back into context with their `<user>` attributes, so attribution survives across turns. The agent example above uses this setup.
110
110
 
111
- ### With Observational Memory
111
+ ### With observational Memory
112
112
 
113
113
  [Observational Memory](https://mastra.ai/docs/memory/observational-memory) (OM) keeps a long shared thread inside the context window by replacing older messages with observations. Enable it on the same `Memory`:
114
114
 
@@ -38,7 +38,7 @@ yarn add @mastra/memory@latest @mastra/libsql@latest
38
38
  bun add @mastra/memory@latest @mastra/libsql@latest
39
39
  ```
40
40
 
41
- OM needs storage that supports it (`@mastra/libsql`, `@mastra/pg`, `@mastra/mysql`, `@mastra/mongodb`, `@mastra/convex` or `@mastra/oracledb`), a thread for every call, and `observationalMemory: true`. This script stores memory in a local LibSQL file and calls the agent twice on one thread:
41
+ OM needs storage that supports it (`@mastra/libsql`, `@mastra/pg`, `@mastra/mysql`, `@mastra/mongodb`, `@mastra/convex`, `@mastra/oracledb` or `@mastra/mssql`), a thread for every call, and `observationalMemory: true`. This script stores memory in a local LibSQL file and calls the agent twice on one thread:
42
42
 
43
43
  ```typescript
44
44
  import { Agent } from '@mastra/core/agent'
@@ -176,9 +176,9 @@ const memory = new Memory({
176
176
  })
177
177
  ```
178
178
 
179
- Use a model with a large context window (128,000 tokens or more) that's fast enough to run in the background. Mastra has tested `google/gemini-2.5-flash`, `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5` and `deepseek/deepseek-flash`.
179
+ Use a model with a large context window (128,000 tokens or more) that's fast enough to run in the background. Mastra has tested `google/gemini-2.5-flash`, `openai/gpt-6-luna`, `anthropic/claude-haiku-5.5` and `deepseek/deepseek-flash`.
180
180
 
181
- To use a different model per role, set `observation.model` and `reflection.model` instead, and leave the top-level `model` out. Setting both throws. Some models keep so much detail that their reflections can stay above the threshold; in testing, `google/gemini-2.5-flash` did this. A common split uses a detail-preserving model as the Observer and one that condenses more readily, such as `deepseek/deepseek-flash`, as the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
181
+ To use a different model per role, set `observation.model` and `reflection.model` instead, and leave the top-level `model` out. Setting both throws. Some models keep so much detail that their reflections can stay above the threshold; in testing, `google/gemini-2.5-flash` did this. A common split uses a detail-preserving model as the Observer and one that condenses more aggressively, such as `deepseek/deepseek-flash`, as the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
182
182
 
183
183
  ### Tune automatic selection
184
184
 
@@ -239,7 +239,7 @@ const memory = new Memory({
239
239
 
240
240
  Each tier needs a concrete model ID, not `'auto'`. Each `upTo` key is an inclusive upper bound. A call larger than the biggest key throws, so make the last tier cover the largest input you expect.
241
241
 
242
- ### Attachments and text-only Observers
242
+ ### Attachments and text-only observers
243
243
 
244
244
  By default the Observer receives images and PDFs (`observation.observeAttachments: ['image/*', 'application/pdf']`). Other attachments are left out, and their placeholders stay in the transcript. Change it when your Observer model handles more or less:
245
245
 
@@ -265,7 +265,7 @@ The same filter applies to images and files inside tool results. Attachments the
265
265
 
266
266
  ## Cost and latency
267
267
 
268
- Each observation and reflection is a model call. With the defaults, a thread costs one Observer call for roughly every 6,000 tokens of new messages, and one Reflector call each time the log reaches 40,000 tokens. In return, every main-agent call reads a context of at most a few tens of thousands of tokens instead of the whole thread. The observation prefix changes rarely, so prompt caching keeps working: users generally see 97 to 99% prompt cache hit rates with OM.
268
+ Each observation and reflection is a model call. With the defaults, a thread costs one Observer call for about every 6,000 tokens of new messages, and one Reflector call each time the log reaches 40,000 tokens. In return, every main-agent call reads a context of at most a few tens of thousands of tokens instead of the whole thread. The observation prefix stays stable, so prompt caching keeps working: users see 97 to 99% prompt cache hit rates with OM.
269
269
 
270
270
  The Observer runs ahead in the background (async buffering), so the agent doesn't stop to wait for it. These settings control the timing:
271
271
 
@@ -309,7 +309,7 @@ Every other store expects your application to supply the vectors, and keeps requ
309
309
 
310
310
  Semantic recall relies on an [embedding model](https://mastra.ai/reference/memory/memory-class) to convert messages into embeddings. Mastra supports embedding models through the model router using `provider/model` strings, or you can use any [embedding model](https://sdk.vercel.ai/docs/ai-sdk-core/embeddings) compatible with the AI SDK.
311
311
 
312
- ### Using the Model Router (Recommended)
312
+ ### Using the model router (recommended)
313
313
 
314
314
  The simplest way is to use a `provider/model` string with autocomplete support:
315
315
 
@@ -353,7 +353,7 @@ const agent = new Agent({
353
353
 
354
354
  The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_API_KEY`, `OPENROUTER_API_KEY`). Google models also fall back to `GOOGLE_GENERATIVE_AI_API_KEY`.
355
355
 
356
- ### Using AI SDK Packages
356
+ ### Using AI SDK packages
357
357
 
358
358
  You can also use AI SDK embedding models directly:
359
359
 
@@ -432,7 +432,13 @@ Memory uses a single embedder for both storing and recalling messages, so pick o
432
432
 
433
433
  Multilingual E5 produces 1024-dimensional vectors. Your vector index must be created with matching dimensions, and E5 vectors can't be mixed with vectors from another embedder in the same index.
434
434
 
435
- FastEmbed models embed at most 512 tokens per input (roughly 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding. Semantic recall sizes its message chunks to fit this window automatically (see [Long messages](#long-messages)). Outside of memory, the AI SDK v3 FastEmbed models return a warning when an input is truncated. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
435
+ FastEmbed models embed at most 512 tokens per input (about 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding. Semantic recall sizes its message chunks to fit this window automatically (see [Long messages](#long-messages)). Outside of memory, the AI SDK v3 FastEmbed models return a warning when an input is truncated. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
436
+
437
+ FastEmbed runs on your server's CPU. Under a CPU limit, such as a container's CPU quota, each loaded model uses one thread per CPU the process may use. Without a limit, it uses one thread per physical core. Each model has its own threads, so models loaded side by side add up. To leave CPU for the rest of your server, or when the process can't see its limit (for example a Kubernetes CPU request without a limit), set the thread count per model:
438
+
439
+ ```bash
440
+ MASTRA_FASTEMBED_THREADS=2
441
+ ```
436
442
 
437
443
  ### Setting the embedding dimension
438
444
 
@@ -507,4 +513,4 @@ Keep semantic recall disabled when:
507
513
 
508
514
  ## Viewing recalled messages
509
515
 
510
- When tracing is enabled, any messages retrieved via semantic recall will appear in the agent's trace output, alongside recent message history (if configured).
516
+ When tracing is enabled, any messages retrieved via semantic recall will show up in the agent's trace output, alongside recent message history (if configured).