fix(mnemopi): preserve empty structured extraction

Short-circuit successfully parsed structured extractor output even when all extraction arrays are empty, so the JSON response body is not stored as a fallback memory.

Added coverage for plain and fenced empty extraction JSON.

Fixes #4390
This commit is contained in:
roboomp
2026-07-03 03:41:50 +00:00
parent eacaf65ea3
commit b24052b895
2 changed files with 8 additions and 3 deletions
+1 -3
View File
@@ -115,9 +115,7 @@ export function parseFacts(rawOutput: string | null | undefined): string[] {
}
}
}
if (out.length > 0) {
return out.slice(0, 5);
}
return out.slice(0, 5);
}
} catch {
const matches = [...raw.matchAll(/"([^"]{10,})"/g)].map(m => m[1]).filter((v): v is string => v !== undefined);
+7
View File
@@ -52,6 +52,13 @@ describe("structured extraction", () => {
expect(parseFacts("NO_FACTS")).toEqual([]);
});
it("treats a valid empty structured extraction as no facts", () => {
expect(parseFacts('{"facts": [], "instructions": [], "preferences": [], "timelines": [], "kg": []}')).toEqual([]);
expect(
parseFacts('```json\n{"facts": [], "instructions": [], "preferences": [], "timelines": [], "kg": []}\n```'),
).toEqual([]);
});
it("uses deterministic heuristic extraction when no LLM is configured", async () => {
process.env.MNEMOPI_LLM_ENABLED = "false";
const facts = await extractFactsSafe("My name is Ada. I work at Example Corp and I prefer dark mode.");