{"record":{"id":"323665d78f7dea0e","repo":"iflytek/astron-agent","slug":"workflow-bad-response","errorCode":"WORKFLOW_BAD_RESPONSE","errorMessage":"Workflow returned an unreadable response.","messagePattern":"Workflow returned an unreadable response\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/workflow/AgentWorkflowRuntimeService.java","lineNumber":265,"sourceCode":"        schema.put(\"type\", \"object\");\n        schema.put(\"properties\", properties);\n        schema.put(\"required\", required);\n        return schema.toJSONString();\n    }\n\n    private boolean isFileInput(BizInputOutput input) {\n        return StringUtils.isNotBlank(input.getFileType())\n                || StringUtils.containsIgnoreCase(input.getCustomParameterType(), \"file\");\n    }\n\n    private String extractResult(AgentWorkflowDefinition definition, String responseBody) {\n        JSONObject json;\n        try {\n            json = JSON.parseObject(responseBody);\n        } catch (Exception e) {\n            log.warn(\"Invalid workflow response, flowId: {}\", definition.getFlowId());\n            return errorContent(\"WORKFLOW_BAD_RESPONSE\", \"Workflow returned an unreadable response.\");\n        }\n        if (json == null) {\n            return errorContent(\"WORKFLOW_EMPTY_RESPONSE\", \"Workflow returned an empty response.\");\n        }\n        Integer code = json.getInteger(\"code\");\n        if (code != null && code != 0) {\n            return errorContent(\"WORKFLOW_ERROR\",\n                    StringUtils.defaultIfBlank(json.getString(\"message\"), \"Workflow returned an error.\"));\n        }\n        if (json.get(\"event_data\") != null) {\n            return errorContent(\"WORKFLOW_INTERRUPT\",\n                    \"This workflow contains an interactive Q&A node and cannot run automatically in an agent chat.\");\n        }\n        JSONArray choices = json.getJSONArray(\"choices\");\n        if (choices != null) {\n            for (int i = 0; i < choices.size(); i++) {\n                JSONObject choice = choices.getJSONObject(i);\n                JSONObject delta = choice == null ? null : choice.getJSONObject(\"delta\");\n                String content = delta == null ? null : delta.getString(\"content\");","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/workflow/AgentWorkflowRuntimeService.java#L247-L283","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log a snippet of the raw responseBody (currently only flowId is logged) to see what was returned","Check gateway/nginx logs for 502/504 between toolkit and core/workflow","Verify the workflow invocation URL/content-type headers are correct for a JSON response","Check core/workflow service health and memory (mid-response crashes produce truncated bodies)","Add a content-type/status-code check before parsing to give a more precise error code"],"exampleFix":"// before\ntry {\n    json = JSON.parseObject(responseBody);\n} catch (Exception e) {\n    log.warn(\"Invalid workflow response, flowId: {}\", definition.getFlowId());\n    return errorContent(\"WORKFLOW_BAD_RESPONSE\", \"Workflow returned an unreadable response.\");\n}\n// after\ntry {\n    json = JSON.parseObject(responseBody);\n} catch (Exception e) {\n    log.warn(\"Invalid workflow response, flowId: {}, body: {}\", definition.getFlowId(), responseBody);\n    return errorContent(\"WORKFLOW_BAD_RESPONSE\", \"Workflow returned an unreadable response.\");\n}","handlingStrategy":"validation","validationCode":"if (!responseContentType.contains(\"application/json\")) return errorContent(\"WORKFLOW_BAD_RESPONSE\", \"non-JSON content-type\");","typeGuard":null,"tryCatchPattern":"try { json = JSON.parseObject(body); } catch (Exception e) { log.warn(\"bad body: {}\", body); return errorContent(\"WORKFLOW_BAD_RESPONSE\", \"unreadable\"); }","preventionTips":["Check HTTP status/Content-Type before parsing","Log a raw-body snippet on parse failure","Monitor gateway 502/504 rates between services","Contract-test the workflow response schema"],"tags":["workflow","json-parsing","http"],"backgroundTag":"invalid-json-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}