{"record":{"id":"e5beba3f7f6d09f5","repo":"iflytek/astron-agent","slug":"rpa-is-usage","errorCode":"RPA_IS_USAGE","errorMessage":"BusinessException(ResponseEnum.RPA_IS_USAGE)","messagePattern":"BusinessException\\(ResponseEnum\\.RPA_IS_USAGE\\)","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/RpaAssistantService.java","lineNumber":417,"sourceCode":"            BizWorkflowData bizWorkflowData;\n            try {\n                bizWorkflowData = JSON.parseObject(dataJson, BizWorkflowData.class);\n            } catch (Exception e) {\n                log.warn(\"Invalid workflow data JSON, workflowId={}\", workflow.getId(), e);\n                continue;\n            }\n\n            List<BizWorkflowNode> nodes = bizWorkflowData.getNodes();\n            if (CollUtil.isEmpty(nodes)) {\n                continue;\n            }\n\n            boolean inUse = nodes.stream()\n                    .filter(Objects::nonNull)\n                    .anyMatch(node -> isRpaNodeUsingAssistant(node, assistantId));\n\n            if (inUse) {\n                throw new BusinessException(ResponseEnum.RPA_IS_USAGE);\n            }\n        }\n    }\n\n    /**\n     * Check if a single node is an RPA node using the specified assistant.\n     *\n     * @param node workflow node\n     * @param assistantId assistant ID\n     * @return true if the node is an RPA node referencing the assistant\n     */\n    private boolean isRpaNodeUsingAssistant(BizWorkflowNode node, Long assistantId) {\n        if (node == null || StringUtils.isBlank(node.getId()) || node.getData() == null) {\n            return false;\n        }\n\n        String nodeId = node.getId();\n        // Defensive: only split once and handle missing prefix","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/RpaAssistantService.java#L399-L435","documentation":"checkRpaIsUsage throws BusinessException(RPA_IS_USAGE) when any node of the workflow being deleted still references the RPA assistant — the deletion guard prevents removing an RPA resource that is in use by workflow nodes.","triggerScenarios":"Calling delete(assistantId) while one or more workflow nodes still reference the assistant (matched via isRpaNodeUsingAssistant).","commonSituations":"Deleting an assistant that is wired into live workflows; bulk cleanup of unused-looking assistants that are actually referenced; stale local copy of workflows missing the reference.","solutions":["Remove or re-point the workflow nodes that use this assistant, then retry delete.","List referencing workflows first and confirm with the owner before deletion.","If intentional, delete the nodes and workflow versions referencing the assistant.","Catch RPA_IS_USAGE and return the list of referencing workflows to the user."],"exampleFix":"// before\nservice.delete(assistantId); // node still uses it\n// after\nworkflowService.removeAssistantFromNodes(assistantId);\nservice.delete(assistantId);","handlingStrategy":"try-catch","validationCode":"List<WorkflowNode> nodes = workflowService.findNodesUsingAssistant(assistantId);\nboolean safeToDelete = nodes.stream().filter(Objects::nonNull).noneMatch(n -> isRpaNodeUsingAssistant(n, assistantId));","typeGuard":null,"tryCatchPattern":"try { service.delete(id); } catch (BusinessException e) { if (ResponseEnum.RPA_IS_USAGE.equals(e.getCode())) { showReferencingWorkflows(workflowService.findWorkflowsUsingAssistant(id)); } else { throw e; } }","preventionTips":["Check references in the UI before enabling the delete button.","Clean up workflow nodes when decommissioning assistants.","Require explicit confirmation listing referencing workflows.","Add a cascade/detach option that removes references in one action."],"tags":["referential-integrity","delete-protection","workflow","java"],"backgroundTag":"invalid-state-transition","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}