iflytek/astron-agent · error · BusinessException

MODEL_DELETE_FAILED_APPLY_AGENT

MODEL_DELETE_FAILED_APPLY_AGENT

Error message

BusinessException(ResponseEnum.MODEL_DELETE_FAILED_APPLY_AGENT)

What it means

Thrown by checkAndDelete when the model is still referenced by agent applications: sparkBotMapper.checkDomainIsUsage(uid, model.getDomain()) returns a positive count. The platform refuses to delete a model whose domain/serviceId is bound to at least one Spark bot/agent, preventing broken agents.

Solutions

  1. Find and update the agents using this model's domain, re-pointing them to another model, then retry deletion.
  2. Temporarily unbind/disconnect the agents from the model domain.
  3. Choose a different domain/serviceId if the model entry is being replaced rather than removed.
  4. If the reference is stale, verify checkDomainIsUsage results and clean up orphaned agent bindings.

Example fix

// before
deleteModel(modelId); // throws MODEL_DELETE_FAILED_APPLY_AGENT
// after
const agents = await listAgentsUsingDomain(model.domain);
await Promise.all(agents.map(a => updateAgentModel(a.id, replacementModelId)));
deleteModel(modelId);
Defensive patterns

Strategy: try-catch

Validate before calling

Integer usage = sparkBotMapper.checkDomainIsUsage(uid, model.getDomain());
boolean safeToDelete = model != null && (usage == null || usage == 0);

Type guard

if (modelCount != null && modelCount > 0) { /* blocked: model in use by agents */ }

Try / catch

try { modelService.checkAndDelete(modelId, request); }
catch (BusinessException e) {
  if (ResponseEnum.MODEL_DELETE_FAILED_APPLY_AGENT.equals(e.getResponseEnum())) {
    promptUserToRebindAgents(model.getDomain());
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Deleting a model whose domain is used as the LLM domain by one or more agents belonging to the same uid; typically a widely-used default model or one bound to a production agent.

Common situations: Cleaning up old fine-tuned models still attached to live agents; shared default domain reused across many bots; forgetting to re-point agents before deletion.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java:1054

    }

    @Transactional(rollbackFor = Exception.class)
    public ApiResult checkAndDelete(Long modelId, HttpServletRequest request) {
        String uid = UserInfoManagerHandler.getUserId();
        Model model = this.getById(modelId);
        if (model == null) {
            throw new BusinessException(ResponseEnum.MODEL_NOT_EXIST);
        }
        if (!model.getUid().equals(uid)) {
            log.warn("Unauthorized deletion, uid={}, modelId={}", uid, modelId);
            throw new BusinessException(ResponseEnum.EXCEED_AUTHORITY);
        }

        checkWorkflowReference(uid, model);

        Integer modelCount = sparkBotMapper.checkDomainIsUsage(uid, model.getDomain());
        if (modelCount != null && modelCount > 0) {
            throw new BusinessException(ResponseEnum.MODEL_DELETE_FAILED_APPLY_AGENT);
        }

        boolean result;
        if (Objects.equals(model.getType(), 1)) {
            result = this.removeById(modelId);
        } else {
            result = this.removeById(modelId) && modelHandler.deleteModel(model.getRemark());
        }
        return ApiResult.success(result);
    }

    /**
     * Check if model is used by workflow applications
     *
     * @param uid
     * @param model
     */
    private void checkWorkflowReference(String uid, Model model) {

View on GitHub (pinned to 5e758547a8)