{"record":{"id":"6db1cb0d88faf15e","repo":"jd-opensource/joyagent-jdgenie","slug":"sse-nl2sql-failed","errorCode":null,"errorMessage":"sse nl2sql failed:","messagePattern":"sse nl2sql failed:","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java","lineNumber":53,"sourceCode":"\n@Slf4j\n@Service\npublic class Nl2SqlService {\n    public static final String NL2SQL_URL = \"/v1/tool/nl2sql\";\n\n    @Autowired\n    DataAgentConfig dataAgentConfig;\n    @Autowired\n    JdbcDataProvider jdbcDataProvider;\n\n    public List<ChatQueryData> runNL2SQLSync(NL2SQLReq request) throws Exception {\n        AtomicReference<Throwable> err = new AtomicReference<>();\n        request.setStream(false);\n        String jsonResult = OkHttpUtil.postJsonBody(dataAgentConfig.getAgentUrl() + NL2SQL_URL, null, JSONObject.toJSONString(request));\n        log.info(\"{},{} nl2sql result without sse:{}\", request.getTraceId(), request.getRequestId(), jsonResult);\n        NL2SQLResult nl2SQLResult = JSONObject.parseObject(jsonResult, NL2SQLResult.class);\n        if (err.get() != null) {\n            throw new RuntimeException(\"sse nl2sql failed:\" + err.get().getMessage());\n        }\n        return nl2sqlQueryData(request, nl2SQLResult);\n    }\n\n    public List<ChatQueryData> runNL2SQLSse(NL2SQLReq request, SseEmitter emitter) throws Exception {\n        AtomicReference<Throwable> err = new AtomicReference<>();\n        Nl2SqlSseListener sqlSseListener = new Nl2SqlSseListener(emitter, request.getRequestId(), request.getTraceId());\n        OkHttpUtil.requestSse(dataAgentConfig.getAgentUrl() + NL2SQL_URL, null, JSONObject.toJSONString(request), sqlSseListener);\n        sqlSseListener.getCountDownLatch().await();\n        int eventCount = sqlSseListener.getEventCount();\n        log.info(\"{} sse event count:{}\", request.getRequestId(), eventCount);\n        if (!sqlSseListener.isSuccess()) {\n            throw new RuntimeException(\"sse listener failed \" + sqlSseListener.getErrorMessage());\n        }\n        NL2SQLResult nl2SQLResult = sqlSseListener.getNl2SQLResult();\n        if (err.get() != null) {\n            throw new RuntimeException(\"sse nl2sql failed:\" + err.get().getMessage());\n        }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java#L35-L71","documentation":"runNL2SQLSync posts the NL2SQL request synchronously to the Python agent and wraps any Throwable captured by the SSE listener/err AtomicReference in a RuntimeException. It means the underlying nl2sql HTTP/SSE call failed, and the original message is appended after the 'sse nl2sql failed:' prefix.","triggerScenarios":"The OkHttpUtil.postJsonBody call to dataAgentConfig.getAgentUrl() + NL2SQL_URL throws or the err reference is populated (network failure, agent error, callback exception) during runNL2SQLSync.","commonSituations":"Python nl2sql agent down or wrong agentUrl configured; timeouts on large schema prompts; serialization errors in the request; agent returning malformed JSON that breaks the listener callback.","solutions":["Read the suffixed original message after 'sse nl2sql failed:' to find the root cause","Verify dataAgentConfig.getAgentUrl() + NL2SQL_URL is reachable (curl the endpoint)","Retry the request; if transient network errors persist, add timeout/retry handling in OkHttpUtil usage"],"exampleFix":"// before\nthrow new RuntimeException(\"sse nl2sql failed:\" + err.get().getMessage());\n// after\nThrowable cause = err.get();\nthrow new RuntimeException(\"sse nl2sql failed:\" + cause.getMessage(), cause);","handlingStrategy":"try-catch","validationCode":"// pre-check agent reachability\nboolean up = java.net.InetAddress.getByName(new java.net.URL(dataAgentConfig.getAgentUrl()).getHost()).isReachable(3000);\nif (!up) { throw new IllegalStateException(\"nl2sql agent unreachable\"); }","typeGuard":null,"tryCatchPattern":"try {\n    return nl2SqlService.runNL2SQLSync(request);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"sse nl2sql failed:\")) {\n        // inspect root cause, retry or degrade\n    }\n    throw e;\n}","preventionTips":["Health-check the agent URL before requests","Set explicit OkHttp timeouts","Always capture the original Throwable as cause"],"tags":["http","sse","nl2sql","upstream"],"backgroundTag":"upstream-api-error","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}