From 5260595472038a808e55c8a4e28704ea8a1551d6 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:35:00 -0700 Subject: [PATCH] fix(sdk): treat zero search results as success (#11510) --- .../src/extensions/tools/definitions.test.ts | 52 +++++++++++++++++++ .../core/src/extensions/tools/definitions.ts | 5 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/sdk/packages/core/src/extensions/tools/definitions.test.ts b/sdk/packages/core/src/extensions/tools/definitions.test.ts index 8f69e9ec75..17616983f5 100644 --- a/sdk/packages/core/src/extensions/tools/definitions.test.ts +++ b/sdk/packages/core/src/extensions/tools/definitions.test.ts @@ -8,6 +8,7 @@ import { createBashTool, createDefaultTools, createReadFilesTool, + createSearchTool, createSkillsTool, createWindowsShellTool, } from "./definitions"; @@ -348,6 +349,57 @@ describe("default submit_and_exit tool", () => { }); }); +describe("default search_codebase tool", () => { + it("treats a valid search with zero matches as success", async () => { + const noResults = + "No results found for pattern: missingSymbol\nSearched 3 files."; + const execute = vi.fn(async () => noResults); + const tool = createSearchTool(execute); + + const result = await tool.execute( + { queries: ["missingSymbol"] }, + { + agentId: "agent-1", + conversationId: "conv-1", + iteration: 1, + }, + ); + + expect(result).toEqual([ + { + query: "missingSymbol", + result: noResults, + success: true, + }, + ]); + }); + + it("treats executor errors as failures", async () => { + const execute = vi.fn(async () => { + throw new Error("bad regex"); + }); + const tool = createSearchTool(execute); + + const result = await tool.execute( + { queries: ["("] }, + { + agentId: "agent-1", + conversationId: "conv-1", + iteration: 1, + }, + ); + + expect(result).toEqual([ + { + query: "(", + result: "", + error: "Search failed: bad regex", + success: false, + }, + ]); + }); +}); + describe("default apply_patch tool", () => { it("is included only when enabled with an applyPatch executor", () => { const toolsWithoutExecutor = createDefaultTools({ diff --git a/sdk/packages/core/src/extensions/tools/definitions.ts b/sdk/packages/core/src/extensions/tools/definitions.ts index 5e9f00fed1..30fa578d0a 100644 --- a/sdk/packages/core/src/extensions/tools/definitions.ts +++ b/sdk/packages/core/src/extensions/tools/definitions.ts @@ -247,13 +247,10 @@ export function createSearchTool( timeoutMs, `Search timed out after ${timeoutMs}ms`, ); - // Check if results contain matches - const hasResults = - results.length > 0 && !results.includes("No results found"); return { query, result: results, - success: hasResults, + success: true, }; } catch (error) { const msg = formatError(error);