fix: validate memory search result counts · openclaw/openclaw@e9cca2d
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,7 @@ const MemorySearchSchema = {
|
62 | 62 | type: "object", |
63 | 63 | properties: { |
64 | 64 | query: { type: "string" }, |
65 | | -maxResults: { type: "number" }, |
| 65 | +maxResults: { type: "integer", minimum: 1 }, |
66 | 66 | minScore: { type: "number" }, |
67 | 67 | corpus: { type: "string", enum: ["memory", "wiki", "all", "sessions"] }, |
68 | 68 | }, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,7 @@ export async function loadMemoryToolRuntime(): Promise<MemoryToolRuntime> {
|
30 | 30 | |
31 | 31 | export const MemorySearchSchema = Type.Object({ |
32 | 32 | query: Type.String(), |
33 | | -maxResults: Type.Optional(Type.Number()), |
| 33 | +maxResults: Type.Optional(Type.Integer({ minimum: 1 })), |
34 | 34 | minScore: Type.Optional(Type.Number()), |
35 | 35 | corpus: Type.Optional(stringEnum(["memory", "wiki", "all", "sessions"])), |
36 | 36 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -58,6 +58,19 @@ describe("memory_search unavailable payloads", () => {
|
58 | 58 | resetMemoryToolMockState({ searchImpl: async () => [] }); |
59 | 59 | }); |
60 | 60 | |
| 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 | + |
61 | 74 | it("returns explicit unavailable metadata for quota failures", async () => { |
62 | 75 | setMemorySearchImpl(async () => { |
63 | 76 | throw new Error("openai embeddings failed: 429 insufficient_quota"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -256,7 +256,7 @@ export function createMemorySearchTool(options: {
|
256 | 256 | async (_toolCallId, params) => { |
257 | 257 | const rawParams = asToolParamsRecord(params); |
258 | 258 | const query = readStringParam(rawParams, "query", { required: true }); |
259 | | -const maxResults = readNumberParam(rawParams, "maxResults"); |
| 259 | +const maxResults = readPositiveIntegerParam(rawParams, "maxResults"); |
260 | 260 | const minScore = readNumberParam(rawParams, "minScore"); |
261 | 261 | const requestedCorpus = readStringParam(rawParams, "corpus") as |
262 | 262 | | "memory" |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。