{"record":{"id":"f3ff1e268e79b2e5","repo":"iflytek/astron-agent","slug":"duplicate-bot-name","errorCode":"DUPLICATE_BOT_NAME","errorMessage":"DUPLICATE_BOT_NAME","messagePattern":"DUPLICATE_BOT_NAME","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/commons/src/main/java/com/iflytek/astron/console/commons/service/bot/impl/BotServiceImpl.java","lineNumber":321,"sourceCode":"                throw new IllegalStateException(\"Distributed lock acquisition timeout, please try again later\");\n            }\n            return operation.get();\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new RuntimeException(\"Thread interrupted while acquiring lock\", e);\n        } catch (Exception e) {\n            log.error(\"Operation failed with lock: {}\", lockKey, e);\n            throw e;\n        } finally {\n            if (lock.isHeldByCurrentThread()) {\n                lock.unlock();\n            }\n        }\n    }\n\n    private void validateBotCreation(String uid, String botName, Long spaceId) {\n        if (chatBotDataService.checkRepeatBotName(uid, null, botName, spaceId)) {\n            throw new BusinessException(ResponseEnum.DUPLICATE_BOT_NAME);\n        }\n\n        Long count = (spaceId == null) ? chatBotDataService.countBotsByUid(uid) : chatBotDataService.countBotsByUid(uid, spaceId);\n\n        if (count.intValue() > 100) {\n            throw new BusinessException(ResponseEnum.TOO_MANY_BOTS);\n        }\n    }\n\n    private void validateBotNameForUpdate(String uid, String botName, Long spaceId) {\n        if (chatBotDataService.checkRepeatBotName(uid, null, botName, spaceId)) {\n            throw new BusinessException(ResponseEnum.DUPLICATE_BOT_NAME);\n        }\n    }\n\n    private void validateBotNameForUpdate(String uid, String botName, Integer botId, Long spaceId) {\n        if (chatBotDataService.checkRepeatBotName(uid, botId, botName, spaceId)) {\n            throw new BusinessException(ResponseEnum.DUPLICATE_BOT_NAME);","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/commons/src/main/java/com/iflytek/astron/console/commons/service/bot/impl/BotServiceImpl.java#L303-L339","documentation":"BusinessException with code DUPLICATE_BOT_NAME thrown by validateBotCreation when chatBotDataService.checkRepeatBotName reports the uid already owns a bot with the given name in the target space. Bot names must be unique per user/space, so creation is rejected before any persistence happens.","triggerScenarios":"Calling insertWorkflowBot or insertBotBasicInfo with a botName that already exists for the same uid (and same spaceId, when provided) — including case/whitespace variants if the DB check is not normalized.","commonSituations":"Users re-submitting a create form after a perceived failure when the bot was actually created; copying a bot and keeping the default name; automation/scripts that recreate bots idempotently without checking existing names.","solutions":["Rename the bot to a unique name before calling the create API.","Query the user's existing bot list first and pick a non-conflicting name.","If the duplicate is a leftover from a failed earlier attempt, delete the old bot or reuse it instead of creating a new one.","If the check is a false positive (e.g. deleted-but-not-purged bot), investigate soft-deleted records in chatBotDataService."],"exampleFix":"// before\nawait createBot({ botName: 'My Assistant', ... });\n// after\nconst existing = await listBots();\nif (existing.some(b => b.botName === 'My Assistant')) {\n  throw new Error('Name in use; choose another');\n}\nawait createBot({ botName: 'My Assistant v2', ... });","handlingStrategy":"validation","validationCode":"const names = (await listBots()).map(b => b.botName);\nif (names.includes(newName)) throw new Error('Bot name already in use');","typeGuard":null,"tryCatchPattern":"try { await createBot(form); } catch (e) { if (e.code === 'DUPLICATE_BOT_NAME') { promptUserToRename(); } else throw e; }","preventionTips":["Check existing bot names before submitting create","Auto-suggest unique names (append v2/timestamp) on conflict","Deduplicate name logic between create and copy features","Handle the error code explicitly in UI with a rename prompt"],"tags":["duplicate","validation","business-logic","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"}