{"record":{"id":"859d43da019d7e57","repo":"iflytek/astron-agent","slug":"response-failed-assistant-name-already-exists","errorCode":"RESPONSE_FAILED","errorMessage":"Assistant name already exists: ","messagePattern":"Assistant name already exists: ","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":79,"sourceCode":"    private final ApiUrl apiUrl;\n\n    /**\n     * Create an RPA assistant with plaintext credentials.\n     *\n     * @param currentUserId current user ID\n     * @param req creation request\n     * @return created assistant response\n     * @throws IllegalArgumentException if the platform does not exist or field validation fails\n     */\n    @Transactional\n    public RpaAssistantResp create(String currentUserId, CreateRpaAssistantReq req) {\n        // 0. Idempotency check: same user, same assistant name is not allowed\n        long exists = assistantMapper.selectCount(\n                new LambdaQueryWrapper<RpaUserAssistant>()\n                        .eq(RpaUserAssistant::getUserId, currentUserId)\n                        .eq(RpaUserAssistant::getAssistantName, req.assistantName()));\n        if (exists > 0) {\n            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, \"Assistant name already exists: \" + req.assistantName());\n        }\n\n        // 1. Read rpa_info platform definition and parse field specs\n        List<PlatformFieldSpec> specs = loadPlatformSpecs(req.platformId());\n        Map<String, PlatformFieldSpec> specMap = specs.stream()\n                .collect(Collectors.toMap(PlatformFieldSpec::getName, s -> s, (a, b) -> a));\n\n        // 2. Validate required fields and types (only required & string check for now)\n        Integer count = validate(specMap, req.fields());\n\n        // 3. Insert main assistant record\n        String username = UserInfoManagerHandler.get().getUsername();\n        RpaUserAssistant assistant = new RpaUserAssistant();\n        assistant.setUserId(currentUserId);\n        assistant.setUserName(username);\n        assistant.setRobotCount(count);\n        assistant.setPlatformId(req.platformId());\n        assistant.setAssistantName(req.assistantName());","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/RpaAssistantService.java#L61-L97","documentation":"RpaAssistantService.create enforces per-user uniqueness of RPA assistant names. If a record with the same userId and assistantName already exists, it throws BusinessException(RESPONSE_FAILED) with 'Assistant name already exists: <name>'.","triggerScenarios":"POSTing a hot_load_callback / create request whose assistantName matches an existing assistant owned by the same user.","commonSituations":"Double-submitting a creation form; re-running an RPA load script that already succeeded; migrating assistants with colliding names.","solutions":["Query the user's existing assistant names first and pick a unique name.","If the existing record is the intended one, call the update endpoint instead of create.","Delete or rename the conflicting assistant, then retry creation.","Catch the exception in the callback and surface a friendly duplicate-name message to the UI."],"exampleFix":"// before\nservice.create(req with assistantName=\"bot1\"); // second call throws\n// after\nif (service.nameExists(userId, \"bot1\")) req = req.withName(\"bot1-v2\");\nservice.create(req);","handlingStrategy":"validation","validationCode":"long exists = assistantMapper.selectCount(new LambdaQueryWrapper<RpaUserAssistant>().eq(RpaUserAssistant::getUserId, uid).eq(RpaUserAssistant::getAssistantName, name));\nif (exists > 0) { /* resolve duplicate before create */ }","typeGuard":"boolean nameAvailable(String name, String uid) { return assistantMapper.selectCount(new LambdaQueryWrapper<RpaUserAssistant>().eq(RpaUserAssistant::getUserId, uid).eq(RpaUserAssistant::getAssistantName, name)) == 0; }","tryCatchPattern":"try { service.create(req); } catch (BusinessException e) { if (e.getMessage() != null && e.getMessage().startsWith(\"Assistant name already exists\")) { showDuplicateNameError(req.assistantName()); } else { throw e; } }","preventionTips":["Pre-check name availability with an API call before submit.","Uniquely suffix generated assistant names (timestamp/uuid).","Debounce/deduplicate submit buttons to avoid double posts.","Handle hot_load_callback idempotently with a client-side request id."],"tags":["duplicate","validation","uniqueness","java"],"backgroundTag":"file-already-exists","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"}