{"record":{"id":"4f07110bae72ef59","repo":"iflytek/astron-agent","slug":"insufficient-permissions-responseenum","errorCode":"INSUFFICIENT_PERMISSIONS","errorMessage":"ResponseEnum.INSUFFICIENT_PERMISSIONS","messagePattern":"ResponseEnum\\.INSUFFICIENT_PERMISSIONS","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/impl/AgentMemoryServiceImpl.java","lineNumber":229,"sourceCode":"        dto.setBotId(botId);\n        dto.setProvider(Mem0MemoryProvider.PROVIDER);\n        dto.setEnabled(false);\n        dto.setHasApiKey(false);\n        dto.setAutoSearch(true);\n        dto.setSearchTopK(DEFAULT_TOP_K);\n        dto.setMinScore(DEFAULT_MIN_SCORE);\n        return dto;\n    }\n\n    private void validateUser(String uid) {\n        if (StringUtils.isBlank(uid)) {\n            throw new BusinessException(ResponseEnum.UNAUTHORIZED);\n        }\n    }\n\n    private void checkBotPermission(String uid, Long spaceId, Integer botId) {\n        if (botId == null || chatBotBaseMapper.checkBotPermission(botId, uid, spaceId) <= 0) {\n            throw new BusinessException(ResponseEnum.INSUFFICIENT_PERMISSIONS);\n        }\n    }\n\n    private void addSpaceCondition(LambdaQueryWrapper<AgentMemoryConfig> queryWrapper, Long spaceId) {\n        queryWrapper.eq(AgentMemoryConfig::getSpaceId, toStoredSpaceId(spaceId));\n    }\n\n    private String normalizeProvider(String provider) {\n        String normalized = StringUtils.upperCase(StringUtils.trimToEmpty(provider));\n        return StringUtils.isBlank(normalized) ? Mem0MemoryProvider.PROVIDER : normalized;\n    }\n\n    private int normalizeTopK(Integer topK) {\n        int value = topK == null ? DEFAULT_TOP_K : topK;\n        return Math.max(MIN_TOP_K, Math.min(MAX_TOP_K, value));\n    }\n\n    private double normalizeMinScore(Double minScore) {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/impl/AgentMemoryServiceImpl.java#L211-L247","documentation":"checkBotPermission throws INSUFFICIENT_PERMISSIONS when botId is null or the chatBotBaseMapper.checkBotPermission query returns <= 0, i.e. the user has no access to that bot within the given space. The bot exists elsewhere, belongs to another user, or is outside the space.","triggerScenarios":"Calling getConfig/saveConfig/listMemories/deleteMemory/clearMemories with a botId the authenticated uid cannot access in the given spaceId, or with botId=null passing the earlier null-body check.","commonSituations":"Sharing a bot id between teammates without granting access; wrong spaceId (bot lives in another workspace); frontend cache holding a bot from a previous account.","solutions":["Verify the botId belongs to the requesting user in the given space (check chat_bot_base ownership/space columns).","Grant the user access to the bot in that space if sharing is intended.","Send the correct spaceId matching where the bot was created."],"exampleFix":"// before\nmemSvc.listMemories(uid, wrongSpaceId, botIdOfOtherSpace); // throws\n// after\nLong spaceId = botService.getSpaceIdOfBot(botId); // resolve correct space\nmemSvc.listMemories(uid, spaceId, botId);","handlingStrategy":"validation","validationCode":"const bot = await fetchBot(botId); if (!bot || bot.spaceId !== currentSpaceId) { throw new Error('no access to bot in this space'); }","typeGuard":"boolean canUseBot(bot, uid, spaceId) { return bot != null && bot.uid === uid && bot.spaceId === spaceId; }","tryCatchPattern":"try { await memApi.listMemories(botId, spaceId); } catch (e) { if (e.code === 'INSUFFICIENT_PERMISSIONS') { showNoAccessMessage(); } }","preventionTips":["Resolve botId and spaceId from the same source of truth (the bot detail API).","Clear cached bot ids when switching accounts or workspaces.","Grant collaborators access instead of sharing raw ids."],"tags":["permissions","authorization","multi-tenant"],"backgroundTag":"insufficient-permissions","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"}