@mastra/memory 1.5.0 → 1.5.1-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.
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-DF7NDDSM.js → chunk-6PKWQ3GH.js} +28 -11
- package/dist/chunk-6PKWQ3GH.js.map +1 -0
- package/dist/{chunk-LLTHE64H.cjs → chunk-6XVTMLW4.cjs} +28 -11
- package/dist/chunk-6XVTMLW4.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{observational-memory-ZNTAIUGT.js → observational-memory-AJWSMZVP.js} +3 -3
- package/dist/{observational-memory-ZNTAIUGT.js.map → observational-memory-AJWSMZVP.js.map} +1 -1
- package/dist/{observational-memory-4PCXEZIS.cjs → observational-memory-Q5TO525O.cjs} +17 -17
- package/dist/{observational-memory-4PCXEZIS.cjs.map → observational-memory-Q5TO525O.cjs.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-DF7NDDSM.js.map +0 -1
- package/dist/chunk-LLTHE64H.cjs.map +0 -1
- package/dist/docs/SKILL.md +0 -54
- package/dist/docs/assets/SOURCE_MAP.json +0 -103
- package/dist/docs/references/docs-agents-agent-approval.md +0 -377
- package/dist/docs/references/docs-agents-agent-memory.md +0 -212
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-agents-networks.md +0 -290
- package/dist/docs/references/docs-memory-memory-processors.md +0 -316
- package/dist/docs/references/docs-memory-message-history.md +0 -260
- package/dist/docs/references/docs-memory-observational-memory.md +0 -246
- package/dist/docs/references/docs-memory-overview.md +0 -45
- package/dist/docs/references/docs-memory-semantic-recall.md +0 -272
- package/dist/docs/references/docs-memory-storage.md +0 -261
- package/dist/docs/references/docs-memory-working-memory.md +0 -400
- package/dist/docs/references/reference-core-getMemory.md +0 -50
- package/dist/docs/references/reference-core-listMemory.md +0 -56
- package/dist/docs/references/reference-memory-clone-utilities.md +0 -199
- package/dist/docs/references/reference-memory-cloneThread.md +0 -130
- package/dist/docs/references/reference-memory-createThread.md +0 -68
- package/dist/docs/references/reference-memory-getThreadById.md +0 -24
- package/dist/docs/references/reference-memory-listThreads.md +0 -145
- package/dist/docs/references/reference-memory-memory-class.md +0 -147
- package/dist/docs/references/reference-memory-observational-memory.md +0 -565
- package/dist/docs/references/reference-processors-token-limiter-processor.md +0 -113
- package/dist/docs/references/reference-storage-dynamodb.md +0 -282
- package/dist/docs/references/reference-storage-libsql.md +0 -135
- package/dist/docs/references/reference-storage-mongodb.md +0 -262
- package/dist/docs/references/reference-storage-postgresql.md +0 -529
- package/dist/docs/references/reference-storage-upstash.md +0 -160
- package/dist/docs/references/reference-vectors-libsql.md +0 -305
- package/dist/docs/references/reference-vectors-mongodb.md +0 -295
- package/dist/docs/references/reference-vectors-pg.md +0 -408
- package/dist/docs/references/reference-vectors-upstash.md +0 -294
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.5.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- **Fixed memory leak in Observational Memory** ([#13425](https://github.com/mastra-ai/mastra/pull/13425))
|
|
8
|
+
|
|
9
|
+
Fixed several memory management issues that could cause OOM crashes in long-running processes with Observational Memory enabled:
|
|
10
|
+
- **Shared tokenizer**: The default Tiktoken encoder (~80-120 MB heap) is now shared across all OM instances instead of being allocated per request. This is the primary fix — previously each request allocated two encoders that persisted in memory due to async buffering promise retention.
|
|
11
|
+
- **Cleanup key fix**: Fixed a bug where reflection cycle IDs were not properly cleaned up due to using the wrong map key in `cleanupStaticMaps`.
|
|
12
|
+
|
|
13
|
+
- Fixed PostgreSQL deadlock when parallel agents with different threadIds share the same resourceId while using Observational Memory. Thread scope now requires a valid threadId and throws a clear error if one is missing. Also fixed the database lock ordering in synchronous observation to prevent lock inversions. ([#13436](https://github.com/mastra-ai/mastra/pull/13436))
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`24284ff`](https://github.com/mastra-ai/mastra/commit/24284ffae306ddf0ab83273e13f033520839ef40), [`f5097cc`](https://github.com/mastra-ai/mastra/commit/f5097cc8a813c82c3378882c31178320cadeb655), [`71e237f`](https://github.com/mastra-ai/mastra/commit/71e237fa852a3ad9a50a3ddb3b5f3b20b9a8181c), [`13a291e`](https://github.com/mastra-ai/mastra/commit/13a291ebb9f9bca80befa0d9166b916bb348e8e9), [`397af5a`](https://github.com/mastra-ai/mastra/commit/397af5a69f34d4157f51a7c8da3f1ded1e1d611c), [`d4701f7`](https://github.com/mastra-ai/mastra/commit/d4701f7e24822b081b70f9c806c39411b1a712e7), [`2b40831`](https://github.com/mastra-ai/mastra/commit/2b40831dcca2275c9570ddf09b7f25ba3e8dc7fc), [`6184727`](https://github.com/mastra-ai/mastra/commit/6184727e812bf7a65cee209bacec3a2f5a16e923), [`6f6385b`](https://github.com/mastra-ai/mastra/commit/6f6385be5b33687cd21e71fc27e972e6928bb34c), [`14aba61`](https://github.com/mastra-ai/mastra/commit/14aba61b9cff76d72bc7ef6f3a83ae2c5d059193), [`dd9dd1c`](https://github.com/mastra-ai/mastra/commit/dd9dd1c9ae32ae79093f8c4adde1732ac6357233)]:
|
|
16
|
+
- @mastra/core@1.7.0-alpha.0
|
|
17
|
+
|
|
3
18
|
## 1.5.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -909,6 +909,13 @@ function extractReflectorListItems(content) {
|
|
|
909
909
|
function validateCompression(reflectedTokens, targetThreshold) {
|
|
910
910
|
return reflectedTokens < targetThreshold;
|
|
911
911
|
}
|
|
912
|
+
var sharedDefaultEncoder;
|
|
913
|
+
function getDefaultEncoder() {
|
|
914
|
+
if (!sharedDefaultEncoder) {
|
|
915
|
+
sharedDefaultEncoder = new Tiktoken(o200k_base);
|
|
916
|
+
}
|
|
917
|
+
return sharedDefaultEncoder;
|
|
918
|
+
}
|
|
912
919
|
var TokenCounter = class _TokenCounter {
|
|
913
920
|
encoder;
|
|
914
921
|
// Per-message overhead: accounts for role tokens, message framing, and separators.
|
|
@@ -918,7 +925,7 @@ var TokenCounter = class _TokenCounter {
|
|
|
918
925
|
// Conversation-level overhead: system prompt framing, reply priming tokens, etc.
|
|
919
926
|
static TOKENS_PER_CONVERSATION = 24;
|
|
920
927
|
constructor(encoding) {
|
|
921
|
-
this.encoder = new Tiktoken(encoding
|
|
928
|
+
this.encoder = encoding ? new Tiktoken(encoding) : getDefaultEncoder();
|
|
922
929
|
}
|
|
923
930
|
/**
|
|
924
931
|
* Count tokens in a plain string
|
|
@@ -1373,7 +1380,7 @@ var ObservationalMemory = class _ObservationalMemory {
|
|
|
1373
1380
|
_ObservationalMemory.lastBufferedBoundary.delete(reflBufKey);
|
|
1374
1381
|
_ObservationalMemory.asyncBufferingOps.delete(obsBufKey);
|
|
1375
1382
|
_ObservationalMemory.asyncBufferingOps.delete(reflBufKey);
|
|
1376
|
-
_ObservationalMemory.reflectionBufferCycleIds.delete(
|
|
1383
|
+
_ObservationalMemory.reflectionBufferCycleIds.delete(reflBufKey);
|
|
1377
1384
|
}
|
|
1378
1385
|
}
|
|
1379
1386
|
/**
|
|
@@ -1925,6 +1932,11 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1925
1932
|
resourceId: resourceId ?? threadId
|
|
1926
1933
|
};
|
|
1927
1934
|
}
|
|
1935
|
+
if (!threadId) {
|
|
1936
|
+
throw new Error(
|
|
1937
|
+
`ObservationalMemory (scope: 'thread') requires a threadId, but received an empty value. This is a bug \u2014 getThreadContext should have caught this earlier.`
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1928
1940
|
return {
|
|
1929
1941
|
threadId,
|
|
1930
1942
|
resourceId: resourceId ?? threadId
|
|
@@ -2683,6 +2695,11 @@ ${suggestedResponse}
|
|
|
2683
2695
|
resourceId: serialized.memoryInfo.resourceId
|
|
2684
2696
|
};
|
|
2685
2697
|
}
|
|
2698
|
+
if (this.scope === "thread") {
|
|
2699
|
+
throw new Error(
|
|
2700
|
+
`ObservationalMemory (scope: 'thread') requires a threadId, but none was found in RequestContext or MessageList. Ensure the agent is configured with Memory and a valid threadId is provided.`
|
|
2701
|
+
);
|
|
2702
|
+
}
|
|
2686
2703
|
return null;
|
|
2687
2704
|
}
|
|
2688
2705
|
// ══════════════════════════════════════════════════════════════════════════
|
|
@@ -3759,13 +3776,6 @@ ${result.observations}` : result.observations;
|
|
|
3759
3776
|
const newMessageIds = messagesToObserve.map((m) => m.id);
|
|
3760
3777
|
const existingIds = freshRecord?.observedMessageIds ?? record.observedMessageIds ?? [];
|
|
3761
3778
|
const allObservedIds = [.../* @__PURE__ */ new Set([...Array.isArray(existingIds) ? existingIds : [], ...newMessageIds])];
|
|
3762
|
-
await this.storage.updateActiveObservations({
|
|
3763
|
-
id: record.id,
|
|
3764
|
-
observations: newObservations,
|
|
3765
|
-
tokenCount: totalTokenCount,
|
|
3766
|
-
lastObservedAt,
|
|
3767
|
-
observedMessageIds: allObservedIds
|
|
3768
|
-
});
|
|
3769
3779
|
if (result.suggestedContinuation || result.currentTask) {
|
|
3770
3780
|
const thread = await this.storage.getThreadById({ threadId });
|
|
3771
3781
|
if (thread) {
|
|
@@ -3780,6 +3790,13 @@ ${result.observations}` : result.observations;
|
|
|
3780
3790
|
});
|
|
3781
3791
|
}
|
|
3782
3792
|
}
|
|
3793
|
+
await this.storage.updateActiveObservations({
|
|
3794
|
+
id: record.id,
|
|
3795
|
+
observations: newObservations,
|
|
3796
|
+
tokenCount: totalTokenCount,
|
|
3797
|
+
lastObservedAt,
|
|
3798
|
+
observedMessageIds: allObservedIds
|
|
3799
|
+
});
|
|
3783
3800
|
const actualTokensObserved = this.tokenCounter.countMessages(messagesToObserve);
|
|
3784
3801
|
if (lastMessage?.id) {
|
|
3785
3802
|
const endMarker = this.createObservationEndMarker({
|
|
@@ -5048,5 +5065,5 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5048
5065
|
};
|
|
5049
5066
|
|
|
5050
5067
|
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput };
|
|
5051
|
-
//# sourceMappingURL=chunk-
|
|
5052
|
-
//# sourceMappingURL=chunk-
|
|
5068
|
+
//# sourceMappingURL=chunk-6PKWQ3GH.js.map
|
|
5069
|
+
//# sourceMappingURL=chunk-6PKWQ3GH.js.map
|