{"record":{"id":"62f424ad3bc210f5","repo":"iflytek/astron-agent","slug":"invite-add-space-user-failed","errorCode":"INVITE_ADD_SPACE_USER_FAILED","errorMessage":"INVITE_ADD_SPACE_USER_FAILED","messagePattern":"INVITE_ADD_SPACE_USER_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/SpaceBizServiceImpl.java","lineNumber":116,"sourceCode":"            Long count = spaceService.countByUid(uid);\n            if (OrderInfoUtil.existValidProOrder(uid)) {\n                space.setType(SpaceTypeEnum.PRO.getCode());\n                if (count >= spaceLimitProperties.getPro().getSpaceCount()) {\n                    return ApiResult.error(ResponseEnum.SPACE_PERSONAL_PRO_MAX_EXCEEDED);\n                }\n            } else {\n                space.setType(SpaceTypeEnum.FREE.getCode());\n                if (count >= spaceLimitProperties.getFree().getSpaceCount()) {\n                    return ApiResult.error(ResponseEnum.SPACE_FREE_USER_MAX_EXCEEDED);\n                }\n\n            }\n        }\n        // Save space data\n        if (spaceService.save(space)) {\n            // Creator becomes space owner by default\n            if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {\n                throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED);\n            }\n            return ApiResult.success(space.getId());\n        } else {\n            return ApiResult.error(ResponseEnum.ENTERPRISE_CREATE_FAILED);\n        }\n    }\n\n    /**\n     * Delete space\n     *\n     * @param spaceId\n     * @param mobile\n     * @param verifyCode\n     * @return\n     */\n    @Override\n    @Transactional\n    public ApiResult<String> deleteSpace(Long spaceId, String mobile, String verifyCode) {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/SpaceBizServiceImpl.java#L98-L134","documentation":"INVITE_ADD_SPACE_USER_FAILED is thrown by SpaceBizServiceImpl.create when spaceUserService.addSpaceUser fails to insert the creator as OWNER right after the space row itself was saved successfully. It indicates the space exists but its owner membership row could not be created, leaving a space with no owner.","triggerScenarios":"addSpaceUser returning false, typically because a duplicate space_user row for the uid/space already exists (unique constraint or existence check inside addSpaceUser), or the insert fails silently inside the service and returns false.","commonSituations":"Retrying a failed create that partially succeeded (space saved but user add rolled back outside a transaction); duplicate key from a prior partial creation; DB connectivity/constraint issues during the insert.","solutions":["Wrap the space save and addSpaceUser in one @Transactional method so a failed owner insert rolls back the space row and the retry is clean","Check the space_user table for an orphan row for (spaceId, uid) and remove it, or make addSpaceUser idempotent (insert-or-ignore)","Inspect addSpaceUser for conditions that return false (existing membership, failed insert) and log the reason","Retry space creation after cleanup; if persistent, check DB constraint errors in logs"],"exampleFix":"// before\nif (spaceService.save(space)) {\n    if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {\n        throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED);\n    }\n// after\n@Transactional(rollbackFor = Exception.class)\npublic ApiResult<Long> create(...) {\n    spaceService.save(space);\n    if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {\n        throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED); // rolls back space row too\n    }","handlingStrategy":"retry","validationCode":"// pre-check for orphan membership before retrying creation\nboolean ownerExists = spaceUserService.getSpaceUserByUid(spaceId, uid) != null;","typeGuard":null,"tryCatchPattern":"try {\n    return spaceBizService.create(request);\n} catch (BusinessException e) {\n    if (ResponseEnum.INVITE_ADD_SPACE_USER_FAILED.getCode().equals(e.getCode())) {\n        // inspect space_user for the orphan row, clean up, then retry once\n        cleanupOrphanSpaceUser(request.getSpaceName(), uid);\n        return spaceBizService.create(request);\n    }\n    throw e;\n}","preventionTips":["Always make space save + owner insert atomic with @Transactional","Make addSpaceUser idempotent (upsert) so retries succeed","Log the concrete reason when addSpaceUser returns false","Watch for partial-failure retries after network timeouts on create"],"tags":["java","transaction","space-creation","membership-insert"],"backgroundTag":"database-write-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}