{"record":{"id":"8d44125e06c888d4","repo":"alibaba/spring-ai-alibaba","slug":"error-creating-thread","errorCode":null,"errorMessage":"Error creating thread","messagePattern":"Error creating thread","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":214,"sourceCode":"\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.\n\t * @param state Optional initial state for the thread.\n\t * @return The newly created Thread object.\n\t * @throws ResponseStatusException if creation fails (INTERNAL_SERVER_ERROR).\n\t */\n\t@PostMapping(\"/apps/{appName}/users/{userId}/threads\")\n\tpublic Thread createThread(\n\t\t\t@PathVariable String appName,\n\t\t\t@PathVariable String userId,\n\t\t\t@RequestBody(required = false) Map<String, Object> state) {","sourceCodeStart":196,"sourceCodeEnd":232,"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#L196-L232","documentation":"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).","triggerScenarios":"threadService.createThread(...).block() throwing: datastore connection failures, write errors, serialization errors on the initial state map, or any RuntimeException raised by a custom ThreadService.","commonSituations":"Redis/DB credentials wrong or network unreachable; oversized or non-serializable initial state values; storage schema mismatch after version upgrade; custom ThreadService bugs.","solutions":["Inspect the server log entry 'Error creating thread with id {threadId}' for the root-cause stack trace (kept as the exception cause)","Verify thread store connectivity and credentials","Ensure the initial state map contains serializable values compatible with the store","Retry with a smaller/simpler state to isolate state-serialization problems","If using a custom ThreadService, run its tests against the configured backend"],"exampleFix":"// before\nstate.put(\"conn\", someNonSerializableObject);\n// after\nstate.put(\"conn\", someNonSerializableObject.toString()); // store-serializable value","handlingStrategy":"try-catch","validationCode":"// sanity-check state before sending\nfor (Object v : state.values()) {\n  try (ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream())) { oos.writeObject(v); }\n  catch (NotSerializableException e) { throw new IllegalArgumentException(\"state value not serializable: \" + v.getClass()); }\n}","typeGuard":null,"tryCatchPattern":"try { return createThread(state); } catch (HttpServerErrorException.InternalServerError e) { // inspect server-side cause; check store connectivity; retry after fix }","preventionTips":["Send only JSON-serializable values in initial state","Pre-verify thread store connectivity in startup probes","Watch backend logs for write errors matching creation attempts","Version-check store schema after studio upgrades"],"tags":["http","internal-server-error","reactive","thread-management"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}