{"record":{"id":"641bca93b4eea326","repo":"iflytek/astron-agent","slug":"bot-not-exists-641bca","errorCode":"BOT_NOT_EXISTS","errorMessage":"BOT_NOT_EXISTS","messagePattern":"BOT_NOT_EXISTS","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/publish/impl/McpServiceImpl.java","lineNumber":54,"sourceCode":"    private final UserLangChainInfoMapper userLangChainInfoMapper;\n    private final BotPublishService botPublishService;\n    private final WorkflowReleaseService workflowReleaseService;\n    private final UserLangChainDataService userLangChainDataService;\n\n\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void publishMcp(McpPublishRequestDto request, String currentUid, Long spaceId) {\n        log.info(\"Publish MCP: botId={}, serverName={}, uid={}, spaceId={}\",\n                request.getBotId(), request.getServerName(), currentUid, spaceId);\n\n        Integer botId = request.getBotId();\n\n        // 1. Permission check\n        int hasPermission = chatBotBaseMapper.checkBotPermission(botId, currentUid, spaceId);\n        if (hasPermission == 0) {\n            throw new BusinessException(ResponseEnum.BOT_NOT_EXISTS);\n        }\n\n        // 2. Check if workflow protocol exists\n        UserLangChainInfo chainInfo = userLangChainInfoMapper.selectOne(\n                new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<UserLangChainInfo>()\n                        .eq(\"bot_id\", botId)\n                        .orderByDesc(\"create_time\")\n                        .last(\"LIMIT 1\"));\n        if (chainInfo == null) {\n            log.info(\"Bot workflow protocol not found: uid={}, botId={}\", currentUid, botId);\n            throw new BusinessException(ResponseEnum.BOT_CHAIN_SUBMIT_ERROR);\n        }\n\n        // 3. Content moderation (simplified here, should call moderation service in production)\n        // TODO: Call moderation service to check text and images\n        // String allText = request.getServerName() + request.getDescription() + request.getContent();\n\n        // 4. Get version name first (without releasing yet)","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/publish/impl/McpServiceImpl.java#L36-L72","documentation":"BOT_NOT_EXISTS is thrown by publishMcp when the pre-publish permission check fails: chatBotBaseMapper.checkBotPermission returns 0, meaning no chat bot row is visible to the given user in the given space. The platform reuses this code both for 'bot does not exist' and 'caller lacks permission', so the botId may be valid but simply owned by someone else or in another space.","triggerScenarios":"Calling POST MCP publish with a botId that does not exist, a botId belonging to another space, a bot deleted (soft-deleted), or a currentUid that is not an owner/editor of the bot.","commonSituations":"Stale frontend state publishing after the bot was deleted; cross-space API calls where spaceId header/token doesn't match the bot's space; typos or int/long conversion of botId; publishing from automation using a service account without bot access.","solutions":["Verify the botId exists and belongs to the current user + spaceId before calling publishMcp (query chat_bot_base with uid/space filters).","Confirm the spaceId passed to the service matches the space that owns the bot.","If the bot was deleted, recreate or restore it and retry publish.","Check the calling account's role/permission on the bot (owner vs viewer)."],"exampleFix":"// before\nmcpService.publishMcp(new McpPublishRequestDto(99999 /* stale botId */), uid, spaceId);\n// after\nChatBotBase bot = chatBotDataService.findOne(uid, 99999, spaceId);\nif (bot == null) {\n    throw new BusinessException(ResponseEnum.BOT_NOT_EXISTS); // fail fast with clear context\n}\nmcpService.publishMcp(request, uid, spaceId);","handlingStrategy":"validation","validationCode":"int hasPermission = chatBotBaseMapper.checkBotPermission(botId, uid, spaceId);\nif (hasPermission == 0) { throw new BusinessException(ResponseEnum.BOT_NOT_EXISTS); }","typeGuard":"boolean canPublish = bot != null && bot.getSpaceId().equals(spaceId) && bot.getUid().equals(uid);","tryCatchPattern":null,"preventionTips":["Always pass the botId, uid, and spaceId from the same authenticated session/context.","Refresh bot lists after deletes to avoid stale IDs.","Pre-check bot existence in the UI before showing publish options."],"tags":["permission","bot-not-found","publish","mcp"],"backgroundTag":"permission-denied","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"}