alibaba/spring-ai-alibaba · error · RuntimeException
code execution failed!
Error message
code execution failed!
What it means
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.
Source
Thrown at 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:107
// 将代码运行的结果拆包
Map<String, Object> result = codeNodeAction.apply(state);
Object object = result.get(key);
if(!(object instanceof Map)) {
throw new RuntimeException("unexcepted result");
}
return ((Map<String, Object>) object).entrySet().stream()
.collect(Collectors.toMap(
entry -> nodeName + "_" + entry.getKey(),
Map.Entry::getValue
));
} catch (Exception e) {
Thread.sleep(retryIntervalMs);
}
}
if(defaultValue != null) {
return defaultValue;
} else {
throw new RuntimeException("code execution failed!");
}
};
}
""";
default -> "";
};
}
@Override
public List<String> getImports() {
return List.of("com.alibaba.cloud.ai.graph.node.code.CodeExecutorNodeAction",
"com.alibaba.cloud.ai.graph.node.code.entity.CodeExecutionConfig",
"com.alibaba.cloud.ai.graph.node.code.CodeExecutor",
"com.alibaba.cloud.ai.graph.node.code.LocalCommandlineCodeExecutor", "java.io.IOException",
"java.nio.file.Files", "java.nio.file.Path", "java.util.stream.Collectors",
"com.alibaba.cloud.ai.graph.node.code.entity.CodeParam",
"com.alibaba.cloud.ai.graph.node.code.entity.CodeStyle");
}View on GitHub (pinned to f82da0b50f)
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.
Example fix
// before
throw new RuntimeException("code execution failed!");
// after (node config)
retryCount: 3, retryIntervalMs: 500, defaultValue: Map.of("output", "") // or fix the script bug Defensive patterns
Strategy: fallback
Validate before calling
if (node.getDefaultValue() == null && node.getRetryCount() == 0)
warn("Code node has no default and no retries — failures will abort the workflow"); Try / catch
try { codeFn.apply(state); } catch (RuntimeException e) { if ("code execution failed!".equals(e.getMessage())) return defaultOrEmptyResult(); throw e; } Prevention
- 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
When it happens
Trigger: assistMethodCode-generated Function: codeNodeAction.apply(state) throws on every attempt (retries exhausted) and defaultValue == null at that call site.
Common situations: 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.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/8a7b99a62f453a72.
Report an issue: GitHub.