Skip to content

Commit e9cca2d

Browse files
committed
fix: validate memory search result counts
1 parent 1610b49 commit e9cca2d

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎extensions/memory-core/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const MemorySearchSchema = {
6262
type: "object",
6363
properties: {
6464
query: { type: "string" },
65-
maxResults: { type: "number" },
65+
maxResults: { type: "integer", minimum: 1 },
6666
minScore: { type: "number" },
6767
corpus: { type: "string", enum: ["memory", "wiki", "all", "sessions"] },
6868
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function loadMemoryToolRuntime(): Promise<MemoryToolRuntime> {
3030

3131
export const MemorySearchSchema = Type.Object({
3232
query: Type.String(),
33-
maxResults: Type.Optional(Type.Number()),
33+
maxResults: Type.Optional(Type.Integer({ minimum: 1 })),
3434
minScore: Type.Optional(Type.Number()),
3535
corpus: Type.Optional(stringEnum(["memory", "wiki", "all", "sessions"])),
3636
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ describe("memory_search unavailable payloads", () => {
5858
resetMemoryToolMockState({ searchImpl: async () => [] });
5959
});
6060

61+
it("rejects fractional maxResults before searching", async () => {
62+
const tool = createMemorySearchToolOrThrow();
63+
64+
await expect(
65+
tool.execute("fractional-max-results", {
66+
query: "hello",
67+
maxResults: 1.5,
68+
}),
69+
).rejects.toThrow("maxResults must be a positive integer");
70+
71+
expect(getMemorySearchManagerMockCalls()).toBe(0);
72+
});
73+
6174
it("returns explicit unavailable metadata for quota failures", async () => {
6275
setMemorySearchImpl(async () => {
6376
throw new Error("openai embeddings failed: 429 insufficient_quota");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export function createMemorySearchTool(options: {
256256
async (_toolCallId, params) => {
257257
const rawParams = asToolParamsRecord(params);
258258
const query = readStringParam(rawParams, "query", { required: true });
259-
const maxResults = readNumberParam(rawParams, "maxResults");
259+
const maxResults = readPositiveIntegerParam(rawParams, "maxResults");
260260
const minScore = readNumberParam(rawParams, "minScore");
261261
const requestedCorpus = readStringParam(rawParams, "corpus") as
262262
| "memory"

0 commit comments

Comments
 (0)