fix(stats): ignored messages without IDs when parsing session entries

- Added message-ID checks in both assistant and user message parsers so entries without valid ids are ignored.
- This filtering prevents legacy, unlinked message records from being treated as parseable assistant or user messages.
This commit is contained in:
can1357
2026-05-15 01:09:26 +02:00
parent 05117a0258
commit f8ea641cdb
+5
View File
@@ -31,6 +31,10 @@ function extractFolderFromPath(sessionPath: string): string {
function isAssistantMessage(entry: SessionEntry): entry is SessionMessageEntry {
if (entry.type !== "message") return false;
const msgEntry = entry as SessionMessageEntry;
// Legacy sessions (pre-id tracking) recorded message entries without an `id`.
// They're not linkable and would violate the messages.entry_id NOT NULL
// constraint, so skip them at the parser boundary.
if (typeof msgEntry.id !== "string" || msgEntry.id.length === 0) return false;
return msgEntry.message?.role === "assistant";
}
@@ -40,6 +44,7 @@ function isAssistantMessage(entry: SessionEntry): entry is SessionMessageEntry {
function isUserMessage(entry: SessionEntry): entry is SessionMessageEntry {
if (entry.type !== "message") return false;
const msgEntry = entry as SessionMessageEntry;
if (typeof msgEntry.id !== "string" || msgEntry.id.length === 0) return false;
return msgEntry.message?.role === "user";
}