jd-opensource/joyagent-jdgenie · error · RuntimeException
sse nl2sql failed:
Error message
sse nl2sql failed:
What it means
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.
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
Example fix
// before
throw new RuntimeException("sse nl2sql failed:" + err.get().getMessage());
// after
Throwable cause = err.get();
throw new RuntimeException("sse nl2sql failed:" + cause.getMessage(), cause); Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check agent reachability
boolean up = java.net.InetAddress.getByName(new java.net.URL(dataAgentConfig.getAgentUrl()).getHost()).isReachable(3000);
if (!up) { throw new IllegalStateException("nl2sql agent unreachable"); } Try / catch
try {
return nl2SqlService.runNL2SQLSync(request);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("sse nl2sql failed:")) {
// inspect root cause, retry or degrade
}
throw e;
} Prevention
- Health-check the agent URL before requests
- Set explicit OkHttp timeouts
- Always capture the original Throwable as cause
When it happens
Trigger: The OkHttpUtil.postJsonBody call to dataAgentConfig.getAgentUrl() + NL2SQL_URL throws or the err reference is populated (network failure, agent error, callback exception) during runNL2SQLSync.
Common situations: 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.
Related errors
- sse listener failed
- nl2sql server return error:
- 调用接口" + url + "失败:" + response.message()
- nl2sql返回对象为空
- nl2sql result is null
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/6db1cb0d88faf15e.
Report an issue: GitHub.
Appendix: source
Thrown at genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java:53
@Slf4j
@Service
public class Nl2SqlService {
public static final String NL2SQL_URL = "/v1/tool/nl2sql";
@Autowired
DataAgentConfig dataAgentConfig;
@Autowired
JdbcDataProvider jdbcDataProvider;
public List<ChatQueryData> runNL2SQLSync(NL2SQLReq request) throws Exception {
AtomicReference<Throwable> err = new AtomicReference<>();
request.setStream(false);
String jsonResult = OkHttpUtil.postJsonBody(dataAgentConfig.getAgentUrl() + NL2SQL_URL, null, JSONObject.toJSONString(request));
log.info("{},{} nl2sql result without sse:{}", request.getTraceId(), request.getRequestId(), jsonResult);
NL2SQLResult nl2SQLResult = JSONObject.parseObject(jsonResult, NL2SQLResult.class);
if (err.get() != null) {
throw new RuntimeException("sse nl2sql failed:" + err.get().getMessage());
}
return nl2sqlQueryData(request, nl2SQLResult);
}
public List<ChatQueryData> runNL2SQLSse(NL2SQLReq request, SseEmitter emitter) throws Exception {
AtomicReference<Throwable> err = new AtomicReference<>();
Nl2SqlSseListener sqlSseListener = new Nl2SqlSseListener(emitter, request.getRequestId(), request.getTraceId());
OkHttpUtil.requestSse(dataAgentConfig.getAgentUrl() + NL2SQL_URL, null, JSONObject.toJSONString(request), sqlSseListener);
sqlSseListener.getCountDownLatch().await();
int eventCount = sqlSseListener.getEventCount();
log.info("{} sse event count:{}", request.getRequestId(), eventCount);
if (!sqlSseListener.isSuccess()) {
throw new RuntimeException("sse listener failed " + sqlSseListener.getErrorMessage());
}
NL2SQLResult nl2SQLResult = sqlSseListener.getNl2SQLResult();
if (err.get() != null) {
throw new RuntimeException("sse nl2sql failed:" + err.get().getMessage());
}View on GitHub (pinned to 2417e0b8b6)