diff --git a/src/agents/tools/memory-tool.e2e.test.ts b/src/agents/tools/memory-tool.e2e.test.ts index 6ebb3e92ef9..b5dc52b769a 100644 --- a/src/agents/tools/memory-tool.e2e.test.ts +++ b/src/agents/tools/memory-tool.e2e.test.ts @@ -12,7 +12,7 @@ let searchImpl: () => Promise = async () => [ source: "memory" as const, }, ]; -let readFileImpl: () => Promise = async () => ""; +let readFileImpl: () => Promise = async () => ""; const stubManager = { search: vi.fn(async () => await searchImpl()), @@ -59,7 +59,7 @@ beforeEach(() => { source: "memory" as const, }, ]; - readFileImpl = async () => ""; + readFileImpl = async () => ""; // default: return empty string vi.clearAllMocks(); }); @@ -189,4 +189,23 @@ describe("memory tools", () => { error: "path required", }); }); + + it("returns empty text without error when file does not exist (ENOENT)", async () => { + readFileImpl = async () => { + return { text: "", path: "memory/2026-02-19.md" }; + }; + + const cfg = { agents: { list: [{ id: "main", default: true }] } }; + const tool = createMemoryGetTool({ config: cfg }); + expect(tool).not.toBeNull(); + if (!tool) { + throw new Error("tool missing"); + } + + const result = await tool.execute("call_enoent", { path: "memory/2026-02-19.md" }); + expect(result.details).toEqual({ + text: "", + path: "memory/2026-02-19.md", + }); + }); }); diff --git a/src/memory/manager.ts b/src/memory/manager.ts index a0124e1b726..dc159f2afc5 100644 --- a/src/memory/manager.ts +++ b/src/memory/manager.ts @@ -437,7 +437,19 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem if (!absPath.endsWith(".md")) { throw new Error("path required"); } - const stat = await fs.lstat(absPath); + let stat; + try { + stat = await fs.lstat(absPath); + } catch (err: unknown) { + if ( + err instanceof Error && + "code" in err && + (err as NodeJS.ErrnoException).code === "ENOENT" + ) { + return { text: "", path: relPath }; + } + throw err; + } if (stat.isSymbolicLink() || !stat.isFile()) { throw new Error("path required"); }