@mastra/memory 1.23.0-alpha.2 → 1.23.0-alpha.3

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 (28) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{chunk-GHFCSEEP.js → chunk-FNWCP2TI.js} +48 -6
  3. package/dist/chunk-FNWCP2TI.js.map +1 -0
  4. package/dist/{chunk-2ZR7CKDV.cjs → chunk-WZKTIB4U.cjs} +48 -6
  5. package/dist/chunk-WZKTIB4U.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +57 -57
  8. package/dist/docs/references/docs-agents-supervisor-agents.md +1 -3
  9. package/dist/docs/references/docs-evals-evals-with-memory.md +1 -3
  10. package/dist/docs/references/docs-long-running-agents-background-tasks.md +1 -1
  11. package/dist/docs/references/docs-long-running-agents-goals.md +1 -3
  12. package/dist/docs/references/docs-memory-overview.md +4 -4
  13. package/dist/index.cjs +15 -15
  14. package/dist/index.js +1 -1
  15. package/dist/{observational-memory-HUPMKPOX.js → observational-memory-GAYCVM5R.js} +3 -3
  16. package/dist/{observational-memory-HUPMKPOX.js.map → observational-memory-GAYCVM5R.js.map} +1 -1
  17. package/dist/{observational-memory-RJL2PW6O.cjs → observational-memory-HZP3D5IO.cjs} +29 -29
  18. package/dist/{observational-memory-RJL2PW6O.cjs.map → observational-memory-HZP3D5IO.cjs.map} +1 -1
  19. package/dist/processors/index.cjs +27 -27
  20. package/dist/processors/index.js +1 -1
  21. package/dist/processors/observational-memory/observation-turn/step.d.ts +13 -0
  22. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observation-turn/turn.d.ts +25 -0
  24. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  26. package/package.json +5 -5
  27. package/dist/chunk-2ZR7CKDV.cjs.map +0 -1
  28. package/dist/chunk-GHFCSEEP.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.23.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed a "Converting circular structure to JSON" crash when Observational Memory was used with an input or output processor composed as a workflow (the "run guardrails in parallel" pattern). ([#17949](https://github.com/mastra-ai/mastra/pull/17949))
8
+
9
+ The circular data reached the processor workflow's snapshot and broke storage: PostgreSQL threw, and LibSQL saved a corrupted snapshot. Observational Memory now keeps its runtime data in a serializable form, so workflow-composed processors work with it and snapshots persist correctly.
10
+
11
+ - Updated dependencies [[`a5c6337`](https://github.com/mastra-ai/mastra/commit/a5c6337d23c7686c81a32ce62f550f610543a240), [`8b97958`](https://github.com/mastra-ai/mastra/commit/8b979589f9aa59ba67cac565949475f2ffeb4ac3), [`8410541`](https://github.com/mastra-ai/mastra/commit/84105412c60ecd3bb33a9838146f59c4b588228f), [`01b338c`](https://github.com/mastra-ai/mastra/commit/01b338c56271f0219606710e3e8b26dee27ac6c2), [`8b7361d`](https://github.com/mastra-ai/mastra/commit/8b7361d35de68b80d05d30a74e0c69e7218fd612), [`c43f3a9`](https://github.com/mastra-ai/mastra/commit/c43f3a9d1efde99b38789364ba4d0ba670f430e3)]:
12
+ - @mastra/core@1.51.0-alpha.4
13
+
3
14
  ## 1.23.0-alpha.2
4
15
 
5
16
  ### Patch Changes
@@ -2783,6 +2783,18 @@ var ObservationStep = class {
2783
2783
  get prepared() {
2784
2784
  return this._prepared;
2785
2785
  }
2786
+ /**
2787
+ * Serialize to a minimal, acyclic snapshot.
2788
+ *
2789
+ * The `turn` back-reference exists only so a step can read context off its parent turn at
2790
+ * runtime. It closes the `ObservationTurn._currentStep -> ObservationStep.turn` cycle, so
2791
+ * serializing it throws "Converting circular structure to JSON" (e.g. when a turn is stashed
2792
+ * in processor state that flows into a processor-workflow snapshot). The parent turn fully
2793
+ * owns the step, so omitting the back-reference is lossless.
2794
+ */
2795
+ toJSON() {
2796
+ return { stepNumber: this.stepNumber, prepared: this._prepared };
2797
+ }
2786
2798
  /** Step context from prepare(). Throws if prepare() hasn't been called. */
2787
2799
  get context() {
2788
2800
  if (!this._context) throw new Error("Step not prepared yet \u2014 call prepare() first");
@@ -3246,6 +3258,33 @@ var ObservationTurn = class {
3246
3258
  }
3247
3259
  return this._context?.otherThreadsContext;
3248
3260
  }
3261
+ /**
3262
+ * Serialize to a minimal, acyclic snapshot of the turn's identity and lifecycle.
3263
+ *
3264
+ * `ObservationTurn` is a request-scoped runtime orchestration object: it holds live
3265
+ * references (the `ObservationalMemory` engine, the `MessageList`, the stream writer, the
3266
+ * memory provider, lifecycle hooks) and a back-reference to its current `ObservationStep`,
3267
+ * which points back at the turn — a cycle. None of that is persistable state. The turn is
3268
+ * stashed in the shared processor-state map (`state.__omTurn`) only so the input and output
3269
+ * OM processor instances can reach the *live* object within a single request; that map is
3270
+ * also threaded into processor workflows, whose snapshots the storage layer serializes with
3271
+ * `JSON.stringify`. Without this projection, that serialization throws "Converting circular
3272
+ * structure to JSON" via `_currentStep` <-> `turn`.
3273
+ *
3274
+ * The projection is lossless: the dropped fields are live runtime objects that cannot and
3275
+ * should not round-trip through storage, and OM never reads the turn back from a snapshot —
3276
+ * it always reads the live `__omTurn` from the in-memory map and re-establishes a fresh turn
3277
+ * when a deserialized `MessageList` no longer matches (see the processor's turn handling).
3278
+ */
3279
+ toJSON() {
3280
+ return {
3281
+ threadId: this.threadId,
3282
+ resourceId: this.resourceId,
3283
+ started: this._started,
3284
+ ended: this._ended,
3285
+ currentStepNumber: this._currentStep?.stepNumber
3286
+ };
3287
+ }
3249
3288
  };
3250
3289
 
3251
3290
  // src/processors/observational-memory/anchor-ids.ts
@@ -24560,7 +24599,7 @@ ${workingMemory}`;
24560
24599
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
24561
24600
  );
24562
24601
  }
24563
- const { ObservationalMemory: OMClass } = await import('./observational-memory-HUPMKPOX.js');
24602
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-GAYCVM5R.js');
24564
24603
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
24565
24604
  await this.indexObservation(observation);
24566
24605
  } : void 0;
@@ -25608,7 +25647,7 @@ Notes:
25608
25647
  if (!effectiveConfig) return null;
25609
25648
  const engine = await this.omEngine;
25610
25649
  if (!engine) return null;
25611
- const { ObservationalMemoryProcessor: ObservationalMemoryProcessor2 } = await import('./observational-memory-HUPMKPOX.js');
25650
+ const { ObservationalMemoryProcessor: ObservationalMemoryProcessor2 } = await import('./observational-memory-GAYCVM5R.js');
25612
25651
  return new ObservationalMemoryProcessor2(engine, this, {
25613
25652
  temporalMarkers: effectiveConfig.temporalMarkers
25614
25653
  });
@@ -30271,6 +30310,9 @@ async function insertTemporalGapMarkers({
30271
30310
  }
30272
30311
 
30273
30312
  // src/processors/observational-memory/processor.ts
30313
+ function asLiveTurn(value) {
30314
+ return value && typeof value.end === "function" ? value : void 0;
30315
+ }
30274
30316
  function getOmObservabilityContext(args) {
30275
30317
  if (!args.tracing || !args.tracingContext || !args.loggerVNext || !args.metrics) {
30276
30318
  return void 0;
@@ -30388,7 +30430,7 @@ var ObservationalMemoryProcessor = class {
30388
30430
  });
30389
30431
  return messageList;
30390
30432
  }
30391
- const activeTurn = state.__omTurn ?? this.turn;
30433
+ const activeTurn = asLiveTurn(state.__omTurn) ?? this.turn;
30392
30434
  if (activeTurn && activeTurn.messageList !== messageList) {
30393
30435
  await activeTurn.end().catch(() => {
30394
30436
  });
@@ -30505,7 +30547,7 @@ var ObservationalMemoryProcessor = class {
30505
30547
  return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
30506
30548
  const memoryContext = parseMemoryRequestContext(requestContext);
30507
30549
  if (memoryContext?.memoryConfig?.readOnly) return messageList;
30508
- const turn = state.__omTurn ?? this.turn;
30550
+ const turn = asLiveTurn(state.__omTurn) ?? this.turn;
30509
30551
  if (turn) {
30510
30552
  await turn.end();
30511
30553
  this.turn = void 0;
@@ -30558,5 +30600,5 @@ function getObservationsAsOf(activeObservations, asOf) {
30558
30600
  }
30559
30601
 
30560
30602
  export { Extractor, Memory, ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, SUMMARIZE_THREAD_DEFAULTS, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deepMergeWorkingMemory, deriveObservationGroupProvenance, extractCurrentTask, extractWorkingMemoryContent, extractWorkingMemoryTags, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, removeWorkingMemoryTags, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
30561
- //# sourceMappingURL=chunk-GHFCSEEP.js.map
30562
- //# sourceMappingURL=chunk-GHFCSEEP.js.map
30603
+ //# sourceMappingURL=chunk-FNWCP2TI.js.map
30604
+ //# sourceMappingURL=chunk-FNWCP2TI.js.map