diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7f438d0a2e3..2c578bf23f0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -359,7 +359,7 @@ importers: version: 10.6.2 openclaw: specifier: '>=2026.3.11' - version: 2026.3.13(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)) + version: 2026.3.13(@discordjs/opus@0.10.0)(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)) extensions/huggingface: {} @@ -430,7 +430,7 @@ importers: dependencies: openclaw: specifier: '>=2026.3.11' - version: 2026.3.13(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)) + version: 2026.3.13(@discordjs/opus@0.10.0)(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)) extensions/memory-lancedb: dependencies: @@ -7482,7 +7482,7 @@ snapshots: dependencies: css-tree: 3.2.1 - '@buape/carbon@0.0.0-beta-20260216184201(hono@4.12.8)(opusscript@0.1.1)': + '@buape/carbon@0.0.0-beta-20260216184201(@discordjs/opus@0.10.0)(hono@4.12.8)(opusscript@0.1.1)': dependencies: '@types/node': 25.5.0 discord-api-types: 0.38.37 @@ -12403,11 +12403,11 @@ snapshots: ws: 8.19.0 zod: 4.3.6 - openclaw@2026.3.13(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)): + openclaw@2026.3.13(@discordjs/opus@0.10.0)(@napi-rs/canvas@0.1.95)(@types/express@5.0.6)(audio-decode@2.2.3)(jimp@1.6.0)(node-llama-cpp@3.16.2(typescript@5.9.3)): dependencies: '@agentclientprotocol/sdk': 0.16.1(zod@4.3.6) '@aws-sdk/client-bedrock': 3.1009.0 - '@buape/carbon': 0.0.0-beta-20260216184201(hono@4.12.8)(opusscript@0.1.1) + '@buape/carbon': 0.0.0-beta-20260216184201(@discordjs/opus@0.10.0)(hono@4.12.8)(opusscript@0.1.1) '@clack/prompts': 1.1.0 '@discordjs/voice': 0.19.2(@discordjs/opus@0.10.0)(opusscript@0.1.1) '@grammyjs/runner': 2.0.3(grammy@1.41.1) diff --git a/src/auto-reply/reply/memory-flush.ts b/src/auto-reply/reply/memory-flush.ts index 95f6dbaa053..5d68d55d45a 100644 --- a/src/auto-reply/reply/memory-flush.ts +++ b/src/auto-reply/reply/memory-flush.ts @@ -167,6 +167,8 @@ export function resolveMemoryFlushContextWindowTokens(params: { ); } +const _warnedReserve = new Set(); + export function shouldRunMemoryFlush(params: { entry?: Pick< SessionEntry, @@ -197,9 +199,18 @@ export function shouldRunMemoryFlush(params: { return false; } const contextWindow = Math.max(1, Math.floor(params.contextWindowTokens)); - const reserveTokens = Math.max(0, Math.floor(params.reserveTokensFloor)); const softThreshold = Math.max(0, Math.floor(params.softThresholdTokens)); - const threshold = Math.max(0, contextWindow - reserveTokens - softThreshold); + const rawReserve = Math.max(0, Math.floor(params.reserveTokensFloor)); + const maxReserve = Math.max(0, contextWindow - softThreshold - 1); + const warnKey = `${rawReserve}:${maxReserve}`; + if (rawReserve > maxReserve && !_warnedReserve.has(warnKey)) { + _warnedReserve.add(warnKey); + console.warn( + `reserveTokensFloor (${rawReserve}) exceeds contextWindow - softThreshold - 1 (${maxReserve}), clamping to ${maxReserve}`, + ); + } + const reserveTokens = Math.min(rawReserve, maxReserve); + const threshold = contextWindow - reserveTokens - softThreshold; if (threshold <= 0) { return false; } diff --git a/src/auto-reply/reply/reply-state.test.ts b/src/auto-reply/reply/reply-state.test.ts index f83d313e2d3..0ba30d1f83b 100644 --- a/src/auto-reply/reply/reply-state.test.ts +++ b/src/auto-reply/reply/reply-state.test.ts @@ -357,6 +357,17 @@ describe("shouldRunMemoryFlush", () => { }), ).toBe(false); }); + + it("triggers when reserveTokensFloor equals contextWindowTokens", () => { + expect( + shouldRunMemoryFlush({ + entry: { totalTokens: 199_000, compactionCount: 0 }, + contextWindowTokens: 200_000, + reserveTokensFloor: 200_000, + softThresholdTokens: 4_000, + }), + ).toBe(true); + }); }); describe("hasAlreadyFlushedForCurrentCompaction", () => {