{"record":{"id":"84b33ebfdd6d8d50","repo":"spring-projects/spring-ai","slug":"no-sessionid-provided-in-toolsearchrequest-return","errorCode":null,"errorMessage":"No sessionId provided in ToolSearchRequest, returning empty results","messagePattern":"No sessionId provided in ToolSearchRequest, returning empty results","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-tool-search-tool/src/main/java/org/springframework/ai/tool/toolsearch/index/lucene/LuceneToolIndex.java","lineNumber":152,"sourceCode":"\n\t@Override\n\tpublic void indexTool(String sessionId, ToolReference toolReference) {\n\t\tthis.add(sessionId, String.valueOf(this.counter.getAndIncrement()), toolReference.toolName(),\n\t\t\t\ttoolReference.summary());\n\t}\n\n\t@Override\n\tpublic void indexTools(String sessionId, List<ToolReference> toolReferences) {\n\t\tfor (ToolReference ref : toolReferences) {\n\t\t\tthis.add(sessionId, String.valueOf(this.counter.getAndIncrement()), ref.toolName(), ref.summary());\n\t\t}\n\t}\n\n\t@Override\n\tpublic ToolSearchResponse search(ToolSearchRequest toolSearchRequest) {\n\t\tString sessionId = toolSearchRequest.sessionId();\n\t\tif (sessionId == null || sessionId.isBlank()) {\n\t\t\tlogger.warn(\"No sessionId provided in ToolSearchRequest, returning empty results\");\n\t\t\treturn ToolSearchResponse.builder().build();\n\t\t}\n\n\t\tSessionIndex sessionIndex = this.sessionIndexes.get(sessionId);\n\t\tif (sessionIndex == null) {\n\t\t\tlogger.debug(\"No index found for session: \" + sessionId);\n\t\t\treturn ToolSearchResponse.builder().build();\n\t\t}\n\n\t\treturn this.doSearch(sessionIndex, toolSearchRequest.query(),\n\t\t\t\ttoolSearchRequest.maxResults() != null ? toolSearchRequest.maxResults() : DEFAULT_MAX_RESULTS,\n\t\t\t\tthis.minScoreThreshold);\n\t}\n\n\t/**\n\t * Adds a single tool to the index for the specified session.\n\t * <p>\n\t * <b>Thread-safety note:</b> a narrow write-after-close race exists when","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-tool-search-tool/src/main/java/org/springframework/ai/tool/toolsearch/index/lucene/LuceneToolIndex.java#L134-L170","documentation":"LuceneToolIndex.search requires a sessionId to locate the per-session Lucene index. When ToolSearchRequest.sessionId is null or blank, it logs this warning and returns an empty ToolSearchResponse instead of searching, because there is no session scope to search within.","triggerScenarios":"Calling search(new ToolSearchRequest(query, ...)) without setting sessionId, or passing an empty/whitespace sessionId string, against a LuceneToolIndex.","commonSituations":"Building ToolSearchRequest manually in tests or custom tool-search delegates and forgetting the sessionId; a client that doesn't propagate session IDs from the conversation; migrating code written for sessionless indexes.","solutions":["Set a non-blank sessionId on the ToolSearchRequest before calling search.","Propagate the session ID from the caller context (e.g. from the agent conversation) into every request.","If session isolation is unnecessary, use an index implementation configured without session scoping.","Handle the empty ToolSearchResponse gracefully — it means the request was rejected for lack of sessionId, not that no tools matched."],"exampleFix":"// before\nvar resp = luceneToolIndex.search(ToolSearchRequest.builder().query(\"weather\").maxResults(5).build());\n// after\nvar resp = luceneToolIndex.search(ToolSearchRequest.builder()\n    .sessionId(\"session-42\")\n    .query(\"weather\")\n    .maxResults(5)\n    .build());","handlingStrategy":"validation","validationCode":"if (request.sessionId() == null || request.sessionId().isBlank()) {\n    throw new IllegalArgumentException(\"sessionId is required for LuceneToolIndex.search\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build ToolSearchRequest with a non-blank sessionId.","Thread the session ID from the conversation context through all layers.","Add an assert/validator in request construction.","Unit-test tool search with a realistic session-scoped request."],"tags":["tool-search","lucene","missing-session-id","empty-result"],"backgroundTag":"empty-required-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}