mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 20:00:41 +00:00
fix: guard pre-compaction token estimation with try/catch
If estimateTokens throws on a malformed/legacy message, fall back to 0 so the sanity check becomes a no-op instead of crashing compaction. Also skip the sanity check when fullSessionTokensBefore is 0.
This commit is contained in:
@@ -905,8 +905,8 @@ export async function compactEmbeddedPiSessionDirect(
|
||||
try {
|
||||
fullSessionTokensBefore = limited.reduce((sum, msg) => sum + estimateTokens(msg), 0);
|
||||
} catch {
|
||||
// If token estimation throws on a malformed message, skip the sanity check
|
||||
// instead of crashing compaction.
|
||||
// If token estimation throws on a malformed message, fall back to 0 so
|
||||
// the sanity check below becomes a no-op instead of crashing compaction.
|
||||
}
|
||||
const result = await compactWithSafetyTimeout(() =>
|
||||
session.compact(params.customInstructions),
|
||||
|
||||
Reference in New Issue
Block a user