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

  1. Read the server log line 'Thread creation call completed without error but returned null thread' and the preceding persistence errors
  2. Verify the thread store backend is healthy, reachable and writable
  3. Fix custom ThreadService.createThread so its Mono emits the created Thread
  4. Retry creation; confirm via GET whether the thread was actually persisted
  5. 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

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


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