spring-projects/spring-ai · warning
No sessionId provided in ToolSearchRequest, returning empty…
Error message
No sessionId provided in ToolSearchRequest, returning empty results
What it means
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.
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.
Example fix
// before
var resp = luceneToolIndex.search(ToolSearchRequest.builder().query("weather").maxResults(5).build());
// after
var resp = luceneToolIndex.search(ToolSearchRequest.builder()
.sessionId("session-42")
.query("weather")
.maxResults(5)
.build()); Defensive patterns
Strategy: validation
Validate before calling
if (request.sessionId() == null || request.sessionId().isBlank()) {
throw new IllegalArgumentException("sessionId is required for LuceneToolIndex.search");
} Prevention
- 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.
When it happens
Trigger: Calling search(new ToolSearchRequest(query, ...)) without setting sessionId, or passing an empty/whitespace sessionId string, against a LuceneToolIndex.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- No sessionId provided in ToolSearchRequest, returning empty…
- Skipping add for session
- Failed to add document to index
- Failed to clear the index for session:
- Failed to commit changes to index for session:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/84b33ebfdd6d8d50.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-tool-search-tool/src/main/java/org/springframework/ai/tool/toolsearch/index/lucene/LuceneToolIndex.java:152
@Override
public void indexTool(String sessionId, ToolReference toolReference) {
this.add(sessionId, String.valueOf(this.counter.getAndIncrement()), toolReference.toolName(),
toolReference.summary());
}
@Override
public void indexTools(String sessionId, List<ToolReference> toolReferences) {
for (ToolReference ref : toolReferences) {
this.add(sessionId, String.valueOf(this.counter.getAndIncrement()), ref.toolName(), ref.summary());
}
}
@Override
public ToolSearchResponse search(ToolSearchRequest toolSearchRequest) {
String sessionId = toolSearchRequest.sessionId();
if (sessionId == null || sessionId.isBlank()) {
logger.warn("No sessionId provided in ToolSearchRequest, returning empty results");
return ToolSearchResponse.builder().build();
}
SessionIndex sessionIndex = this.sessionIndexes.get(sessionId);
if (sessionIndex == null) {
logger.debug("No index found for session: " + sessionId);
return ToolSearchResponse.builder().build();
}
return this.doSearch(sessionIndex, toolSearchRequest.query(),
toolSearchRequest.maxResults() != null ? toolSearchRequest.maxResults() : DEFAULT_MAX_RESULTS,
this.minScoreThreshold);
}
/**
* Adds a single tool to the index for the specified session.
* <p>
* <b>Thread-safety note:</b> a narrow write-after-close race exists whenView on GitHub (pinned to 98a7beda4f)