{"record":{"id":"bedbf2202c9e6af9","repo":"JuliusBrussee/caveman","slug":"cave-tool-search-query-required","errorCode":"cave_tool_search_query_required","errorMessage":"cave_tool_search_query_required","messagePattern":"cave_tool_search_query_required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3067,"sourceCode":"      };\n    },\n  };\n}\n\nfunction toolSchemaSearchTool(\n  handles: ReadonlySet<string>,\n  engineBin: string | undefined,\n  trace?: MutableTransformTrace[],\n): AgentTool<TSchema> {\n  return {\n    name: \"cave_search_tools\",\n    label: \"cave_search_tools\",\n    description: \"Search exact original tool definitions when compacted annotations are insufficient.\",\n    parameters: Type.Object({ query: Type.String() }),\n    executionMode: \"parallel\",\n    async execute(_toolCallId, params) {\n      const query = (params as { query: string }).query.trim().toLowerCase();\n      if (query === \"\") throw new Error(\"cave_tool_search_query_required\");\n      const terms = tokenize(query);\n      const hits: Array<{ score: number; value: Record<string, unknown>; handle: string }> = [];\n      for (const handle of handles) {\n        const original = await engineRetrieve(handle, undefined, engineBin);\n        let parsed: unknown;\n        try {\n          parsed = JSON.parse(new TextDecoder().decode(original));\n        } catch {\n          continue;\n        }\n        if (!isRecord(parsed) || typeof parsed.name !== \"string\" ||\n            typeof parsed.description !== \"string\" || !isRecord(parsed.input)) continue;\n        const haystack = `${parsed.name} ${parsed.description} ${JSON.stringify(parsed.input)}`.toLowerCase();\n        const score = terms.reduce((total, term) => total + (haystack.includes(term) ? 1 : 0), 0);\n        if (score > 0) hits.push({ score, value: parsed, handle });\n      }\n      hits.sort((first, second) => second.score - first.score ||\n        String(first.value.name).localeCompare(String(second.value.name)));","sourceCodeStart":3049,"sourceCodeEnd":3085,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3049-L3085","documentation":"The built-in `cave_search_tools` recovery tool throws `cave_tool_search_query_required` when the model calls it with a `query` that is empty or whitespace-only after trimming/lowercasing. The tool searches the original, un-compacted tool definitions stored in the engine, so without a query it cannot rank or select anything. The throw happens inside `execute` and surfaces as a normal tool-call error in the agent loop.","triggerScenarios":"Calling `cave_search_tools` with `{ query: \"\" }`, `{ query: \"   \" }`, or when the model omits/garbles the query parameter so the trimmed string is empty.","commonSituations":"A model hallucinating an empty argument during context-compaction recovery; a wrapper that passes through an unset variable as the query; string interpolation producing an empty string.","solutions":["Supply a non-empty `query` string containing terms from the tool name/description you are looking for.","If a caller wraps this tool, validate the query is non-blank before forwarding and retry with a real query.","If the model repeatedly sends empty queries, restate the task or the needed tool name in the prompt so it can form a search term."],"exampleFix":"// before\nawait agent.run(\"find a tool\", { /* model calls cave_search_tools with query: \"\" */ });\n// after\nawait agent.run(\"Use cave_search_tools with a non-empty query, e.g. query=\\\"read file\\\", to locate the file-reading tool.\");","handlingStrategy":"validation","validationCode":"function canSearch(query: unknown): query is string {\n  return typeof query === \"string\" && query.trim().length > 0;\n}\nif (!canSearch(args.query)) throw new Error(\"supply a non-empty query for cave_search_tools\");","typeGuard":"const hasQuery = (p: unknown): p is { query: string } =>\n  typeof p === \"object\" && p !== null && typeof (p as { query?: unknown }).query === \"string\";","tryCatchPattern":"try {\n  await tools.cave_search_tools.execute(id, { query });\n} catch (e) {\n  if ((e as Error).message === \"cave_tool_search_query_required\") {\n    return tools.cave_search_tools.execute(id, { query: fallbackQuery });\n  }\n  throw e;\n}","preventionTips":["Never pass user/model-supplied strings to the query without trimming and checking non-empty.","Prompt the model with an example non-empty query for the tool.","Validate tool arguments at the wrapper level before forwarding to execute."],"tags":["tool-call","validation","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}