@mastra/memory 1.5.1-alpha.0 → 1.5.2-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 +29 -0
- package/dist/{chunk-6PKWQ3GH.js → chunk-HNPAIFCZ.js} +59 -16
- package/dist/chunk-HNPAIFCZ.js.map +1 -0
- package/dist/{chunk-6XVTMLW4.cjs → chunk-PVFLHAZX.cjs} +59 -16
- package/dist/chunk-PVFLHAZX.cjs.map +1 -0
- package/dist/docs/SKILL.md +55 -0
- package/dist/docs/assets/SOURCE_MAP.json +103 -0
- package/dist/docs/references/docs-agents-agent-approval.md +558 -0
- package/dist/docs/references/docs-agents-agent-memory.md +209 -0
- package/dist/docs/references/docs-agents-network-approval.md +275 -0
- package/dist/docs/references/docs-agents-networks.md +299 -0
- package/dist/docs/references/docs-agents-supervisor-agents.md +304 -0
- package/dist/docs/references/docs-memory-memory-processors.md +314 -0
- package/dist/docs/references/docs-memory-message-history.md +260 -0
- package/dist/docs/references/docs-memory-observational-memory.md +248 -0
- package/dist/docs/references/docs-memory-overview.md +45 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +272 -0
- package/dist/docs/references/docs-memory-storage.md +261 -0
- package/dist/docs/references/docs-memory-working-memory.md +400 -0
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-memory-clone-utilities.md +199 -0
- package/dist/docs/references/reference-memory-cloneThread.md +130 -0
- package/dist/docs/references/reference-memory-createThread.md +68 -0
- package/dist/docs/references/reference-memory-getThreadById.md +24 -0
- package/dist/docs/references/reference-memory-listThreads.md +145 -0
- package/dist/docs/references/reference-memory-memory-class.md +147 -0
- package/dist/docs/references/reference-memory-observational-memory.md +565 -0
- package/dist/docs/references/reference-processors-token-limiter-processor.md +115 -0
- package/dist/docs/references/reference-storage-dynamodb.md +282 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/references/reference-storage-mongodb.md +262 -0
- package/dist/docs/references/reference-storage-postgresql.md +526 -0
- package/dist/docs/references/reference-storage-upstash.md +160 -0
- package/dist/docs/references/reference-vectors-libsql.md +305 -0
- package/dist/docs/references/reference-vectors-mongodb.md +295 -0
- package/dist/docs/references/reference-vectors-pg.md +408 -0
- package/dist/docs/references/reference-vectors-upstash.md +294 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{observational-memory-AJWSMZVP.js → observational-memory-KAFD4QZK.js} +3 -3
- package/dist/{observational-memory-AJWSMZVP.js.map → observational-memory-KAFD4QZK.js.map} +1 -1
- package/dist/{observational-memory-Q5TO525O.cjs → observational-memory-Q47HN5YL.cjs} +17 -17
- package/dist/{observational-memory-Q5TO525O.cjs.map → observational-memory-Q47HN5YL.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 +2 -2
- 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 +8 -8
- package/dist/chunk-6PKWQ3GH.js.map +0 -1
- package/dist/chunk-6XVTMLW4.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.5.2-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed observational memory buffering to preserve more context and activate at the right time. ([#13476](https://github.com/mastra-ai/mastra/pull/13476))
|
|
8
|
+
- **Fixed** activation timing so observations trigger mid-step as soon as the threshold is crossed, instead of waiting for the next user message.
|
|
9
|
+
- **Fixed** partial activations that left too much context — activation is now skipped when it can't compress enough, falling back to a full observation instead.
|
|
10
|
+
- **Fixed** token counting so reasoning-only message parts no longer inflate totals and cause premature context reduction.
|
|
11
|
+
- **Clarified** `blockAfter` behavior: values below 100 are treated as multipliers (e.g. `1.2` = 1.2× threshold), values ≥ 100 as absolute token counts.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`df170fd`](https://github.com/mastra-ai/mastra/commit/df170fd139b55f845bfd2de8488b16435bd3d0da), [`ae55343`](https://github.com/mastra-ai/mastra/commit/ae5534397fc006fd6eef3e4f80c235bcdc9289ef), [`c290cec`](https://github.com/mastra-ai/mastra/commit/c290cec5bf9107225de42942b56b487107aa9dce), [`f03e794`](https://github.com/mastra-ai/mastra/commit/f03e794630f812b56e95aad54f7b1993dc003add), [`aa4a5ae`](https://github.com/mastra-ai/mastra/commit/aa4a5aedb80d8d6837bab8cbb2e301215d1ba3e9), [`de3f584`](https://github.com/mastra-ai/mastra/commit/de3f58408752a8d80a295275c7f23fc306cf7f4f), [`d3fb010`](https://github.com/mastra-ai/mastra/commit/d3fb010c98f575f1c0614452667396e2653815f6), [`702ee1c`](https://github.com/mastra-ai/mastra/commit/702ee1c41be67cc532b4dbe89bcb62143508f6f0), [`f495051`](https://github.com/mastra-ai/mastra/commit/f495051eb6496a720f637fc85b6d69941c12554c), [`e622f1d`](https://github.com/mastra-ai/mastra/commit/e622f1d3ab346a8e6aca6d1fe2eac99bd961e50b), [`8d14a59`](https://github.com/mastra-ai/mastra/commit/8d14a591d46fbbbe81baa33c9c267d596f790329), [`861f111`](https://github.com/mastra-ai/mastra/commit/861f11189211b20ddb70d8df81a6b901fc78d11e), [`00f43e8`](https://github.com/mastra-ai/mastra/commit/00f43e8e97a80c82b27d5bd30494f10a715a1df9), [`1b6f651`](https://github.com/mastra-ai/mastra/commit/1b6f65127d4a0d6c38d0a1055cb84527db529d6b), [`96a1702`](https://github.com/mastra-ai/mastra/commit/96a1702ce362c50dda20c8b4a228b4ad1a36a17a), [`cb9f921`](https://github.com/mastra-ai/mastra/commit/cb9f921320913975657abb1404855d8c510f7ac5), [`114e7c1`](https://github.com/mastra-ai/mastra/commit/114e7c146ac682925f0fb37376c1be70e5d6e6e5), [`1b6f651`](https://github.com/mastra-ai/mastra/commit/1b6f65127d4a0d6c38d0a1055cb84527db529d6b), [`72df4a8`](https://github.com/mastra-ai/mastra/commit/72df4a8f9bf1a20cfd3d9006a4fdb597ad56d10a)]:
|
|
14
|
+
- @mastra/core@1.8.0-alpha.0
|
|
15
|
+
- @mastra/schema-compat@1.1.3-alpha.0
|
|
16
|
+
|
|
17
|
+
## 1.5.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- **Fixed memory leak in Observational Memory** ([#13425](https://github.com/mastra-ai/mastra/pull/13425))
|
|
22
|
+
|
|
23
|
+
Fixed several memory management issues that could cause OOM crashes in long-running processes with Observational Memory enabled:
|
|
24
|
+
- **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.
|
|
25
|
+
- **Cleanup key fix**: Fixed a bug where reflection cycle IDs were not properly cleaned up due to using the wrong map key in `cleanupStaticMaps`.
|
|
26
|
+
|
|
27
|
+
- 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))
|
|
28
|
+
|
|
29
|
+
- 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), [`0c338b8`](https://github.com/mastra-ai/mastra/commit/0c338b87362dcd95ff8191ca00df645b6953f534), [`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)]:
|
|
30
|
+
- @mastra/core@1.7.0
|
|
31
|
+
|
|
3
32
|
## 1.5.1-alpha.0
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -979,7 +979,7 @@ var TokenCounter = class _TokenCounter {
|
|
|
979
979
|
`Unhandled tool-invocation state '${part.toolInvocation?.state}' in token counting for part type '${part.type}'`
|
|
980
980
|
);
|
|
981
981
|
}
|
|
982
|
-
} else if (typeof part.type === "string" && part.type.startsWith("data-")) ; else {
|
|
982
|
+
} else if (typeof part.type === "string" && part.type.startsWith("data-")) ; else if (part.type === "reasoning") ; else {
|
|
983
983
|
tokenString += JSON.stringify(part);
|
|
984
984
|
}
|
|
985
985
|
}
|
|
@@ -1475,10 +1475,12 @@ var ObservationalMemory = class _ObservationalMemory {
|
|
|
1475
1475
|
const maxOvershoot = retentionFloor * 0.95;
|
|
1476
1476
|
const overshoot = bestOverTokens - targetMessageTokens;
|
|
1477
1477
|
const remainingAfterOver = currentPendingTokens - bestOverTokens;
|
|
1478
|
+
const remainingAfterUnder = currentPendingTokens - bestUnderTokens;
|
|
1479
|
+
const minRemaining = Math.min(1e3, retentionFloor);
|
|
1478
1480
|
let bestBoundaryMessageTokens;
|
|
1479
|
-
if (bestOverBoundary > 0 && overshoot <= maxOvershoot &&
|
|
1481
|
+
if (bestOverBoundary > 0 && overshoot <= maxOvershoot && remainingAfterOver >= minRemaining) {
|
|
1480
1482
|
bestBoundaryMessageTokens = bestOverTokens;
|
|
1481
|
-
} else if (bestUnderBoundary > 0) {
|
|
1483
|
+
} else if (bestUnderBoundary > 0 && remainingAfterUnder >= minRemaining) {
|
|
1482
1484
|
bestBoundaryMessageTokens = bestUnderTokens;
|
|
1483
1485
|
} else if (bestOverBoundary > 0) {
|
|
1484
1486
|
bestBoundaryMessageTokens = bestOverTokens;
|
|
@@ -1838,14 +1840,14 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
1838
1840
|
}
|
|
1839
1841
|
/**
|
|
1840
1842
|
* Resolve blockAfter config value.
|
|
1841
|
-
* Values
|
|
1843
|
+
* Values in [1, 100) are treated as multipliers of the threshold.
|
|
1842
1844
|
* e.g. blockAfter: 1.5 with messageTokens: 20_000 → 30_000
|
|
1843
|
-
* Values >=
|
|
1845
|
+
* Values >= 100 are treated as absolute token counts.
|
|
1844
1846
|
* Defaults to 1.2 (120% of threshold) when async buffering is enabled but blockAfter is omitted.
|
|
1845
1847
|
*/
|
|
1846
1848
|
resolveBlockAfter(blockAfter, messageTokens) {
|
|
1847
1849
|
if (blockAfter === void 0) return void 0;
|
|
1848
|
-
if (blockAfter >= 1 && blockAfter <
|
|
1850
|
+
if (blockAfter >= 1 && blockAfter < 100) {
|
|
1849
1851
|
const threshold = typeof messageTokens === "number" ? messageTokens : messageTokens.max;
|
|
1850
1852
|
return Math.round(threshold * blockAfter);
|
|
1851
1853
|
}
|
|
@@ -2979,7 +2981,7 @@ ${suggestedResponse}
|
|
|
2979
2981
|
* Remove observed messages from message list after successful observation.
|
|
2980
2982
|
* Accepts optional observedMessageIds for activation-based cleanup (when no markers are present).
|
|
2981
2983
|
*/
|
|
2982
|
-
async cleanupAfterObservation(messageList, sealedIds, threadId, resourceId, state, observedMessageIds) {
|
|
2984
|
+
async cleanupAfterObservation(messageList, sealedIds, threadId, resourceId, state, observedMessageIds, minRemaining) {
|
|
2983
2985
|
const allMsgs = messageList.get.all.db();
|
|
2984
2986
|
let markerIdx = -1;
|
|
2985
2987
|
let markerMsg = null;
|
|
@@ -3023,13 +3025,25 @@ ${suggestedResponse}
|
|
|
3023
3025
|
} else if (observedMessageIds && observedMessageIds.length > 0) {
|
|
3024
3026
|
const observedSet = new Set(observedMessageIds);
|
|
3025
3027
|
const idsToRemove = [];
|
|
3028
|
+
const totalTokens = typeof minRemaining === "number" ? this.tokenCounter.countMessages(allMsgs) : void 0;
|
|
3029
|
+
let removedTokens = 0;
|
|
3030
|
+
let skipped = 0;
|
|
3026
3031
|
for (const msg of allMsgs) {
|
|
3027
3032
|
if (msg?.id && msg.id !== "om-continuation" && observedSet.has(msg.id)) {
|
|
3033
|
+
if (typeof minRemaining === "number") {
|
|
3034
|
+
const msgTokens = this.tokenCounter.countMessage(msg);
|
|
3035
|
+
const remainingIfRemoved = (totalTokens ?? 0) - removedTokens - msgTokens;
|
|
3036
|
+
if (remainingIfRemoved < minRemaining) {
|
|
3037
|
+
skipped += 1;
|
|
3038
|
+
continue;
|
|
3039
|
+
}
|
|
3040
|
+
removedTokens += msgTokens;
|
|
3041
|
+
}
|
|
3028
3042
|
idsToRemove.push(msg.id);
|
|
3029
3043
|
}
|
|
3030
3044
|
}
|
|
3031
3045
|
omDebug(
|
|
3032
|
-
`[OM:cleanupActivation] observedSet=${[...observedSet].map((id) => id.slice(0, 8)).join(",")}, matched=${idsToRemove.length}, idsToRemove=${idsToRemove.map((id) => id.slice(0, 8)).join(",")}`
|
|
3046
|
+
`[OM:cleanupActivation] observedSet=${[...observedSet].map((id) => id.slice(0, 8)).join(",")}, matched=${idsToRemove.length}, skipped=${skipped}, idsToRemove=${idsToRemove.map((id) => id.slice(0, 8)).join(",")}`
|
|
3033
3047
|
);
|
|
3034
3048
|
if (idsToRemove.length > 0) {
|
|
3035
3049
|
messageList.removeByIds(idsToRemove);
|
|
@@ -3178,8 +3192,12 @@ ${suggestedResponse}
|
|
|
3178
3192
|
async processInputStep(args) {
|
|
3179
3193
|
const { messageList, requestContext, stepNumber, state: _state, writer, abortSignal, abort } = args;
|
|
3180
3194
|
const state = _state ?? {};
|
|
3195
|
+
omDebug(
|
|
3196
|
+
`[OM:processInputStep:ENTER] step=${stepNumber}, hasMastraMemory=${!!requestContext?.get("MastraMemory")}, hasMemoryInfo=${!!messageList?.serialize()?.memoryInfo?.threadId}`
|
|
3197
|
+
);
|
|
3181
3198
|
const context = this.getThreadContext(requestContext, messageList);
|
|
3182
3199
|
if (!context) {
|
|
3200
|
+
omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null \u2014 returning early`);
|
|
3183
3201
|
return messageList;
|
|
3184
3202
|
}
|
|
3185
3203
|
const { threadId, resourceId } = context;
|
|
@@ -3318,7 +3336,7 @@ ${suggestedResponse}
|
|
|
3318
3336
|
record
|
|
3319
3337
|
);
|
|
3320
3338
|
const { totalPendingTokens, threshold } = thresholds;
|
|
3321
|
-
const bufferedChunkTokens = this.getBufferedChunks(record).reduce((sum, c) => sum + (c.
|
|
3339
|
+
const bufferedChunkTokens = this.getBufferedChunks(record).reduce((sum, c) => sum + (c.messageTokens ?? 0), 0);
|
|
3322
3340
|
const unbufferedPendingTokens = Math.max(0, totalPendingTokens - bufferedChunkTokens);
|
|
3323
3341
|
const stateSealedIds = state.sealedIds ?? /* @__PURE__ */ new Set();
|
|
3324
3342
|
const staticSealedIds = _ObservationalMemory.sealedMessageIds.get(threadId) ?? /* @__PURE__ */ new Set();
|
|
@@ -3326,7 +3344,7 @@ ${suggestedResponse}
|
|
|
3326
3344
|
state.sealedIds = sealedIds;
|
|
3327
3345
|
const lockKey = this.getLockKey(threadId, resourceId);
|
|
3328
3346
|
if (this.isAsyncObservationEnabled() && totalPendingTokens < threshold) {
|
|
3329
|
-
const shouldTrigger = this.shouldTriggerAsyncObservation(
|
|
3347
|
+
const shouldTrigger = this.shouldTriggerAsyncObservation(totalPendingTokens, lockKey, record, threshold);
|
|
3330
3348
|
omDebug(
|
|
3331
3349
|
`[OM:async-obs] belowThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, shouldTrigger=${shouldTrigger}, isBufferingObs=${record.isBufferingObservation}, lastBufferedAt=${record.lastBufferedAtTokens}`
|
|
3332
3350
|
);
|
|
@@ -3342,7 +3360,7 @@ ${suggestedResponse}
|
|
|
3342
3360
|
);
|
|
3343
3361
|
}
|
|
3344
3362
|
} else if (this.isAsyncObservationEnabled()) {
|
|
3345
|
-
const shouldTrigger = this.shouldTriggerAsyncObservation(
|
|
3363
|
+
const shouldTrigger = this.shouldTriggerAsyncObservation(totalPendingTokens, lockKey, record, threshold);
|
|
3346
3364
|
omDebug(
|
|
3347
3365
|
`[OM:async-obs] atOrAboveThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, step=${stepNumber}, shouldTrigger=${shouldTrigger}`
|
|
3348
3366
|
);
|
|
@@ -3376,10 +3394,19 @@ ${suggestedResponse}
|
|
|
3376
3394
|
);
|
|
3377
3395
|
if (observationSucceeded) {
|
|
3378
3396
|
const observedIds = activatedMessageIds?.length ? activatedMessageIds : Array.isArray(updatedRecord.observedMessageIds) ? updatedRecord.observedMessageIds : void 0;
|
|
3397
|
+
const minRemaining = typeof this.observationConfig.bufferActivation === "number" ? Math.min(1e3, this.resolveRetentionFloor(this.observationConfig.bufferActivation, threshold)) : void 0;
|
|
3379
3398
|
omDebug(
|
|
3380
|
-
`[OM:cleanup] observedIds=${observedIds?.length ?? "undefined"}, ids=${observedIds?.join(",") ?? "none"}, updatedRecord.observedMessageIds=${JSON.stringify(updatedRecord.observedMessageIds)}`
|
|
3399
|
+
`[OM:cleanup] observedIds=${observedIds?.length ?? "undefined"}, ids=${observedIds?.join(",") ?? "none"}, updatedRecord.observedMessageIds=${JSON.stringify(updatedRecord.observedMessageIds)}, minRemaining=${minRemaining ?? "n/a"}`
|
|
3400
|
+
);
|
|
3401
|
+
await this.cleanupAfterObservation(
|
|
3402
|
+
messageList,
|
|
3403
|
+
sealedIds,
|
|
3404
|
+
threadId,
|
|
3405
|
+
resourceId,
|
|
3406
|
+
state,
|
|
3407
|
+
observedIds,
|
|
3408
|
+
minRemaining
|
|
3381
3409
|
);
|
|
3382
|
-
await this.cleanupAfterObservation(messageList, sealedIds, threadId, resourceId, state, observedIds);
|
|
3383
3410
|
if (activatedMessageIds?.length) {
|
|
3384
3411
|
this.cleanupStaticMaps(threadId, resourceId, activatedMessageIds);
|
|
3385
3412
|
}
|
|
@@ -3976,7 +4003,7 @@ ${result.observations}` : result.observations;
|
|
|
3976
4003
|
}
|
|
3977
4004
|
try {
|
|
3978
4005
|
omDebug(
|
|
3979
|
-
`[OM:bufferInput] cycleId=${cycleId}, msgCount=${messagesToBuffer.length}, msgTokens=${
|
|
4006
|
+
`[OM:bufferInput] cycleId=${cycleId}, msgCount=${messagesToBuffer.length}, msgTokens=${tokensToBuffer}, ids=${messagesToBuffer.map((m) => `${m.id?.slice(0, 8)}@${m.createdAt ? new Date(m.createdAt).toISOString() : "none"}`).join(",")}`
|
|
3980
4007
|
);
|
|
3981
4008
|
await this.doAsyncBufferedObservation(
|
|
3982
4009
|
freshRecord,
|
|
@@ -4143,6 +4170,22 @@ ${bufferedObservations}`;
|
|
|
4143
4170
|
const bufferActivation = this.observationConfig.bufferActivation ?? 0.7;
|
|
4144
4171
|
const activationRatio = this.resolveActivationRatio(bufferActivation, messageTokensThreshold);
|
|
4145
4172
|
const forceMaxActivation = !!(this.observationConfig.blockAfter && effectivePendingTokens >= this.observationConfig.blockAfter);
|
|
4173
|
+
const bufferTokens = this.observationConfig.bufferTokens ?? 0;
|
|
4174
|
+
const retentionFloor = this.resolveRetentionFloor(bufferActivation, messageTokensThreshold);
|
|
4175
|
+
const projectedMessageRemoval = this.calculateProjectedMessageRemoval(
|
|
4176
|
+
freshChunks,
|
|
4177
|
+
bufferActivation,
|
|
4178
|
+
messageTokensThreshold,
|
|
4179
|
+
effectivePendingTokens
|
|
4180
|
+
);
|
|
4181
|
+
const projectedRemaining = Math.max(0, effectivePendingTokens - projectedMessageRemoval);
|
|
4182
|
+
const maxRemaining = retentionFloor + bufferTokens;
|
|
4183
|
+
if (!forceMaxActivation && bufferTokens > 0 && projectedRemaining > maxRemaining) {
|
|
4184
|
+
omDebug(
|
|
4185
|
+
`[OM:tryActivate] skipping activation: projectedRemaining=${projectedRemaining} > maxRemaining=${maxRemaining} (retentionFloor=${retentionFloor}, bufferTokens=${bufferTokens})`
|
|
4186
|
+
);
|
|
4187
|
+
return { success: false };
|
|
4188
|
+
}
|
|
4146
4189
|
omDebug(
|
|
4147
4190
|
`[OM:tryActivate] swapping: freshChunks=${freshChunks.length}, bufferActivation=${bufferActivation}, activationRatio=${activationRatio}, forceMax=${forceMaxActivation}, totalChunkTokens=${freshChunks.reduce((s, c) => s + (c.tokenCount ?? 0), 0)}`
|
|
4148
4191
|
);
|
|
@@ -5065,5 +5108,5 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5065
5108
|
};
|
|
5066
5109
|
|
|
5067
5110
|
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 };
|
|
5068
|
-
//# sourceMappingURL=chunk-
|
|
5069
|
-
//# sourceMappingURL=chunk-
|
|
5111
|
+
//# sourceMappingURL=chunk-HNPAIFCZ.js.map
|
|
5112
|
+
//# sourceMappingURL=chunk-HNPAIFCZ.js.map
|