Skip to content

Commit a513c58

Browse files
committed
Fix memory_get all supplement fallback
1 parent 5cd71db commit a513c58

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

‎extensions/memory-core/src/tools.citations.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,41 @@ describe("memory tools", () => {
629629
lineCount: 5,
630630
});
631631
});
632+
633+
it("falls back to a wiki corpus supplement when memory_get corpus=all misses memory without throwing", async () => {
634+
setMemoryReadFileImpl(async (params: MemoryReadParams) => ({
635+
text: "",
636+
path: params.relPath,
637+
}));
638+
registerMemoryCorpusSupplement("memory-wiki", {
639+
search: async () => [],
640+
get: async () => ({
641+
corpus: "wiki",
642+
path: "memory/entities/alpha.md",
643+
title: "Alpha",
644+
kind: "entity",
645+
content: "Alpha wiki entry after empty miss",
646+
fromLine: 3,
647+
lineCount: 5,
648+
}),
649+
});
650+
651+
const tool = createMemoryGetToolOrThrow();
652+
const result = await tool.execute("call_get_all_empty_miss_fallback", {
653+
path: "memory/entities/alpha.md",
654+
from: 3,
655+
lines: 5,
656+
corpus: "all",
657+
});
658+
659+
expect(result.details).toEqual({
660+
corpus: "wiki",
661+
path: "memory/entities/alpha.md",
662+
title: "Alpha",
663+
kind: "entity",
664+
text: "Alpha wiki entry after empty miss",
665+
fromLine: 3,
666+
lineCount: 5,
667+
});
668+
});
632669
});

‎extensions/memory-core/src/tools.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,32 @@ async function resolveMemoryReadFailureResult(params: {
360360
return jsonResult({ path: params.relPath, text: "", disabled: true, error: message });
361361
}
362362

363+
function isMissingMemoryReadResult(value: unknown, relPath: string): boolean {
364+
if (!value || typeof value !== "object" || Array.isArray(value)) {
365+
return false;
366+
}
367+
const result = value as {
368+
text?: unknown;
369+
path?: unknown;
370+
disabled?: unknown;
371+
error?: unknown;
372+
from?: unknown;
373+
lines?: unknown;
374+
truncated?: unknown;
375+
nextFrom?: unknown;
376+
};
377+
return (
378+
result.path === relPath &&
379+
result.text === "" &&
380+
result.disabled === undefined &&
381+
result.error === undefined &&
382+
result.from === undefined &&
383+
result.lines === undefined &&
384+
result.truncated === undefined &&
385+
result.nextFrom === undefined
386+
);
387+
}
388+
363389
async function executeMemoryReadResult<T>(params: {
364390
read: () => Promise<T>;
365391
requestedCorpus?: "memory" | "wiki" | "all";
@@ -369,7 +395,20 @@ async function executeMemoryReadResult<T>(params: {
369395
agentSessionKey?: string;
370396
}) {
371397
try {
372-
return jsonResult(await params.read());
398+
const result = await params.read();
399+
if (params.requestedCorpus === "all" && isMissingMemoryReadResult(result, params.relPath)) {
400+
const supplement = await getSupplementMemoryReadResult({
401+
relPath: params.relPath,
402+
from: params.from,
403+
lines: params.lines,
404+
agentSessionKey: params.agentSessionKey,
405+
corpus: params.requestedCorpus,
406+
});
407+
if (supplement) {
408+
return jsonResult(supplement);
409+
}
410+
}
411+
return jsonResult(result);
373412
} catch (error) {
374413
return await resolveMemoryReadFailureResult({
375414
error,

0 commit comments

Comments
 (0)