{"record":{"id":"c52980206e2afd17","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-create-thread-null-result","errorCode":null,"errorMessage":"Failed to create thread (null result)","messagePattern":"Failed to create thread \\(null result\\)","errorType":"http","errorClass":"ResponseStatusException","httpStatus":500,"severity":"error","filePath":"spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/ThreadController.java","lineNumber":205,"sourceCode":"\t\t\t\tthrow e;\n\t\t\t}\n\n\t\t\tlog.info(\"Thread {} not found, proceeding with creation.\", threadId);\n\t\t}\n\n\t\tMap<String, Object> initialState = (state != null) ? state : Collections.emptyMap();\n\t\ttry {\n\t\t\tThread createdThread =\n\t\t\t\t\tthreadService\n\t\t\t\t\t\t\t.createThread(appName, userId, new ConcurrentHashMap<>(initialState), threadId)\n\t\t\t\t\t\t\t.block();\n\n\t\t\tif (createdThread == null) {\n\n\t\t\t\tlog.error(\n\t\t\t\t\t\t\"Thread creation call completed without error but returned null thread for {}\",\n\t\t\t\t\t\tthreadId);\n\t\t\t\tthrow new ResponseStatusException(\n\t\t\t\t\t\tHttpStatus.INTERNAL_SERVER_ERROR, \"Failed to create thread (null result)\");\n\t\t\t}\n\t\t\tlog.info(\"Thread created successfully with id: {}\", createdThread.threadId());\n\t\t\treturn createdThread;\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tlog.error(\"Error creating thread with id {}\", threadId, e);\n\n\t\t\tthrow new ResponseStatusException(\n\t\t\t\t\tHttpStatus.INTERNAL_SERVER_ERROR, \"Error creating thread\", e);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a new thread where the ID is generated by the service.\n\t *\n\t * @param appName The application name.\n\t * @param userId The user ID.","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/ThreadController.java#L187-L223","documentation":"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.","triggerScenarios":"threadService.createThread(appName, userId, state, threadId).block() returning null due to an empty Mono from the backing thread store or a service implementation bug.","commonSituations":"Custom ThreadService whose createThread Mono is empty; persistence backend failing silently (write rejected but no exception propagated); storage connection pool exhaustion swallowed upstream.","solutions":["Read the server log line 'Thread creation call completed without error but returned null thread' and the preceding persistence errors","Verify the thread store backend is healthy, reachable and writable","Fix custom ThreadService.createThread so its Mono emits the created Thread","Retry creation; confirm via GET whether the thread was actually persisted","Check ThreadService/persistence bean configuration in the studio application"],"exampleFix":"// before\nreturn store.save(thread); // returns Mono.empty()\n// after\nreturn store.save(thread).switchIfEmpty(Mono.error(new IllegalStateException(\"save returned empty\")));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { thread = createWithId(id); } catch (HttpServerErrorException.InternalServerError e) { verifyAndRecreate(id); }","preventionTips":["Keep the thread store healthy and monitored","Custom ThreadService must emit the saved thread, never an empty Mono","Log-and-alert on empty Mono completions in service code","Verify creation with GET after any 500"],"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"}