alibaba/spring-ai-alibaba · error · ResponseStatusException

Failed to create thread

Error message

Failed to create thread

What it means

In GraphThreadController.createThreadWithId, after the duplicate check passes, the reactive ThreadService.createThread call is blocked; if it completes with null (no thread emitted), the controller throws a 500 INTERNAL_SERVER_ERROR 'Failed to create thread'. It signals the backend thread store accepted the call but produced no Thread record.

Source

Thrown at spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphThreadController.java:153

		String appName = toAppName(graphName);

		try {
			findThreadOrThrow(graphName, userId, threadId);
			throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Thread already exists: " + threadId);
		}
		catch (ResponseStatusException e) {
			if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
				throw e;
			}
		}

		Map<String, Object> initialState = (state != null) ? state : Collections.emptyMap();
		Thread createdThread = threadService
				.createThread(appName, userId, new ConcurrentHashMap<>(initialState), threadId)
				.block();

		if (createdThread == null) {
			throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create thread");
		}
		return createdThread;
	}

	@PostMapping("/graphs/{graphName}/users/{userId}/threads")
	public Thread createThread(
			@PathVariable String graphName,
			@PathVariable String userId,
			@RequestBody(required = false) Map<String, Object> state) {
		validateGraphExists(graphName);
		String appName = toAppName(graphName);
		Map<String, Object> initialState = (state != null && !state.isEmpty()) ? state : null;

		Thread createdThread = threadService
				.createThread(appName, userId,
						(initialState != null) ? new ConcurrentHashMap<>(initialState) : null,
						null)
				.block();

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Inspect server logs for the underlying ThreadService/persistence error before this point
  2. Verify the thread store backend (Redis/DB/in-memory) is configured, reachable and writable
  3. If using a custom ThreadService, ensure createThread's Mono emits the created Thread (Mono.just(thread) or flatMap returning it)
  4. Retry the creation; if the duplicate check now finds the thread, the thread actually exists and the null was a service bug
  5. Check application configuration for the studio thread persistence properties

Example fix

// before (custom ThreadService)
public Mono<Thread> createThread(...) { repo.save(t); return Mono.empty(); }
// after
public Mono<Thread> createThread(...) { return repo.save(t).thenReturn(t); }
Defensive patterns

Strategy: try-catch

Try / catch

try { thread = create(...) } catch (HttpServerErrorException.InternalServerError e) { // check server logs / retry once, then verify via GET }

Prevention

When it happens

Trigger: threadService.createThread(appName, userId, state, threadId).block() returning null Mono: an empty Mono from the service because the underlying store (in-memory map, Redis, DB) did not persist or return the created thread.

Common situations: Misconfigured or unavailable thread persistence backend that silently returns empty; a custom ThreadService implementation whose createThread forgets to emit the created Thread; races where the thread is deleted between creation and retrieval.

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/eced5ed7a50c2ec2. Report an issue: GitHub.