Skip to content

Commit 84240b7

Browse files
dingguagua996-stackdingguagua996-stack
andauthored
fix: guard against null entries in LLM extraction response (#338)
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') Co-authored-by: dingguagua996-stack <dingguagua996@users.noreply.github.com>
1 parent 4878abd commit 84240b7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/smart-extractor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ export class SmartExtractor {
401401
let shortAbstractCount = 0;
402402
let noiseAbstractCount = 0;
403403
for (const raw of result.memories) {
404+
if (!raw || typeof raw !== "object") {
405+
invalidCategoryCount++;
406+
this.debugLog(
407+
`memory-lancedb-pro: smart-extractor: dropping null/invalid candidate entry`,
408+
);
409+
continue;
410+
}
404411
const category = normalizeCategory(raw.category ?? "");
405412
if (!category) {
406413
invalidCategoryCount++;

0 commit comments

Comments
 (0)