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

  1. Inspect the server log entry 'Error creating thread with id {threadId}' for the root-cause stack trace (kept as the exception cause)
  2. Verify thread store connectivity and credentials
  3. Ensure the initial state map contains serializable values compatible with the store
  4. Retry with a smaller/simpler state to isolate state-serialization problems
  5. 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

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


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/8d44125e06c888d4. Report an issue: GitHub.