{"record":{"id":"dc85e9f26da3fc1a","repo":"alibaba/spring-ai-alibaba","slug":"error-dc85e9","errorCode":null,"errorMessage":"会话不存在: {}","messagePattern":"会话不存在: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/ChatSessionServiceImpl.java","lineNumber":77,"sourceCode":"    public ChatSession createEvaluatorSession(String prompt, String variables, String modelConfig) {\n        String sessionId = UUID.randomUUID().toString();\n        ModelConfigInfo modelConfigInfo = modelConfigParser.checkAndGetModelConfigInfo(modelConfig);\n        ChatSession session = ChatSession.builder().template(prompt).variables(variables).modelConfig(modelConfigInfo)\n                .sessionId(sessionId).createTime(System.currentTimeMillis()).lastUpdateTime(System.currentTimeMillis())\n                .build();\n        sessionStore.put(sessionId, session);\n        return session;\n    }\n    \n    @Override\n    public ChatSession getSession(String sessionId) {\n        if (sessionId == null || sessionId.trim().isEmpty()) {\n            return null;\n        }\n        \n        ChatSession session = sessionStore.get(sessionId);\n        if (session == null) {\n            log.warn(\"会话不存在: {}\", sessionId);\n            return null;\n        }\n        \n        // 检查会话是否过期\n        if (isSessionExpired(session)) {\n            log.info(\"会话已过期，删除: {}\", sessionId);\n            sessionStore.remove(sessionId);\n            return null;\n        }\n        \n        return session;\n    }\n    \n    @Override\n    public void updateSession(ChatSession session) {\n        if (session != null && session.getSessionId() != null) {\n            session.setLastUpdateTime(System.currentTimeMillis());\n            sessionStore.put(session.getSessionId(), session);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/ChatSessionServiceImpl.java#L59-L95","documentation":"ChatSessionServiceImpl.getSession looks up a session in the in-memory sessionStore by id. If the id is missing/blank it returns null quietly; if no session exists for the id it logs '会话不存在' (session not found) and returns null. Callers must handle a null return.","triggerScenarios":"session -> getSession with a sessionId that was never created, was already deleted, or belonged to a different server instance (in-memory store, not shared across replicas or lost on restart).","commonSituations":"Client retrying with an old sessionId after server restart; load balancer routing to a replica that doesn't hold the session; expired sessions evicted; hardcoded/stale session ids in tests.","solutions":["Verify the sessionId passed by the client is the one returned from session creation","Persist sessions in a shared store (Redis/DB) or enable sticky sessions for multi-instance deployments","Treat null return as 'session not found' and create a new session instead of proceeding","Check session expiry settings (isSessionExpired) — the session may have been evicted"],"exampleFix":"// before\nChatSession s = service.getSession(sessionId);\ns.getMessages(); // NPE if not found\n// after\nChatSession s = service.getSession(sessionId);\nif (s == null) { s = service.createSession(); }","handlingStrategy":"type-guard","validationCode":"if (sessionId == null || sessionId.isBlank()) throw new IllegalArgumentException(\"sessionId is required\");","typeGuard":"ChatSession s = service.getSession(sessionId);\nif (s == null) { /* treat as not-found: create new or return 404 */ }","tryCatchPattern":"ChatSession s = service.getSession(sessionId);\nif (s == null) {\n    return ResponseEntity.status(HttpStatus.NOT_FOUND).body(\"session not found: \" + sessionId);\n}","preventionTips":["Reuse the exact sessionId returned at creation time","Use sticky sessions or a shared session store behind multiple instances","Refresh session ids after server restarts; don't hardcode ids in tests","Check expiry windows if sessions disappear under load"],"tags":["session","in-memory-store","null-return"],"backgroundTag":"record-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}