alibaba/spring-ai-alibaba · error · ResponseStatusException
Failed to create thread (null result)
Error message
Failed to create thread (null result)
What it means
In ThreadController.createThreadWithId, if the blocked threadService.createThread call completes without error but emits null, the controller throws 500 INTERNAL_SERVER_ERROR 'Failed to create thread (null result)'. This indicates the reactive pipeline returned empty rather than the newly created Thread record.
Source
Thrown at spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/ThreadController.java:205
throw e;
}
log.info("Thread {} not found, proceeding with creation.", threadId);
}
Map<String, Object> initialState = (state != null) ? state : Collections.emptyMap();
try {
Thread createdThread =
threadService
.createThread(appName, userId, new ConcurrentHashMap<>(initialState), threadId)
.block();
if (createdThread == null) {
log.error(
"Thread creation call completed without error but returned null thread for {}",
threadId);
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create thread (null result)");
}
log.info("Thread created successfully with id: {}", createdThread.threadId());
return createdThread;
}
catch (Exception e) {
log.error("Error creating thread with id {}", threadId, e);
throw new ResponseStatusException(
HttpStatus.INTERNAL_SERVER_ERROR, "Error creating thread", e);
}
}
/**
* Creates a new thread where the ID is generated by the service.
*
* @param appName The application name.
* @param userId The user ID.View on GitHub (pinned to f82da0b50f)
Solutions
- Read the server log line 'Thread creation call completed without error but returned null thread' and the preceding persistence errors
- Verify the thread store backend is healthy, reachable and writable
- Fix custom ThreadService.createThread so its Mono emits the created Thread
- Retry creation; confirm via GET whether the thread was actually persisted
- Check ThreadService/persistence bean configuration in the studio application
Example fix
// before
return store.save(thread); // returns Mono.empty()
// after
return store.save(thread).switchIfEmpty(Mono.error(new IllegalStateException("save returned empty"))); Defensive patterns
Strategy: try-catch
Try / catch
try { thread = createWithId(id); } catch (HttpServerErrorException.InternalServerError e) { verifyAndRecreate(id); } Prevention
- Keep the thread store healthy and monitored
- Custom ThreadService must emit the saved thread, never an empty Mono
- Log-and-alert on empty Mono completions in service code
- Verify creation with GET after any 500
When it happens
Trigger: threadService.createThread(appName, userId, state, threadId).block() returning null due to an empty Mono from the backing thread store or a service implementation bug.
Common situations: Custom ThreadService whose createThread Mono is empty; persistence backend failing silently (write rejected but no exception propagated); storage connection pool exhaustion swallowed upstream.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- Failed to create thread
- Error creating thread
- Thread already exists:
- Thread not found: appName=%s, userId=%s, threadId=%s
- Thread found but belongs to a different app/user.
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/c52980206e2afd17.
Report an issue: GitHub.