From 08a858824b1028662bd0fd81c1567e5a939958e2 Mon Sep 17 00:00:00 2001 From: dingguagua996-stack Date: Tue, 24 Mar 2026 19:30:15 +0800 Subject: [PATCH] fix: guard against null entries in LLM extraction response When the LLM returns malformed JSON with null entries in the memories array (e.g. {memories: [null, {...}]}), accessing raw.category throws: TypeError: Cannot read properties of null (reading 'category') This crash was observed in production (7 occurrences across multiple days), causing the entire auto-capture pipeline to fail silently. Add a null/type guard at the top of the candidate processing loop to skip invalid entries gracefully instead of crashing. Fixes capture failures logged as: memory-lancedb-pro: capture failed: TypeError: Cannot read properties of null (reading 'category') --- src/smart-extractor.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/smart-extractor.ts b/src/smart-extractor.ts index d3313b9..fe2036a 100644 --- a/src/smart-extractor.ts +++ b/src/smart-extractor.ts @@ -377,6 +377,13 @@ export class SmartExtractor { let shortAbstractCount = 0; let noiseAbstractCount = 0; for (const raw of result.memories) { + if (!raw || typeof raw !== "object") { + invalidCategoryCount++; + this.debugLog( + `memory-lancedb-pro: smart-extractor: dropping null/invalid candidate entry`, + ); + continue; + } const category = normalizeCategory(raw.category ?? ""); if (!category) { invalidCategoryCount++;