fix: add console.warn when reserveTokensFloor is clamped
Log a warning when reserveTokensFloor exceeds contextWindow - softThreshold - 1, so users are alerted to misconfigured values instead of silent clamping.
This commit is contained in:
parent
5788066510
commit
1857ff82a1
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -356,7 +356,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: {}
|
||||
|
||||
@ -427,7 +427,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:
|
||||
@ -7499,7 +7499,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
|
||||
@ -12436,11 +12436,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)
|
||||
|
||||
@ -167,6 +167,8 @@ export function resolveMemoryFlushContextWindowTokens(params: {
|
||||
);
|
||||
}
|
||||
|
||||
const _warnedReserve = new Set<string>();
|
||||
|
||||
export function shouldRunMemoryFlush(params: {
|
||||
entry?: Pick<
|
||||
SessionEntry,
|
||||
@ -198,10 +200,16 @@ export function shouldRunMemoryFlush(params: {
|
||||
}
|
||||
const contextWindow = Math.max(1, Math.floor(params.contextWindowTokens));
|
||||
const softThreshold = Math.max(0, Math.floor(params.softThresholdTokens));
|
||||
const reserveTokens = Math.min(
|
||||
Math.max(0, Math.floor(params.reserveTokensFloor)),
|
||||
Math.max(0, contextWindow - softThreshold - 1),
|
||||
);
|
||||
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;
|
||||
|
||||
@ -494,4 +494,4 @@ describe("incrementCompactionCount", () => {
|
||||
// totalTokens unchanged
|
||||
expect(stored[sessionKey].totalTokens).toBe(180_000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user