-
-
Notifications
You must be signed in to change notification settings - Fork 53k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
When /compact runs or auto-compaction triggers, a TypeError: Cannot read properties of undefined (reading 'length') occurs.
Stack Trace
The error occurs in limitHistoryTurns (history.js) when messages is undefined:
if (!limit || limit <= 0 || messages.length === 0) return messages;Root Cause
In compact.js, session.messages can be undefined in edge cases (e.g., corrupted session file, SDK edge case). This undefined value flows through sanitizeSessionHistory to limitHistoryTurns, which doesn't guard against it.
Suggested Fix
Add a guard in limitHistoryTurns:
export function limitHistoryTurns(messages, limit) {
if (!messages || !limit || limit <= 0 || messages.length === 0) return messages ?? [];
// ...
}Or guard upstream in compact.js:
const prior = await sanitizeSessionHistory({ messages: session.messages ?? [], ... });Environment
- Clawdbot version: 2026.1.24-3
- OS: macOS (arm64)
- Node: v22.11.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working