iflytek/astron-agent · error · BusinessException

INVITE_ADD_SPACE_USER_FAILED

INVITE_ADD_SPACE_USER_FAILED

Error message

INVITE_ADD_SPACE_USER_FAILED

What it means

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.

Solutions

  1. 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
  2. Check the space_user table for an orphan row for (spaceId, uid) and remove it, or make addSpaceUser idempotent (insert-or-ignore)
  3. Inspect addSpaceUser for conditions that return false (existing membership, failed insert) and log the reason
  4. Retry space creation after cleanup; if persistent, check DB constraint errors in logs

Example fix

// before
if (spaceService.save(space)) {
    if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {
        throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED);
    }
// after
@Transactional(rollbackFor = Exception.class)
public ApiResult<Long> create(...) {
    spaceService.save(space);
    if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {
        throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED); // rolls back space row too
    }
Defensive patterns

Strategy: retry

Validate before calling

// pre-check for orphan membership before retrying creation
boolean ownerExists = spaceUserService.getSpaceUserByUid(spaceId, uid) != null;

Try / catch

try {
    return spaceBizService.create(request);
} catch (BusinessException e) {
    if (ResponseEnum.INVITE_ADD_SPACE_USER_FAILED.getCode().equals(e.getCode())) {
        // inspect space_user for the orphan row, clean up, then retry once
        cleanupOrphanSpaceUser(request.getSpaceName(), uid);
        return spaceBizService.create(request);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/62f424ad3bc210f5. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/SpaceBizServiceImpl.java:116

            Long count = spaceService.countByUid(uid);
            if (OrderInfoUtil.existValidProOrder(uid)) {
                space.setType(SpaceTypeEnum.PRO.getCode());
                if (count >= spaceLimitProperties.getPro().getSpaceCount()) {
                    return ApiResult.error(ResponseEnum.SPACE_PERSONAL_PRO_MAX_EXCEEDED);
                }
            } else {
                space.setType(SpaceTypeEnum.FREE.getCode());
                if (count >= spaceLimitProperties.getFree().getSpaceCount()) {
                    return ApiResult.error(ResponseEnum.SPACE_FREE_USER_MAX_EXCEEDED);
                }

            }
        }
        // Save space data
        if (spaceService.save(space)) {
            // Creator becomes space owner by default
            if (!spaceUserService.addSpaceUser(space.getId(), space.getUid(), SpaceRoleEnum.OWNER)) {
                throw new BusinessException(ResponseEnum.INVITE_ADD_SPACE_USER_FAILED);
            }
            return ApiResult.success(space.getId());
        } else {
            return ApiResult.error(ResponseEnum.ENTERPRISE_CREATE_FAILED);
        }
    }

    /**
     * Delete space
     *
     * @param spaceId
     * @param mobile
     * @param verifyCode
     * @return
     */
    @Override
    @Transactional
    public ApiResult<String> deleteSpace(Long spaceId, String mobile, String verifyCode) {

View on GitHub (pinned to 5e758547a8)