alibaba/spring-ai-alibaba · error · ResponseStatusException
Error creating thread
Error message
Error creating thread
What it means
ThreadController.createThreadWithId wraps any exception thrown while creating a thread (excluding the handled NOT_FOUND from the duplicate probe) and rethrows it as 500 INTERNAL_SERVER_ERROR 'Error creating thread' with the original as cause. It is the generic catch-all for failures inside the reactive creation pipeline (store errors, serialization, connection failures).
Source
Thrown at spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/ThreadController.java:214
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.
* @param state Optional initial state for the thread.
* @return The newly created Thread object.
* @throws ResponseStatusException if creation fails (INTERNAL_SERVER_ERROR).
*/
@PostMapping("/apps/{appName}/users/{userId}/threads")
public Thread createThread(
@PathVariable String appName,
@PathVariable String userId,
@RequestBody(required = false) Map<String, Object> state) {View on GitHub (pinned to f82da0b50f)
Solutions
- Inspect the server log entry 'Error creating thread with id {threadId}' for the root-cause stack trace (kept as the exception cause)
- Verify thread store connectivity and credentials
- Ensure the initial state map contains serializable values compatible with the store
- Retry with a smaller/simpler state to isolate state-serialization problems
- If using a custom ThreadService, run its tests against the configured backend
Example fix
// before
state.put("conn", someNonSerializableObject);
// after
state.put("conn", someNonSerializableObject.toString()); // store-serializable value Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check state before sending
for (Object v : state.values()) {
try (ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream())) { oos.writeObject(v); }
catch (NotSerializableException e) { throw new IllegalArgumentException("state value not serializable: " + v.getClass()); }
} Try / catch
try { return createThread(state); } catch (HttpServerErrorException.InternalServerError e) { // inspect server-side cause; check store connectivity; retry after fix } Prevention
- Send only JSON-serializable values in initial state
- Pre-verify thread store connectivity in startup probes
- Watch backend logs for write errors matching creation attempts
- Version-check store schema after studio upgrades
When it happens
Trigger: threadService.createThread(...).block() throwing: datastore connection failures, write errors, serialization errors on the initial state map, or any RuntimeException raised by a custom ThreadService.
Common situations: Redis/DB credentials wrong or network unreachable; oversized or non-serializable initial state values; storage schema mismatch after version upgrade; custom ThreadService bugs.
Related errors
- Failed to create thread
- Failed to create thread (null result)
- 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/8d44125e06c888d4.
Report an issue: GitHub.