{"record":{"id":"6bad95909786fbbc","repo":"iflytek/astron-agent","slug":"model-not-exist-6bad95","errorCode":"MODEL_NOT_EXIST","errorMessage":"BusinessException(ResponseEnum.MODEL_NOT_EXIST)","messagePattern":"BusinessException\\(ResponseEnum\\.MODEL_NOT_EXIST\\)","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java","lineNumber":142,"sourceCode":"    private final SparkBotMapper sparkBotMapper;\n    private final ModelCategoryService modelCategoryService;\n    private final ModelCommonService modelCommonService;\n    private final LocalModelHandler modelHandler;\n    private final EnterpriseSpaceService enterpriseSpaceService;\n\n    // ======== Environment Variables ========\n    @Value(\"${spring.profiles.active}\")\n    String env;\n\n\n    @Transactional(rollbackFor = Exception.class)\n    public String validateModel(ModelValidationRequest request) {\n        // 1) Parse apiKey (use encrypted value from database when updating unchanged; otherwise decrypt)\n        final String decryptedApiKey;\n        if (request.getId() != null && Boolean.FALSE.equals(request.getApiKeyMasked())) {\n            Model byId = this.getById(request.getId());\n            if (byId == null) {\n                throw new BusinessException(ResponseEnum.MODEL_NOT_EXIST);\n            }\n            decryptedApiKey = byId.getApiKey();\n        } else {\n            decryptedApiKey = decryptApiKey(request.getApiKey());\n        }\n\n        // 2) Construct/validate URL + request body/headers\n        final String provider = normalizeProvider(request.getProvider(), true);\n        final String url = buildModelApiUrlNew(request.getEndpoint(), provider, request.getDomain());\n        final Map<String, Object> requestBody =\n                buildValidationPayload(request.getDomain(), provider);\n        final HttpHeaders headers = buildAuthHeaders(decryptedApiKey, provider);\n\n        try {\n            String responseBody = doPostModelApi(url, requestBody, headers);\n            if (isValidModelResponse(responseBody, provider)) {\n                log.info(\"Model validation passed, domain={}, endpoint={}\", request.getDomain(), url);\n                request.setApiKey(decryptedApiKey);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java#L124-L160","documentation":"ModelService.validateModel throws MODEL_NOT_EXIST when the caller indicates the stored (masked) API key should be reused — id != null and apiKeyMasked == false — but getById(id) finds no Model row. It means the model record the request refers to does not exist in the database.","triggerScenarios":"Calling validateModel with request.id set and apiKeyMasked explicitly false, while the id does not match any row in the model table (deleted model, wrong id, other tenant's model, stale id in the frontend).","commonSituations":"User opens an old edit page after the model was deleted elsewhere; frontend passes an id from another workspace/tenant; ids mistyped in API integrations; DB restored/reset while clients kept old ids.","solutions":["Confirm the id exists (SELECT from model table) and that the caller has access to it before calling validateModel","Refresh the model list on the client after deletions so stale ids are not submitted","If the caller intends to provide a new key, send apiKeyMasked=true (or true-by-default) with the plaintext/encrypted apiKey instead of referencing a stored one","Check for tenant/space scoping filters in getById lookups that may hide an existing row"],"exampleFix":"// before\nreq.setId(999L); req.setApiKeyMasked(false); // model deleted\n// after\nif (modelService.getById(999L) == null) { req.setId(null); req.setApiKey(newKey); req.setApiKeyMasked(true); }","handlingStrategy":"validation","validationCode":"if (req.getId() != null && Boolean.FALSE.equals(req.getApiKeyMasked())) {\n    Model m = modelService.getById(req.getId());\n    if (m == null) throw new IllegalStateException(\"model \" + req.getId() + \" no longer exists; supply a fresh apiKey\");\n}","typeGuard":"boolean modelExistsForMaskedReuse(ModelValidationRequest r) { return r.getId() == null || !Boolean.FALSE.equals(r.getApiKeyMasked()) || modelService.getById(r.getId()) != null; }","tryCatchPattern":"try { modelService.validateModel(req); } catch (BusinessException e) { if (ResponseEnum.MODEL_NOT_EXIST.equals(e.getResponseEnum())) { reloadModelList(); return 404-model-gone; } throw e; }","preventionTips":["Refresh the model list after any deletion so stale ids never reach validateModel","Scope ids to the current tenant/workspace and validate access client-side","Treat apiKeyMasked=false as 'use stored key' only when you just loaded the record successfully","Add referential checks before edit operations on entities that can be deleted concurrently"],"tags":["not-found","validation","java","spring"],"backgroundTag":"entity-not-found","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"}