{"record":{"id":"eced5ed7a50c2ec2","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-create-thread","errorCode":null,"errorMessage":"Failed to create thread","messagePattern":"Failed to create thread","errorType":"http","errorClass":"ResponseStatusException","httpStatus":500,"severity":"error","filePath":"spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphThreadController.java","lineNumber":153,"sourceCode":"\t\tString appName = toAppName(graphName);\n\n\t\ttry {\n\t\t\tfindThreadOrThrow(graphName, userId, threadId);\n\t\t\tthrow new ResponseStatusException(HttpStatus.BAD_REQUEST, \"Thread already exists: \" + threadId);\n\t\t}\n\t\tcatch (ResponseStatusException e) {\n\t\t\tif (e.getStatusCode() != HttpStatus.NOT_FOUND) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\n\t\tMap<String, Object> initialState = (state != null) ? state : Collections.emptyMap();\n\t\tThread createdThread = threadService\n\t\t\t\t.createThread(appName, userId, new ConcurrentHashMap<>(initialState), threadId)\n\t\t\t\t.block();\n\n\t\tif (createdThread == null) {\n\t\t\tthrow new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, \"Failed to create thread\");\n\t\t}\n\t\treturn createdThread;\n\t}\n\n\t@PostMapping(\"/graphs/{graphName}/users/{userId}/threads\")\n\tpublic Thread createThread(\n\t\t\t@PathVariable String graphName,\n\t\t\t@PathVariable String userId,\n\t\t\t@RequestBody(required = false) Map<String, Object> state) {\n\t\tvalidateGraphExists(graphName);\n\t\tString appName = toAppName(graphName);\n\t\tMap<String, Object> initialState = (state != null && !state.isEmpty()) ? state : null;\n\n\t\tThread createdThread = threadService\n\t\t\t\t.createThread(appName, userId,\n\t\t\t\t\t\t(initialState != null) ? new ConcurrentHashMap<>(initialState) : null,\n\t\t\t\t\t\tnull)\n\t\t\t\t.block();","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphThreadController.java#L135-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect server logs for the underlying ThreadService/persistence error before this point","Verify the thread store backend (Redis/DB/in-memory) is configured, reachable and writable","If using a custom ThreadService, ensure createThread's Mono emits the created Thread (Mono.just(thread) or flatMap returning it)","Retry the creation; if the duplicate check now finds the thread, the thread actually exists and the null was a service bug","Check application configuration for the studio thread persistence properties"],"exampleFix":"// before (custom ThreadService)\npublic Mono<Thread> createThread(...) { repo.save(t); return Mono.empty(); }\n// after\npublic Mono<Thread> createThread(...) { return repo.save(t).thenReturn(t); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { thread = create(...) } catch (HttpServerErrorException.InternalServerError e) { // check server logs / retry once, then verify via GET }","preventionTips":["Use a persistent, health-checked thread store backend","If implementing ThreadService, always emit the created Thread from createThread","Monitor persistence backend health before studio startup","After a 500, list threads to detect partial creation"],"tags":["http","internal-server-error","reactive","thread-management"],"backgroundTag":"empty-result-set","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}