iflytek/astron-agent · error

WORKFLOW_BAD_RESPONSE

WORKFLOW_BAD_RESPONSE

Error message

Workflow returned an unreadable response.

What it means

AgentWorkflowRuntimeService.extractResult parses the workflow HTTP response body with fastjson. If parsing throws, the method logs 'Invalid workflow response' and returns error content with code WORKFLOW_BAD_RESPONSE. The workflow service did respond, but the body is not valid JSON or not an object, so no result can be extracted.

Solutions

  1. Log a snippet of the raw responseBody (currently only flowId is logged) to see what was returned
  2. Check gateway/nginx logs for 502/504 between toolkit and core/workflow
  3. Verify the workflow invocation URL/content-type headers are correct for a JSON response
  4. Check core/workflow service health and memory (mid-response crashes produce truncated bodies)
  5. Add a content-type/status-code check before parsing to give a more precise error code

Example fix

// before
try {
    json = JSON.parseObject(responseBody);
} catch (Exception e) {
    log.warn("Invalid workflow response, flowId: {}", definition.getFlowId());
    return errorContent("WORKFLOW_BAD_RESPONSE", "Workflow returned an unreadable response.");
}
// after
try {
    json = JSON.parseObject(responseBody);
} catch (Exception e) {
    log.warn("Invalid workflow response, flowId: {}, body: {}", definition.getFlowId(), responseBody);
    return errorContent("WORKFLOW_BAD_RESPONSE", "Workflow returned an unreadable response.");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!responseContentType.contains("application/json")) return errorContent("WORKFLOW_BAD_RESPONSE", "non-JSON content-type");

Try / catch

try { json = JSON.parseObject(body); } catch (Exception e) { log.warn("bad body: {}", body); return errorContent("WORKFLOW_BAD_RESPONSE", "unreadable"); }

Prevention

When it happens

Trigger: runWorkflow receives a response whose body makes JSON.parseObject throw: HTML error pages, gateway 502/504 text, truncated streamed output, or empty-but-nonnull garbage bytes from the core/workflow endpoint.

Common situations: nginx/gateway returning an HTML 502 page when core/workflow is overloaded; response compression/content-type mismatch; core/workflow crashing mid-response; wrong URL configured on the workflow definition pointing to a non-JSON endpoint.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/323665d78f7dea0e. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/workflow/AgentWorkflowRuntimeService.java:265

        schema.put("type", "object");
        schema.put("properties", properties);
        schema.put("required", required);
        return schema.toJSONString();
    }

    private boolean isFileInput(BizInputOutput input) {
        return StringUtils.isNotBlank(input.getFileType())
                || StringUtils.containsIgnoreCase(input.getCustomParameterType(), "file");
    }

    private String extractResult(AgentWorkflowDefinition definition, String responseBody) {
        JSONObject json;
        try {
            json = JSON.parseObject(responseBody);
        } catch (Exception e) {
            log.warn("Invalid workflow response, flowId: {}", definition.getFlowId());
            return errorContent("WORKFLOW_BAD_RESPONSE", "Workflow returned an unreadable response.");
        }
        if (json == null) {
            return errorContent("WORKFLOW_EMPTY_RESPONSE", "Workflow returned an empty response.");
        }
        Integer code = json.getInteger("code");
        if (code != null && code != 0) {
            return errorContent("WORKFLOW_ERROR",
                    StringUtils.defaultIfBlank(json.getString("message"), "Workflow returned an error."));
        }
        if (json.get("event_data") != null) {
            return errorContent("WORKFLOW_INTERRUPT",
                    "This workflow contains an interactive Q&A node and cannot run automatically in an agent chat.");
        }
        JSONArray choices = json.getJSONArray("choices");
        if (choices != null) {
            for (int i = 0; i < choices.size(); i++) {
                JSONObject choice = choices.getJSONObject(i);
                JSONObject delta = choice == null ? null : choice.getJSONObject("delta");
                String content = delta == null ? null : delta.getString("content");

View on GitHub (pinned to 5e758547a8)