@mastra/memory 1.15.0-alpha.2 → 1.15.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.15.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed reflection threshold not respecting per-record overrides set via the PATCH API. Previously, lowering the reflection threshold for a specific record had no effect on the actual reflection trigger — only the default 40k threshold was used. Now per-record overrides are correctly applied in both sync and async reflection paths. ([#15170](https://github.com/mastra-ai/mastra/pull/15170))
8
+
3
9
  ## 1.15.0-alpha.2
4
10
 
5
11
  ### Patch Changes
@@ -4124,13 +4124,29 @@ var ReflectorRunner = class {
4124
4124
  model
4125
4125
  });
4126
4126
  }
4127
- getObservationMarkerConfig() {
4127
+ getObservationMarkerConfig(record) {
4128
4128
  return {
4129
4129
  messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
4130
- observationTokens: getMaxThreshold(this.reflectionConfig.observationTokens),
4130
+ observationTokens: getMaxThreshold(
4131
+ record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens
4132
+ ),
4131
4133
  scope: this.scope
4132
4134
  };
4133
4135
  }
4136
+ /**
4137
+ * Resolve the effective reflection observationTokens for a record.
4138
+ * Only explicit per-record overrides (stored under `_overrides`) win;
4139
+ * the initial config snapshot is ignored so instance-level changes
4140
+ * still take effect for existing records.
4141
+ */
4142
+ getEffectiveReflectionTokens(record) {
4143
+ const overrides = record.config?._overrides;
4144
+ const recordTokens = overrides?.reflection?.observationTokens;
4145
+ if (recordTokens) {
4146
+ return recordTokens;
4147
+ }
4148
+ return this.reflectionConfig.observationTokens;
4149
+ }
4134
4150
  /**
4135
4151
  * Call the Reflector agent with escalating compression levels.
4136
4152
  */
@@ -4319,7 +4335,7 @@ var ReflectorRunner = class {
4319
4335
  const freshRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
4320
4336
  const currentRecord = freshRecord ?? record;
4321
4337
  const observationTokens = currentRecord.observationTokenCount ?? 0;
4322
- const reflectThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);
4338
+ const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
4323
4339
  const bufferActivation = this.reflectionConfig.bufferActivation ?? 0.5;
4324
4340
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
4325
4341
  const cycleId = `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
@@ -4348,7 +4364,7 @@ var ReflectorRunner = class {
4348
4364
  recordId: record.id,
4349
4365
  threadId: record.threadId ?? "",
4350
4366
  threadIds: record.threadId ? [record.threadId] : [],
4351
- config: this.getObservationMarkerConfig()
4367
+ config: this.getObservationMarkerConfig(currentRecord)
4352
4368
  });
4353
4369
  void writer.custom(startMarker).catch(() => {
4354
4370
  });
@@ -4460,7 +4476,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4460
4476
  threadId: freshRecord.threadId ?? "",
4461
4477
  generationCount: afterRecord?.generationCount ?? freshRecord.generationCount ?? 0,
4462
4478
  observations: afterRecord?.activeObservations,
4463
- config: this.getObservationMarkerConfig()
4479
+ config: this.getObservationMarkerConfig(freshRecord)
4464
4480
  });
4465
4481
  void writer.custom(activationMarker).catch(() => {
4466
4482
  });
@@ -4491,7 +4507,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4491
4507
  observabilityContext
4492
4508
  } = opts;
4493
4509
  const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
4494
- const reflectThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);
4510
+ const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
4495
4511
  if (this.buffering.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
4496
4512
  const shouldTrigger = (() => {
4497
4513
  if (!this.buffering.isAsyncReflectionEnabled()) return false;
@@ -4570,7 +4586,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4570
4586
  recordId: record.id,
4571
4587
  threadId,
4572
4588
  threadIds: [threadId],
4573
- config: this.getObservationMarkerConfig()
4589
+ config: this.getObservationMarkerConfig(record)
4574
4590
  });
4575
4591
  await writer.custom(startMarker).catch(() => {
4576
4592
  });
@@ -8818,5 +8834,5 @@ function getObservationsAsOf(activeObservations, asOf) {
8818
8834
  }
8819
8835
 
8820
8836
  export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
8821
- //# sourceMappingURL=chunk-ERPFT635.js.map
8822
- //# sourceMappingURL=chunk-ERPFT635.js.map
8837
+ //# sourceMappingURL=chunk-42AZEBIK.js.map
8838
+ //# sourceMappingURL=chunk-42AZEBIK.js.map