Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(search): treat an empty types array as no filter (#5390)
Ziyang Guoba98957a7fe3
diff --git a/src/core/ops/search.ts b/src/core/ops/search.tsindex f27f00e58d..1d0f859abf 100644--- a/src/core/ops/search.ts+++ b/src/core/ops/search.ts@@ -245,13 +245,23 @@ async function buildRetrievalResponseMeta(/*** #3985: normalize the `types` param. MCP passes a real array; the CLI* passes `--types person,company` as one string. Rejects non-string entries- * and an all-empty list loudly (invalid_params) instead of silently- * dropping the filter. The SQL-level plumbing (SearchOpts.types → both- * engines' keyword/title/vector legs) has existed since v0.33 (whoknows);- * this just exposes it on the public search/query ops.+ * and a non-empty list whose entries trim/filter to nothing loudly+ * (invalid_params) instead of silently dropping the filter.+ *+ * #5390: a structurally empty array (`[]`) carries no user intent — it is+ * what OpenAI-family MCP clients send when an LLM over-fills every optional+ * parameter with a type-zero value. Treat it as absent (no filter applied)+ * rather than throwing, so the search still runs unfiltered. A non-empty+ * list that filters to nothing (`['']`, `',,'`) still throws, so a CLI+ * `--types ,` typo is still loud. The SQL-level plumbing (SearchOpts.types+ * → both engines' keyword/title/vector legs) has existed since v0.33+ * (whoknows); this just exposes it on the public search/query ops.*/function normalizeTypesParam(raw: unknown): string[] | undefined {if (raw === undefined || raw === null) return undefined;+ // #5390: structurally empty array is treated as absent, not as a request+ // for an impossible filter. The CLI typo guard below still catches `',,'`.+ if (Array.isArray(raw) && raw.length === 0) return undefined;const arr = Array.isArray(raw)? raw: typeof raw === 'string'diff --git a/test/ops-search-types.test.ts b/test/ops-search-types.test.tsindex 2b538e2fd3..183f1fe220 100644--- a/test/ops-search-types.test.ts+++ b/test/ops-search-types.test.ts@@ -89,6 +89,26 @@ describe('search op — types param (#3985)', () => {searchOp.handler(ctxOf(), { query: 'zebra telescope', types: ' , ' }),).rejects.toThrow(/no usable page-type/i);});++ // #5390: a structurally empty array carries no user intent (OpenAI-family+ // MCP clients emit `types: []` whenever the model over-fills an optional+ // parameter with a type-zero value, which happens routinely). The CLI typo+ // guard above is preserved — only a list that had entries which all blanked+ // out keeps throwing.+ test('empty array is treated as no filter (#5390)', async () => {+ const out = await searchOp.handler(ctxOf(), { query: 'zebra telescope', types: [] });+ expect(slugsOf(out)).toEqual([+ 'companies/acme-example',+ 'notes/telescope-note',+ 'people/alice-example',+ ]);+ });++ test('non-empty array of blanks still rejects as invalid_params (#5390)', async () => {+ await expect(+ searchOp.handler(ctxOf(), { query: 'zebra telescope', types: [''] }),+ ).rejects.toThrow(/no usable page-type/i);+ });});describe('query op — types param (#3985)', () => {diff --git a/test/schema-engine-isolation.serial.test.ts b/test/schema-engine-isolation.serial.test.tsindex 6025124301..26d9f323c9 100644--- a/test/schema-engine-isolation.serial.test.ts+++ b/test/schema-engine-isolation.serial.test.ts@@ -144,7 +144,15 @@ for (const failedKey of ['schema_pack', 'schema_pack.source.default']) {}));}-test('explicit empty type sets deny hybrid and expert reads before any engine or cache access', async () => {+test('explicit empty type sets pass through as no-filter (regression #5390)', async () => {+ // #5390: a structurally empty `types` array (`[]`) carries no user+ // intent — it is what OpenAI-family MCP clients emit when the model+ // over-fills every optional parameter. The contract is now: treat it+ // as absent (no filter applied) rather than throwing `no usable page-type+ // strings`. The engine then runs the unfiltered search; with the proxy+ // below, that access trips the `Empty filters must not access the engine`+ // guard at the engine boundary, which is what proves the no-filter path+ // reaches the engine (i.e. the filter was dropped, not rejected).const access = new Proxy({} as PGLiteEngine, { get() { throw new Error('Empty filters must not access the engine'); } });for (const type of [undefined, 'company']) {expect(await expandEngineTypeFilters(access, { type, types: [] })).toEqual({ type: undefined, types: [] });@@ -154,7 +162,10 @@ test('explicit empty type sets deny hybrid and expert reads before any engine orexpect(await findExperts(access, { topic: 'quasar', types: [] })).toEqual([]);expect(await expandEngineTypeFilters(access, {})).toEqual({});for (const name of ['search', 'query']) {- await expect(operations.find(op => op.name === name)!.handler(ctx(access), { query: 'quasar', types: [] })).rejects.toThrow('no usable page-type strings');+ // The MCP handler no longer throws on `types: []`; it drops the filter+ // and runs unfiltered. The proxy proves the engine was reached, not+ // short-circuited — that is the desired post-#5390 contract.+ await expect(operations.find(op => op.name === name)!.handler(ctx(access), { query: 'quasar', types: [] })).rejects.toThrow('Empty filters must not access the engine');}});