From ceca3caa7754864626b6fda71b4155f458fea859 Mon Sep 17 00:00:00 2001 From: oaslananka <285490571+oaslananka@users.noreply.github.com> Date: Tue, 30 Jun 2026 02:43:22 +0300 Subject: [PATCH] Fix memory search for entities without observations --- src/memory/__tests__/knowledge-graph.test.ts | 12 ++++++++++++ src/memory/index.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/memory/__tests__/knowledge-graph.test.ts b/src/memory/__tests__/knowledge-graph.test.ts index 236242413a..a757cfbd04 100644 --- a/src/memory/__tests__/knowledge-graph.test.ts +++ b/src/memory/__tests__/knowledge-graph.test.ts @@ -323,6 +323,18 @@ describe('KnowledgeGraphManager', () => { expect(result.entities).toHaveLength(0); expect(result.relations).toHaveLength(0); }); + it('should handle legacy entities without observations when searching', async () => { + await fs.writeFile( + testFilePath, + JSON.stringify({ type: 'entity', name: 'Legacy Node', entityType: 'person' }), + ); + + const result = await manager.searchNodes('Legacy'); + expect(result.entities).toHaveLength(1); + expect(result.entities[0].name).toBe('Legacy Node'); + expect(result.entities[0].observations).toEqual([]); + }); + }); describe('openNodes', () => { diff --git a/src/memory/index.ts b/src/memory/index.ts index 9865c5318e..dd3b26c662 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -79,7 +79,7 @@ export class KnowledgeGraphManager { graph.entities.push({ name: item.name, entityType: item.entityType, - observations: item.observations + observations: Array.isArray(item.observations) ? item.observations : [] }); } if (item.type === "relation") {