{"record":{"id":"8a7b99a62f453a72","repo":"alibaba/spring-ai-alibaba","slug":"code-execution-failed","errorCode":null,"errorMessage":"code execution failed!","messagePattern":"code execution failed!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/generator/workflow/sections/CodeNodeSection.java","lineNumber":107,"sourceCode":"\t\t\t\t\t\t                   // 将代码运行的结果拆包\n\t\t\t\t\t\t                   Map<String, Object> result = codeNodeAction.apply(state);\n\t\t\t\t\t\t                   Object object = result.get(key);\n\t\t\t\t\t\t                   if(!(object instanceof Map)) {\n\t\t\t\t\t\t                       throw new RuntimeException(\"unexcepted result\");\n\t\t\t\t\t\t                   }\n\t\t\t\t\t\t                   return ((Map<String, Object>) object).entrySet().stream()\n\t\t\t\t\t\t                           .collect(Collectors.toMap(\n\t\t\t\t\t\t                                   entry -> nodeName + \"_\" + entry.getKey(),\n\t\t\t\t\t\t                                   Map.Entry::getValue\n\t\t\t\t\t\t                           ));\n\t\t\t\t\t\t               } catch (Exception e) {\n\t\t\t\t\t\t                   Thread.sleep(retryIntervalMs);\n\t\t\t\t\t\t               }\n\t\t\t\t\t\t           }\n\t\t\t\t\t\t           if(defaultValue != null) {\n\t\t\t\t\t\t               return defaultValue;\n\t\t\t\t\t\t           } else {\n\t\t\t\t\t\t               throw new RuntimeException(\"code execution failed!\");\n\t\t\t\t\t\t           }\n\t\t\t\t\t\t       };\n\t\t\t\t\t\t   }\n\t\t\t\t\t\t\"\"\";\n\t\t\tdefault -> \"\";\n\t\t};\n\t}\n\n\t@Override\n\tpublic List<String> getImports() {\n\t\treturn List.of(\"com.alibaba.cloud.ai.graph.node.code.CodeExecutorNodeAction\",\n\t\t\t\t\"com.alibaba.cloud.ai.graph.node.code.entity.CodeExecutionConfig\",\n\t\t\t\t\"com.alibaba.cloud.ai.graph.node.code.CodeExecutor\",\n\t\t\t\t\"com.alibaba.cloud.ai.graph.node.code.LocalCommandlineCodeExecutor\", \"java.io.IOException\",\n\t\t\t\t\"java.nio.file.Files\", \"java.nio.file.Path\", \"java.util.stream.Collectors\",\n\t\t\t\t\"com.alibaba.cloud.ai.graph.node.code.entity.CodeParam\",\n\t\t\t\t\"com.alibaba.cloud.ai.graph.node.code.entity.CodeStyle\");\n\t}","sourceCodeStart":89,"sourceCodeEnd":125,"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/builder/generator/service/generator/workflow/sections/CodeNodeSection.java#L89-L125","documentation":"In the same generated CodeNode helper, if all retry attempts to execute the code node fail (after retries with retryIntervalMs sleeps), the function returns an optional defaultValue; when no default is configured it throws RuntimeException('code execution failed!'). It signals persistent failure of user-supplied code execution.","triggerScenarios":"assistMethodCode-generated Function: codeNodeAction.apply(state) throws on every attempt (retries exhausted) and defaultValue == null at that call site.","commonSituations":"User script has a runtime bug (NPE, syntax-level runtime failure); script times out or depends on unavailable services; state lacks inputs the script expects.","solutions":["Fix the underlying exception in the code node script — inspect the cause chain of this RuntimeException.","Configure a defaultValue on the code node so the workflow can continue when execution fails.","Increase retry count / retryIntervalMs on the node if failures are transient."],"exampleFix":"// before\nthrow new RuntimeException(\"code execution failed!\");\n// after  (node config)\nretryCount: 3, retryIntervalMs: 500, defaultValue: Map.of(\"output\", \"\")  // or fix the script bug","handlingStrategy":"fallback","validationCode":"if (node.getDefaultValue() == null && node.getRetryCount() == 0)\n    warn(\"Code node has no default and no retries — failures will abort the workflow\");","typeGuard":null,"tryCatchPattern":"try { codeFn.apply(state); } catch (RuntimeException e) { if (\"code execution failed!\".equals(e.getMessage())) return defaultOrEmptyResult(); throw e; }","preventionTips":["Always configure a defaultValue on production code nodes","Set sensible retryCount and retryIntervalMs for flaky dependencies","Test user scripts in isolation before deploying the workflow"],"tags":["code-node","retry-exhausted","workflow"],"backgroundTag":"retry-exhausted","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}